Skip to content

Commit

Permalink
fix(transport-chrome): allow http for localhost (#1580)
Browse files Browse the repository at this point in the history
* fix(transport-chrome): allow http for localhost

* chore: add changesets

* chore: format with prettier

* fix(transport-chrome): review

* fix: prettier
  • Loading branch information
VanishMax authored Jul 30, 2024
1 parent 0f0272f commit 06aa65d
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
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
12 changes: 8 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,15 @@ 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

0 comments on commit 06aa65d

Please sign in to comment.