Skip to content

Commit

Permalink
Revert "fix(extension): #107: allow http for localhost (#129)"
Browse files Browse the repository at this point in the history
This reverts commit 8141aa4.
  • Loading branch information
grod220 authored Aug 8, 2024
1 parent f71d20b commit 7455586
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 14 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://*/*", "http://localhost:*/*"],
"matches": ["https://*/*"],
"js": [
"injected-connection-port.js",
"injected-disconnect-listener.js",
Expand All @@ -25,7 +25,7 @@
"run_at": "document_start"
},
{
"matches": ["https://*/*", "http://localhost:*/*"],
"matches": ["https://*/*"],
"js": ["injected-penumbra-global.js"],
"run_at": "document_start",
"world": "MAIN"
Expand Down
18 changes: 6 additions & 12 deletions apps/extension/src/senders/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ type ValidSender = chrome.runtime.MessageSender & {
frameId: 0;
documentId: string;
tab: chrome.tabs.Tab & { id: number };
origin: string;
url: string;
};

const isHttpLocalhost = (url: URL): boolean =>
url.protocol === 'http:' && url.hostname === 'localhost';
// the relationship between origin and url is pretty complex.
// just rely on the browser's tools.
origin: `${ValidProtocol}//${string}`;
url: `${ValidProtocol}//${string}/${string}`;
};

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

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

Expand Down

0 comments on commit 7455586

Please sign in to comment.