Skip to content

Commit 84164d6

Browse files
committed
Build: Fix an XSS in the test server HTML serving logic
The test server has a rule for `/tests/unit/*/*.html` paths that serves a proper local file. However, the parameters after `/unit/` were so far not escaped, leading to possibly reading a file from outside of the Git repository. Fix that by replacing non-alphanumeric characters that are also not `-` or `_`. This should resolve one CodeQL alert.
1 parent ebdcd0d commit 84164d6

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

tests/runner/createTestServer.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ export async function createTestServer( report ) {
2323

2424
// Add a script tag to HTML pages to load the QUnit listeners
2525
app.use( /\/tests\/unit\/([^/]+)\/\1\.html$/, async( req, res ) => {
26+
const moduleEscaped = req.params[ 0 ].replace( /[^a-z0-9_-]/gi, "" );
2627
const html = await readFile(
27-
`tests/unit/${ req.params[ 0 ] }/${ req.params[ 0 ] }.html`,
28+
`tests/unit/${ moduleEscaped }/${ moduleEscaped }.html`,
2829
"utf8"
2930
);
3031
res.send(

0 commit comments

Comments
 (0)