Conversation
rounak610
commented
Jun 9, 2026
rounak610
commented
Jun 9, 2026
yashdsaraf
requested changes
Jun 9, 2026
| } | ||
| host = host.toLowerCase(); | ||
| for (String allowed : ALLOWED_DOWNLOAD_HOSTS) { | ||
| if (host.equals(allowed)) return url; |
Collaborator
There was a problem hiding this comment.
If you had to do this all along then why all the checks before this?
Collaborator
Author
There was a problem hiding this comment.
Each check covers a different case the host equals on line 67 doesn't:
- HTTPS check (line 58): allowlist matches host only, so without this http://browserstack.com would still pass and we'd download over plain HTTP.
- MalformedURLException catch (line 55): converts a raw JVM exception into LocalException so the caller sees one exception type.
- null/empty host check (line 62): getHost() returns null for URLs like https:///foo. Without this, host.toLowerCase() on line 65 throws NPE.
- null URL check (line 49): new URL(null) throws NPE before the catch can run.
Collaborator
There was a problem hiding this comment.
Ack got it, mind adding a small comment at the top to make sure the next dev understands the purpose?
(e.g my instinct was directly to de-dup code, didn't realise throwing specific exceptions was the use case)
This was referenced Jun 9, 2026
Open
LOC-6727: validate source URL host before binary download
browserstack/browserstack-local-nodejs#176
Open
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.