-
Notifications
You must be signed in to change notification settings - Fork 5k
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
getSiteMetadata if possibly FQDN and not extension id, for eth_requestAccounts #7169
Changes from all commits
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 |
---|---|---|
|
@@ -41,7 +41,7 @@ class ProviderApprovalController extends SafeEventEmitter { | |
return | ||
} | ||
// register the provider request | ||
const metadata = await getSiteMetadata(origin) | ||
const metadata = /localhost|[.:/]/.test(origin) ? await getSiteMetadata(origin) : { name: 'An extenstion' } | ||
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. I have some reservations about this choice in default extension name. Maybe something like 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. I like that actually. I was actually worried you and others wouldn't. I'd do "An unknown browser extension". 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.
I chose to omit the Though on that point - maybe we're better off choosing a fallback title in the UI rather than here. This feels like the wrong place to make UI decisions. Though the front-end does need to know that this is from an extension, not a normal page. I've just had an idea - we could bypass the problem of detecting whether it's an extension or not completely and avoid making UI decisions in the background by adding I don't think it'd be super difficult to implement. You'd need to add it to this metadata object, and pass it through to the state update in 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.
Sure, I can drop the 'an'.
I completely agree. I can modify
I just want to make it clear that it's not possible to detect that something is an extension (without the Management API) and thus it is only possible to detect if something definitely isn't an extension.
Yes, either the UI can detect with regex if the origin isn't an extension by regex, or by a null So, at the end of the day, while I can do what you suggested, I cannot call |
||
this._handleProviderRequest(origin, metadata.name, metadata.icon) | ||
// wait for resolution of request | ||
const approved = await new Promise(resolve => this.once(`resolvedRequest:${origin}`, ({ approved }) => resolve(approved))) | ||
|
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.
Interesting method of detecting extension URLs. I think it should work for now? 🤔
It doesn't seem ideal though. I'd prefer that we check the actual scheme of the origin, but unfortunately that's stripped out earlier on.
I'm tempted to try updating
background.js
to include the scheme in the origin it passes through, then you could just extract the scheme here and use that instead. It'll be a bit delicate though, as everything else is expecting the origin to not have a scheme...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.
Ya, I noticed this was a bit delicate, so this is a simpler way that doesn't really break anything. Although, if the alphabetic extension id happens to contain 'localhost' (which in incredibly unlikely), well, edge case...
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.
I'm tempted to accept the regex for now and improve this using the
scheme
later on, but... I'm concerned there will be more edge cases than justlocalhost
. It's not uncommon to use custom domains locally for testing for example (by modifying thehosts
file).Instead I think we can sidestep even attempting to detect extensions by using the origin as the fallback if a title isn't present (as mentioned in my other comment). This lets us avoid this until we can do it well.
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.
So long as the the custom domain in the hosts file has a tld, or if a port is used, it will be picked up as a domain
Keep in mind, this isn't detecting an extension, its detecting domains with a very large net. Also, I am not sure what you mean by "title". Do you mean the
name
in the object returned bygetSiteMetadata
? If so, the issue is thatgetSiteMetadata
throws silently for extensions, and never returnsnull
forname
.To be honest, I didn't really understand how
getSiteMetadata
gets what it gets, as the code got pretty consulted, and wasn't that functions. At least IMO.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.
You're right about the
tld
. I don't think the port is included though - theorigin
parameter here is really just thehostname
, which afaik doesn't include the port.Sorry yes, that's what I meant.
Ah I see 🤔. I had not realized - that does change things. I'll take a quick look to see if I can find out why this happens.
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.
Maybe we/I modify
getSiteMetadata
to do the regex test before calling its downstream functions, and immediately return a null name and icon, or a null object altogether? This way, we can ignore why downstream calls might crash and can implement the UI logic as you suggested.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.
I've made an attempt here: 1b32801
I'm not entirely sure that the
extensionId
is a reliable indicator of whether the sender is an extension or not; the docs imply it'll bet set for extensions but I haven't tested it yet. We could check the scheme instead (forchrome-extension
ormoz-extension
, and that should work reliably as well. It does avoid callinggetSiteMetadata
just as your solution did, so that;s good.The tests still aren't working; I need to investigate a bit to find out why. I haven't updated the UI yet either, so it'll still likely break because it expects a name in the metadata.