Skip to content
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

fix(transport-chrome): allow http for localhost #1580

Merged
merged 5 commits into from
Jul 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 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
5 changes: 5 additions & 0 deletions .changeset/nice-mangos-hammer.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@penumbra-zone/transport-chrome': patch
---

Allow http://localhost to establish the connection with chrome extensions
11 changes: 7 additions & 4 deletions packages/transport-chrome/src/session-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,14 @@ export class CRSessionManager {
return;
}

// origin restrictions
const fromThisExtension = sender.id === chrome.runtime.id;
// frameId == 0 for top-level documents
const fromPageHttps = !sender.frameId && sender.tab?.id && sender.origin.startsWith('https://');
if (!(fromThisExtension || fromPageHttps)) {
const fromPageHttps = !sender.frameId && !!sender.tab?.id && sender.origin.startsWith('https://');
const isLocalhost =
sender.origin.startsWith('http://localhost:') || sender.origin === 'http://localhost';

// Allow connections from the same extension, from https pages, or from http://localhost
const validOrigin = isLocalhost || fromPageHttps || fromThisExtension;
if (!validOrigin) {
return;
}

Expand Down
Loading