Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Fix regex misuse. #199

Merged
merged 2 commits into from
Jun 10, 2024
Merged

Fix regex misuse. #199

merged 2 commits into from
Jun 10, 2024

Conversation

sengi
Copy link
Contributor

@sengi sengi commented Jun 7, 2024

  • Overbroad matching of hostnames: . vs \.
  • Overuse of RegExp.prototype.match where String.prototype.includes or RegExp.prototype.test suffice and better communicate the intent by returning a boolean.
  • Use Location.hostname and not Location.host, because we're already assuming there isn't a port on the end (e.g. :8080). This avoids further complicating the (corrected) regexes.
  • Where we're given a full URL as a String and we're trying to match on the hostname, just parse it properly with URL.

Should resolve:

I don't believe these are exploitable, hence raising a regular PR.

- Overbroad matching of hostnames: `.` vs `\.`
- Overuse of `RegExp.prototype.match` where `String.prototype.includes`
  or `RegExp.prototype.test` suffice and better communicate the intent
  by returning a boolean.
- Use `Location.hostname` and not `Location.host`, because we're already
  assuming there isn't a port on the end (e.g. `:8080`). This avoids
  further complicating the (corrected) regexes.

Should resolve:

- https://github.com/alphagov/govuk-browser-extension/security/code-scanning/1
- https://github.com/alphagov/govuk-browser-extension/security/code-scanning/2
- https://github.com/alphagov/govuk-browser-extension/security/code-scanning/3
- https://github.com/alphagov/govuk-browser-extension/security/code-scanning/4

I don't believe these are exploitable, hence raising a regular PR.
src/popup/extract_path.js Fixed Show resolved Hide resolved
Otherwise we just substitute one CodeQL warning for another :/
Copy link
Contributor

@KludgeKML KludgeKML left a comment

Choose a reason for hiding this comment

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

LGTM - nice tidy!

@sengi sengi merged commit 9dac875 into main Jun 10, 2024
5 checks passed
@sengi sengi deleted the sengi/cwe-20 branch June 10, 2024 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants