Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Build: Fix an XSS in the test server HTML serving logic #2309

Merged
merged 1 commit into from
Oct 28, 2024

Conversation

mgol
Copy link
Member

@mgol mgol commented Oct 25, 2024

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.

@mgol mgol added this to the 1.14.1 milestone Oct 25, 2024
@mgol mgol requested a review from timmywil October 25, 2024 22:36
@mgol mgol self-assigned this Oct 25, 2024
@mgol mgol force-pushed the codeql-createTestServer branch from fba692e to 84164d6 Compare October 25, 2024 22:37
tests/runner/createTestServer.js Fixed Show resolved Hide resolved
@mgol mgol requested a review from fnagel October 26, 2024 21:54
@mgol mgol force-pushed the codeql-createTestServer branch from 84164d6 to 0eca8b8 Compare October 27, 2024 12:16
Copy link
Member

@fnagel fnagel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 by reading

Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Doesn't fix it. The issue is using a user-provided value in the argument to readfile without limiting the reads to a certain location.

@mgol
Copy link
Member Author

mgol commented Oct 27, 2024

@timmywil this limits it to the tests/unit/ directory, how does it not fix it? The mitigation proposed by the check description doesn’t guarantee anything else.

@timmywil
Copy link
Member

I meant that it doesn't fix the codeql check, which is all we really care about here as there isn't a real vulnerability since the test server is not hosted. Why not refactor this in a way that passes codeql so we don't have to dismiss the alert?

@mgol
Copy link
Member Author

mgol commented Oct 28, 2024

I meant that it doesn't fix the codeql check, which is all we really care about here as there isn't a real vulnerability since the test server is not hosted.

No, I care about it precisely because it might be a real vulnerability. I've dismissed a number of purely test/demo reports that we don't need to care about. But here we have a dev server running on a local network; any device on that network can access its resources this way.

TBH, I don't know how to exploit it considering that the matcher already excludes / - and this is perhaps where I should make the regex also exclude ., etc.

But OK, I can try to do it the way CodeQL is happy.

@mgol mgol force-pushed the codeql-createTestServer branch from 0eca8b8 to 5000491 Compare October 28, 2024 09:01
@mgol
Copy link
Member Author

mgol commented Oct 28, 2024

Updating the regex in the matcher seems to make CodeQL happy. It now complains about a lack of rate limiter for file system access, but caring about potential DoS on a local test server would probably be too much, so I'd leave it as-is.

@mgol mgol requested a review from timmywil October 28, 2024 09:13
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.
@mgol mgol force-pushed the codeql-createTestServer branch from 5000491 to 78947f1 Compare October 28, 2024 09:36
Copy link
Member

@timmywil timmywil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. How could it know it's not rate limited when that's often handled by a front door? Seems strange it's an error and not a warning. Anyway, thanks for humoring me. My OCD was kicking in and I didn't want us to address an error and then have to dismiss it anyway.

Whether we call this a "real" vulnerability I think is still debatable since this isn't production code, but I was certainly not opposed to addressing it.

@mgol mgol removed the Needs review label Oct 28, 2024
@mgol mgol merged commit 85bed8d into jquery:main Oct 28, 2024
11 checks passed
@mgol mgol deleted the codeql-createTestServer branch October 28, 2024 15:47
# for free to join this conversation on GitHub. Already have an account? # to comment
Development

Successfully merging this pull request may close these issues.

3 participants