Skip to content

added host check for binary download url#99

Open
rounak610 wants to merge 3 commits into
masterfrom
LOC-6727
Open

added host check for binary download url#99
rounak610 wants to merge 3 commits into
masterfrom
LOC-6727

Conversation

@rounak610

Copy link
Copy Markdown
Collaborator

No description provided.

@rounak610 rounak610 requested a review from a team as a code owner June 4, 2026 13:52
@rounak610 rounak610 changed the title Loc 6727 added host check for binary download url Jun 5, 2026
@rounak610 rounak610 requested review from yashdsaraf and removed request for kamal-kaur04 and xxshubhamxx June 9, 2026 08:14
Comment thread src/main/java/com/browserstack/local/LocalBinary.java
Comment thread src/main/java/com/browserstack/local/LocalBinary.java
}
host = host.toLowerCase();
for (String allowed : ALLOWED_DOWNLOAD_HOSTS) {
if (host.equals(allowed)) return url;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you had to do this all along then why all the checks before this?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

done

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
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