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

Sanitise environment variables used in RegExps #197

Merged
merged 5 commits into from
May 7, 2020
Merged

Sanitise environment variables used in RegExps #197

merged 5 commits into from
May 7, 2020

Conversation

Alhadis
Copy link
Contributor

@Alhadis Alhadis commented May 7, 2020

The PATH and CHROME_PATH variables are currently being used verbatim for constructing a regular expression:

{regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome.app`), weight: 50},
{regex: new RegExp(`^${process.env.HOME}/Applications/.*Chrome Canary.app`), weight: 51},

This can lead to confusing behaviour if a user's path contains RegExp metacharacters such as $ or ^. Worse still, it leaves room for a malicious actor to inject an expression guaranteed to send the process into performance hell:

export CHROME_PATH='(.*.*.*.*.*.*.*.*.*.*.*.*)*[^Bb]|$'

I also replaced stuff like `${process.env.PATH}` with simply process.env.PATH, because the former syntax will stringify an undefined value as "undefined", which probably isn't what you want (or expect).

Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

thanks very much, nice catch @Alhadis! 👍

src/chrome-finder.ts Outdated Show resolved Hide resolved
src/chrome-finder.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@patrickhulce patrickhulce left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @Alhadis! 🎉

@patrickhulce patrickhulce merged commit 2ae5591 into GoogleChrome:master May 7, 2020
@Alhadis Alhadis deleted the finder-fixes branch May 7, 2020 15:45
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.

2 participants