Skip to content

Commit

Permalink
fix(extension): #107: allow http for localhost
Browse files Browse the repository at this point in the history
  • Loading branch information
VanishMax committed Jul 26, 2024
1 parent ba19606 commit ae0c09d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 2 additions & 2 deletions apps/extension/public/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"content_scripts": [
{
"matches": ["https://*/*"],
"matches": ["https://*/*", "http://localhost:*/*"],
"js": [
"injected-connection-port.js",
"injected-disconnect-listener.js",
Expand All @@ -25,7 +25,7 @@
"run_at": "document_start"
},
{
"matches": ["https://*/*"],
"matches": ["https://*/*", "http://localhost:*/*"],
"js": ["injected-penumbra-global.js"],
"run_at": "document_start",
"world": "MAIN"
Expand Down
7 changes: 6 additions & 1 deletion apps/extension/src/senders/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ type ValidSender = chrome.runtime.MessageSender & {
url: `${ValidProtocol}//${string}/${string}`;
};

const isException = (url: URL): boolean => {
return url.protocol === 'http:' && url.hostname === 'localhost';
};

export const assertValidSender = (sender?: chrome.runtime.MessageSender) => {
if (!sender) {
throw new Error('Sender undefined');
Expand All @@ -34,7 +38,8 @@ export const assertValidSender = (sender?: chrome.runtime.MessageSender) => {
if (parsedOrigin.origin !== sender.origin) {
throw new Error('Sender origin is invalid');
}
if (!(parsedOrigin.protocol in ValidProtocol)) {

if (!(parsedOrigin.protocol in ValidProtocol || isException(parsedOrigin))) {
throw new Error(`Sender protocol is not ${Object.values(ValidProtocol).join(',')}`);
}

Expand Down

0 comments on commit ae0c09d

Please sign in to comment.