Skip to content

Commit e9d41ca

Browse files
rounak610claude
andcommitted
Add comment explaining each guard in validateSourceUrl
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 8936933 commit e9d41ca

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

lib/util.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ module.exports.isUndefined = value => (value === undefined || value === null ||
55
const ALLOWED_DOWNLOAD_HOSTS = ['browserstack.com'];
66
const ALLOWED_DOWNLOAD_HOST_SUFFIXES = ['.browserstack.com'];
77

8+
// Each guard below covers a case the final host-equals check does not:
9+
// - empty/non-string URL: new url.URL(null) throws TypeError; explicit guard returns a clean message.
10+
// - URL constructor catch: convert TypeError on malformed input into our own Error.
11+
// - HTTPS check: allowlist matches host only; without this, http://browserstack.com would pass.
12+
// - null/empty hostname: URL constructor accepts forms like https:///foo where hostname is empty; give a clear error.
813
module.exports.validateSourceUrl = function(sourceUrl) {
914
if (!sourceUrl || typeof sourceUrl !== 'string') {
1015
throw new Error('Refusing binary download: empty source URL');

0 commit comments

Comments
 (0)