Skip to content

Commit 9a2a328

Browse files
authored
Merge pull request #1025 from xiemaisi/js/fix-exports-assign
Approved by asger-semmle
2 parents 7f5e263 + 3cabc12 commit 9a2a328

File tree

8 files changed

+12
-8
lines changed

8 files changed

+12
-8
lines changed

change-notes/1.20/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
| **Query** | **Expected impact** | **Change** |
4040
|--------------------------------------------|------------------------------|------------------------------------------------------------------------------|
4141
| Ambiguous HTML id attribute | Fewer false-positive results | This rule now treats templates more conservatively. Its precision has been revised to 'high'. |
42+
| Assignment to exports variable | Fewer results | This rule no longer flags code that is also flagged by the rule "Useless assignment to local variable". |
4243
| Client-side cross-site scripting | More true-positive results, fewer false-positive results. | This rule now recognizes WinJS functions that are vulnerable to HTML injection. It no longer flags certain safe uses of jQuery, and recognizes custom sanitizers. |
4344
| Hard-coded credentials | Fewer false-positive results | This rule no longer flag the empty string as a hardcoded username. |
4445
| Insecure randomness | More results | This rule now flags insecure uses of `crypto.pseudoRandomBytes`. |

javascript/ql/src/NodeJS/InvalidExport.ql

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,8 @@ from Assignment assgn, Variable exportsVar, DataFlow::Node exportsVal
4141
where
4242
exportsAssign(assgn, exportsVar, exportsVal) and
4343
not exists(exportsVal.getAPredecessor()) and
44-
not (
45-
// this is OK if `exportsVal` flows into `module.exports`
46-
moduleExportsAssign(_, exportsVal) and
47-
// however, if there are no further uses of `exports` the assignment is useless anyway
48-
strictcount(exportsVar.getAnAccess()) > 1
49-
) and
44+
// this is OK if `exportsVal` flows into `module.exports`
45+
not moduleExportsAssign(_, exportsVal) and
5046
// export assignments do work in closure modules
5147
not assgn.getTopLevel() instanceof Closure::ClosureModule
5248
select assgn, "Assigning to 'exports' does not export anything."

javascript/ql/test/query-tests/Declarations/DeadStoreOfLocal/DeadStoreOfLocal.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
| overload.ts:10:12:10:14 | baz | This definition of baz is useless, since its value is never read. |
22
| tst2.js:26:9:26:14 | x = 23 | This definition of x is useless, since its value is never read. |
33
| tst2.js:28:9:28:14 | x = 42 | This definition of x is useless, since its value is never read. |
4+
| tst3.js:2:1:2:36 | exports ... a: 23 } | This definition of exports is useless, since its value is never read. |
5+
| tst3b.js:2:18:2:36 | exports = { a: 23 } | This definition of exports is useless, since its value is never read. |
46
| tst.js:6:2:6:7 | y = 23 | This definition of y is useless, since its value is never read. |
57
| tst.js:13:6:13:11 | a = 23 | This definition of a is useless, since its value is never read. |
68
| tst.js:13:14:13:19 | a = 42 | This definition of a is useless, since its value is never read. |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// NOT OK
2+
exports = module.exports = { a: 23 };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// NOT OK
2+
module.exports = exports = { a: 23 };
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
1-
| tst3.js:2:1:2:36 | exports ... a: 23 } | Assigning to 'exports' does not export anything. |
21
| tst5.js:3:1:3:12 | exports = {} | Assigning to 'exports' does not export anything. |
32
| tst.js:2:1:2:12 | exports = 56 | Assigning to 'exports' does not export anything. |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
// NOT OK: useless assignment
1+
// OK: useless assignment flagged by other query
22
exports = module.exports = { a: 23 };
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// OK: useless assignment flagged by other query
2+
module.exports = exports = { a: 23 };

0 commit comments

Comments
 (0)