JavaScript: Add model of `http2` compatibility API. · github/codeql@46f8dda · GitHub
Skip to content

Commit 46f8dda

Browse files
author
Max Schaefer
committed
JavaScript: Add model of http2 compatibility API.
Also deprecated the `httpOrHttps` predicate, which was now only used in one place and seemed a little pointless anyway.
1 parent d995d5a commit 46f8dda

5 files changed

Lines changed: 29 additions & 6 deletions

File tree

‎change-notes/1.24/analysis-javascript.md‎

Lines changed: 1 addition & 0 deletions

‎javascript/ql/src/semmle/javascript/frameworks/HTTP.qll‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ module HTTP {
119119
}
120120

121121
/**
122+
* DEPRECATED: Use `http` or `https` directly as appropriate.
123+
*
122124
* Gets the string `http` or `https`.
123125
*/
126+
deprecated
124127
string httpOrHttps() { result = "http" or result = "https" }
125128

126129
/**

‎javascript/ql/src/semmle/javascript/frameworks/NodeJSLib.qll‎

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,18 @@ module NodeJSLib {
4242
* Holds if `call` is an invocation of `http.createServer` or `https.createServer`.
4343
*/
4444
predicate isCreateServer(CallExpr call) {
45-
call = DataFlow::moduleMember(HTTP::httpOrHttps(), "createServer").getAnInvocation().asExpr()
45+
exists(string pkg, string fn |
46+
pkg = "http" and fn = "createServer"
47+
or
48+
pkg = "https" and fn = "createServer"
49+
or
50+
// http2 compatibility API
51+
pkg = "http2" and fn = "createServer"
52+
or
53+
pkg = "http2" and fn = "createSecureServer"
54+
|
55+
call = DataFlow::moduleMember(pkg, fn).getAnInvocation().asExpr()
56+
)
4657
}
4758

4859
/**
@@ -356,10 +367,12 @@ module NodeJSLib {
356367
/** An expression that is passed as `http.request({ auth: <expr> }, ...)`. */
357368
class Credentials extends CredentialsExpr {
358369
Credentials() {
359-
this = DataFlow::moduleMember(HTTP::httpOrHttps(), "request")
360-
.getACall()
361-
.getOptionArgument(0, "auth")
362-
.asExpr()
370+
exists(string http | http = "http" or http = "https" |
371+
this = DataFlow::moduleMember(http, "request")
372+
.getACall()
373+
.getOptionArgument(0, "auth")
374+
.asExpr()
375+
)
363376
}
364377

365378
override string getCredentialsKind() { result = "credentials" }
@@ -881,7 +894,6 @@ module NodeJSLib {
881894
override string getSourceType() { result = "NodeJSClientRequest error event" }
882895
}
883896

884-
885897
/**
886898
* An NodeJS EventEmitter instance.
887899
* Events dispatched on this EventEmitter will be handled by event handlers registered on this EventEmitter.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
var https = require('https');
22
https.createServer(function (req, res) {});
33
https.createServer(o, function (req, res) {});
4+
require('http2').createServer((req, res) => {});

‎javascript/ql/test/library-tests/frameworks/NodeJSLib/tests.expected‎

Lines changed: 6 additions & 0 deletions

0 commit comments

Comments
 (0)