-
Notifications
You must be signed in to change notification settings - Fork 2
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(extension): #107: allow http for localhost #153
Changes from 4 commits
ae0c09d
f0198bb
a179d84
e792473
e0840f5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ type ValidSender = chrome.runtime.MessageSender & { | |
frameId: 0; | ||
documentId: string; | ||
tab: chrome.tabs.Tab & { id: number }; | ||
|
||
// the relationship between origin and url is pretty complex. | ||
// just rely on the browser's tools. | ||
origin: `${ValidProtocol}//${string}`; | ||
url: `${ValidProtocol}//${string}/${string}`; | ||
origin: string; | ||
url: string; | ||
}; | ||
|
||
const isHttpLocalhost = (url: URL): boolean => | ||
url.protocol === 'http:' && url.hostname === 'localhost'; | ||
|
||
export const assertValidSender = (sender?: chrome.runtime.MessageSender) => { | ||
if (!sender) { | ||
throw new Error('Sender undefined'); | ||
|
@@ -34,7 +34,13 @@ 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 || | ||
(globalThis.__DEV__ && isHttpLocalhost(parsedOrigin)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Stumbled upon this today. I was trying to connect a production Prax to the dev Dex explorer and it would silently fail. Think we should drop the requirement that the dev version of Prax is needed to connect to localhost sites: parsedOrigin.protocol in ValidProtocol ||
- (globalThis.__DEV__ && isHttpLocalhost(parsedOrigin))
+ isHttpLocalhost(parsedOrigin) @VanishMax can you open a follow PR on this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
) | ||
) { | ||
Comment on lines
+38
to
+43
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. todo: we should have a test for this in validate.test.ts. Also, could you check that test suite to ensure we've covered all cases for this function? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @grod220 thanks for pointing this out. I should pay more attention to the tests |
||
throw new Error(`Sender protocol is not ${Object.values(ValidProtocol).join(',')}`); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this line, instead of the previously used one, must work correctly according to the docs: https://developer.chrome.com/docs/extensions/develop/concepts/match-patterns#special
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked a test upload, it works 👍