Skip to content

Commit 1ad0867

Browse files
committed
model serve-handler in js/exposure-of-private-files
1 parent e276e26 commit 1ad0867

File tree

4 files changed

+38
-5
lines changed

4 files changed

+38
-5
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
lgtm,codescanning
2+
* Private folders exposed using the [`serve-handler`](https://npmjs.com/package/serve-handler) library is not recognized by `js/exposure-of-private-files`.
3+
Affected packages are
4+
[serve-handler](https://npmjs.com/package/serve-handler)

javascript/ql/src/Security/CWE-200/PrivateFileExposure.ql

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,27 @@ DataFlow::CallNode servesAPrivateFolder(string description) {
126126
result.getArgument(0) = getAPrivateFolderPath(description)
127127
}
128128

129-
from Express::RouteSetup setup, string path
129+
/**
130+
* Gets an [`express`](https://npmjs.com/package/express) route-setup
131+
* that exposes a private folder described by `path`.
132+
*/
133+
Express::RouteSetup getAnExposingExpressSetup(string path) {
134+
result.isUseCall() and
135+
result.getArgument([0 .. 1]) = servesAPrivateFolder(path).getEnclosingExpr()
136+
}
137+
138+
/**
139+
* Gets a call to [`serve-handler`](https://npmjs.com/package/serve-handler)
140+
* that exposes a private folder described by `path`.
141+
*/
142+
DataFlow::CallNode getAnExposingServeSetup(string path) {
143+
result = DataFlow::moduleImport("serve-handler").getACall() and
144+
result.getOptionArgument(2, "public") = getAPrivateFolderPath(path)
145+
}
146+
147+
from DataFlow::Node node, string path
130148
where
131-
setup.isUseCall() and
132-
setup.getArgument([0 .. 1]) = servesAPrivateFolder(path).getEnclosingExpr()
133-
select setup, "Serves " + path + ", which can contain private information."
149+
node = getAnExposingExpressSetup(path).flow()
150+
or
151+
node = getAnExposingServeSetup(path)
152+
select node, "Serves " + path + ", which can contain private information."

javascript/ql/test/query-tests/Security/CWE-200/PrivateFileExposure.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@
1919
| private-file-exposure.js:42:1:42:66 | app.use ... dir())) | Serves the home folder, which can contain private information. |
2020
| private-file-exposure.js:43:1:43:46 | app.use ... )("/")) | Serves the root folder, which can contain private information. |
2121
| private-file-exposure.js:51:5:51:88 | app.use ... les'))) | Serves the folder "../node_modules", which can contain private information. |
22+
| private-file-exposure.js:70:5:70:71 | serveHa ... ular"}) | Serves the folder "./node_modules/angular", which can contain private information. |
2223
| subfolder/private-file-exposure-2.js:6:1:6:34 | app.use ... rname)) | Serves the folder query-tests/Security/CWE-200/subfolder, which can contain private information. |

javascript/ql/test/query-tests/Security/CWE-200/private-file-exposure.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,13 @@ function good() {
6161
app.use("bootstrap", express.static('./node_modules/bootstrap/dist')); // OK
6262
}
6363

64-
app.use(express.static(__dirname)) // NOT OK
64+
app.use(express.static(__dirname)) // NOT OK
65+
66+
const serveHandler = require("serve-handler");
67+
const http = require("http");
68+
69+
http.createServer((request, response) => {
70+
serveHandler(request, response, {public: "./node_modules/angular"}); // NOT OK
71+
72+
serveHandler(request, response); // OK
73+
}).listen(8080);

0 commit comments

Comments
 (0)