-
Notifications
You must be signed in to change notification settings - Fork 9.4k
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
cli(run): prevent file:// from running, return error #5936
Conversation
I think we should move this check into core, rather than the cli, so that all the clients get it. I don't believe extensions are allowed to debug Preferably the check can be early on, so maybe here in the module index? We can simplify a bit, something like const URL = require('./lib/url-shim.js');
const LHError = require('./lib/lh-error.js');
const ALLOWED_PROTOCOLS = /^(chrome|https?):$/;
// ...
if (url && !ALLOWED_PROTOCOLS.test(new URL(url).protocol)) {
throw new LHError(LHError.errors.INVALID_URL);
} Then add the Testing should also be simpler, too (just asserting it throws). WDYT? Biggest downside seems like it'll be that we're doing work in the CLI (e.g. starting Chrome, etc) that will be rendered useless by the time it gets here, but we have other checks that end up like that, and with any luck it's a something a user will only run into once (or once every typo :). |
|
@paulirish confirms that is dumb, so nevermind about the |
@brendankenny Sounds good! My initial thought was that this could run earlier, but I was unsure if firing up Chrome and then failing out if the URL was invalid was a okay. Since that sounds alright, I'll shuffle this to check earlier and get this PR updated. |
d1f2ba8
to
1cce214
Compare
@brendankenny The one difference in the above implementation from your guidance is that instead of running a regex check on allowed protocols, I broke that out into |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry for the delay, this LGTM!
🚫 📁 🏃
Per #5924, this prevents
file://
urls from running in LH.A few things:
file
, rather it checks to verify if the URL is a valid form. To see what the regex matches, I put up https://regexr.com/3um70 for easy glance (which is pretty much just an extended version of Mathias' list from https://mathiasbynens.be/demo/url-regex)chrome://
urlsrun
as opposed to running checks incli-flags
mostly because it seemed the cleaner route. Re-useshandleError
in this case (though the error message placement probably needs to move)jest.spyOn
and a mock for theprocess.exit()
call thathandleError
makes when failing onfile:///
(though the console.error will still appear when running tests):Resolves #5924.