-
Notifications
You must be signed in to change notification settings - Fork 155
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
Permissions Policy JS API #401
Comments
I would prefer 4 unless there is a clear way this API can help in a way that the more widely deployed permissions.query cannot. |
The uses that I can see are of two forms:
|
cc @johannhof |
I agree and I can imagine updating permissions.query for that. |
Luckily, synchronous XHR has easily-detectable failure modes, so doesn't necessarily need support from Support for the |
Could the JS API provide the same I use these to check that my FeaturePolicy header is specifying something for everything (as a default would be risky); and while I could check the permissions_policy_features.json5 file, that doesen't show which ones are currently enabled.
|
Yeah, I think that usage shows that we need something like that still. I have something of a concrete proposal that I'm writing up; I'll post it here so folks can see whether it covers the right use cases. |
Based on Chrome's UMA data (added in Chrome 91, which has been in stable release for a week or so, but I've been watching it since it was the Canary channel), there are only three components of the Feature Policy JS API which are used in practice:
The remaining API surface is effectively unused. The feature list is by far the most used API, at a startling 11% of page visits. allowsFeature and allowedFeatures lag far behind at ~0.05% and ~.0005% respectively. Given the rename of Feature Policy to Permissions Policy, the low usage of most of the API, and what seems like an apparent similarity between Permissions Policy and the Permissions API, there seems to be justification for merging the APIs. In practice, this would mean folding the functionality of the Permissions Policy JS API into the Permissions API. I have some concrete suggestions for doing that here: 1. Replace uses of
|
Policy: Denied | Policy: Allowed | |
---|---|---|
User: Denied | Denied | Denied |
User: Prompt | Denied | Prompt |
User: Allowed | Denied | Allowed |
Currently the policy side is revealed by the featurePolicy
interface, while the user side is exposed by permissions.query
. Merging the two APIs would mean that there is no way to distinguish between "denied by policy" and "denied by user".
Q: Are there UI cases where "denied by policy" should be treated differently than "allowed by policy; denied by user"? I think the only thing it would allow is to give websites an extra opportunity to tell the user that they could change their mind, but this seems contradictory to the user's stated intent, and I don't know if that's a pattern that should be encouraged.
For most practical purposes, permissions.query
would be a usable replacement for allowsFeature
.
2. Move the feature list to navigator.permissions.features
.
This is a harder move, as document.featurePolicy.features
has non-trivial amounts of usage. Again, we would need to include other permissions policy features in the Permissions enum. I do think it makes sense in the long term, though. Once usage in the wild moves to permissions.features
, I expect that the entire document.featurePolicy
object can be deprecated.
3. Remove document.featurePolicy.allowedFeatures
This API could be replaced with specific calls to query the state of individual features, rather than providing a list. Especially if the list of available features can be iterated over, it would be trivial to get this with the other API calls.
4. Remove document.featurePolicy.allowsFeature(feature, origin)
, featurePolicy.getAllowlistForFeature
, and all of HTMLIframeElement.featurePolicy
These APIs see essentially zero usage in the wild. Their primary function seems to be to support WPT, by allowing the state of the policy in the browser to be probed. These tests can mostly be replaced with behavioral tests, and if there are tests that absolutely require access to the interior state of the policy, then a TestDriver interface can be added to expose that.
With the "11% of page visits", I assume that's some browser fingerprinting going on? I have a slight worry, even though I'm using it, that it's being used for less than ideal purposes? |
I don't know -- it's a possibility, but My suspicion (mostly because I've seen examples) is that there are a couple of widespread libraries in the wild doing something like
which also isn't necessary at all, but I've seen it done. |
It's also possible that it's being used as a generic feature-detection mechanism, rather than for any sort of permission control or delegation. |
That's interesting (and strange they do that), thanks for checking... otherwise, while I don't have a vote, I'd be happy with any of those suggestions. |
I think I would prefer to not expose |
My use case for I want to keep as many restrictions in place (I'm hosting sensitive medical data), but I don't see a default working because some things shouldn't be disabled by default (e.g. It's not as though the folder of policies is kept up to date. And I can't check permissions_policy_features.json5 as that's for Chrome Canary, and has no indication which |
That seems like a transitional problem, but will over time be solved through improved documentation. |
So we will rely on all things being documented, and website developers checking the list every month or so? Considering |
FYI, I have posted #444 proposing a |
Is there any way to test for Client Hint features that doesn't involve an actual request across the network? That's expensive. |
Permissions Policy currently has the JavaScript API that was specced when it was Feature Policy, but it turns out that the semantics are now a bit different, because of the way that the header is interpreted and combined with the container policy. (#357, #378)
The policy.allowsFeature(feature, origin) method currently returns whether origin is in policy's allowlist for feature (or is part of the default allowlist).
With the old header behaviour, this answered the question "would this feature be allowed in a document from that origin, in an iframe with no
allow
attribute?" -- that is, would the feature be automatically delegated to that origin.Now, with the new behaviour, being present in that allowlist does not imply that the feature would be automatically delegated. Instead, for a third-party origin, it means that the feature could be delegated, if the
allow
attribute is used. (This gets even more vague and tentative if we start looking at an iframe element's policy object, because then it tests whether the feature could be delegated, by another iframe tag inside the framed document, if the framed document matches thesrc
attribute, and hasn't been navigated to another origin, and if the framed document's header policy doesn't change anything)We could resolve this in a few different ways:
'self'
)Number 3 is probably possible; I've been looking for any evidence of usage of that API on the web, and in the entirety of HTTPArchive and the top 100k sites in the Chrome User Experience report, there is absolutely none. Sites I can observe in the wild only use
document.featurePolicy.allowsFeature(feature)
-- no origin, and not on an iframe element, just the document. The only usage I can find anywhere of the other forms of the API are in WPT, and those can be removed / rewritten.The text was updated successfully, but these errors were encountered: