Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/domain-filter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,13 @@ export function buildWebSocketFilterScript(allowedDomains: string[]): string {
}
function _checkUrl(url) {
try {
var parsed = new URL(url);
return _isDomainAllowed(parsed.hostname);
// Handle relative URLs (e.g., /__webpack_hmr) by resolving against page origin
var fullUrl = url;
if (url.startsWith('/') || url.startsWith('.')) {
fullUrl = location.origin + url;
}
var parsed = new URL(fullUrl);
return parsed.hostname ? _isDomainAllowed(parsed.hostname) : true;
Comment on lines +54 to +60
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// Handle relative URLs (e.g., /__webpack_hmr) by resolving against page origin
var fullUrl = url;
if (url.startsWith('/') || url.startsWith('.')) {
fullUrl = location.origin + url;
}
var parsed = new URL(fullUrl);
return parsed.hostname ? _isDomainAllowed(parsed.hostname) : true;
var parsed = new URL(url, location.origin);
return parsed.hostname ? _isDomainAllowed(parsed.hostname) : false;

Two bugs in _checkUrl: manual URL string concatenation produces invalid URLs for relative paths starting with ., and hostless URLs (data:, blob:) bypass the domain filter entirely.

Fix on Vercel

} catch(e) {
return false;
}
Expand Down