Skip to content

Commit f5d3274

Browse files
authored
Merge pull request #508 from esben-semmle/js/indirect-global-call-with-default-arguments
Approved by xiemaisi
2 parents 746b13a + 01ad9ed commit f5d3274

File tree

4 files changed

+20
-0
lines changed

4 files changed

+20
-0
lines changed

change-notes/1.19/analysis-javascript.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
| Duplicate switch case | Lower severity | The severity of this rule has been revised to "warning". |
4444
| Information exposure through a stack trace | More results | This rule now also flags cases where the entire exception object (including the stack trace) may be exposed. |
4545
| Missing CSRF middleware | Fewer false-positive results | This rule now recognizes additional CSRF protection middlewares. |
46+
| Missing 'this' qualifier | Fewer false-positive results | This rule now recognizes additional intentional calls to global functions. |
4647
| Missing variable declaration | Lower severity | The severity of this rule has been revised to "warning". |
4748
| Regular expression injection | Fewer false-positive results | This rule now identifies calls to `String.prototype.search` with more precision. |
4849
| Remote property injection | Fewer results | The precision of this rule has been revised to "medium". Results are no longer shown on LGTM by default. |

javascript/ql/src/Declarations/MissingThisQualifier.ql

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,14 @@ where maybeMissingThis(call, intendedTarget, gv)
5050
decl.isNamespaceExport() and
5151
call.getContainer().getEnclosingContainer*() instanceof NamespaceDeclaration
5252
)
53+
or
54+
// call to global function with additional arguments
55+
exists (Function self |
56+
intendedTarget.getBody() = self and
57+
call.getEnclosingFunction() = self and
58+
call.flow().(DataFlow::CallNode).getNumArgument() > self.getNumParameter() and
59+
not self.hasRestParameter() and
60+
not self.usesArgumentsObject()
61+
)
5362
)
5463
select call, "This call refers to a global function, and not the local method $@.", intendedTarget, intendedTarget.getName()

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
| abstract-missing.ts:3:5:3:24 | setAudioProperties() | This call refers to a global function, and not the local method $@. | abstract-missing.ts:6:3:6:32 | abstrac ... ties(); | setAudioProperties |
2+
| indirection.js:7:9:7:20 | m("default") | This call refers to a global function, and not the local method $@. | indirection.js:2:5:4:5 | m() {\\n ... K\\n } | m |
23
| missing1.js:3:5:3:24 | setAudioProperties() | This call refers to a global function, and not the local method $@. | missing1.js:6:3:7:3 | setAudi ... (){\\n } | setAudioProperties |
34
| missing2.js:3:5:3:24 | setAudioProperties() | This call refers to a global function, and not the local method $@. | missing2.js:7:3:8:3 | static ... (){\\n } | setAudioProperties |
45
| namespaces-uses.ts:3:5:3:20 | globalFunction() | This call refers to a global function, and not the local method $@. | namespaces-uses.ts:2:3:4:3 | globalF ... OK\\n } | globalFunction |
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
class X {
2+
m() {
3+
m("default"); // OK
4+
}
5+
6+
resty(...x) {
7+
m("default"); // NOT OK
8+
}
9+
}

0 commit comments

Comments
 (0)