#408: Feature Policy: Document Policies

Visit on Github.

Opened Aug 13, 2019

こんにちはTAG!

I'm requesting a TAG review of:

Further details:

You should also know that the initial Feature Policy spec, which was reviewed previously (#159) by TAG, can be simplified with the adoption of Document Policies. The goal is to constrain it to just those features which are best served by the "allowed at top-level, delegate to cross-origin frames" model, and focus it tightly on that use case.

You should also also know that this explainer is the result of discussions which were also previously noted by TAG in #341.

This request has been updated (2020-12-08) to reflect the new repository which was opened in WICG for Document Policy, as a result of https://github.com/w3c/webappsec-permissions-policy/issues/411.

We'd prefer the TAG provide feedback as (please select one):

  • open issues in our GitHub repo for each point of feedback
  • open a single issue in our GitHub repo for the entire review
  • leave review feedback as a comment in this issue and @-notify [github usernames]

Discussions

Discussed Sep 4, 2019 (See Github)

Dan: I will work on this before the f2

Comment by @clelland Jan 24, 2020 (See Github)

Friendly ping to TAG :) Is there any update on this since the TPAC f2f?

Discussed Jan 27, 2020 (See Github)

bumped and Dan will try to find someone to work with on it.

Comment by @torgo Jan 27, 2020 (See Github)

Sorry we haven't made enough progress here. We'll try to wrap things up in in 2 weeks.

Discussed Feb 24, 2020 (See Github)

Dan: what is the user need? Feels like it needs to be better documented... Feels very overly complex...

Ken: Document policy enforced? Required document policy / etc... how do these relate? Policies split into 3 different groups- this is part of it. A bit confused between the different types...

[comments in issue]

Ken: How are we gonna make sure these features are consistent... consistency needed... if presentation lock, shouldn't there be one for orientation lock? Need consistency... same names...

Dan: is that a design principles thing?

Dan: reached out to Andrew Betts for additional comment.

Ken: an overview... requires acklnwoledgement flag... What is an associated flag?

Dan: added more comments... let's move on for now

Comment by @kenchris Feb 25, 2020 (See Github)

How does Document-Policy, Require-Document-Policy and Sec-Required-Policy relate to eachother and to the attribute "policy" (used for iframe etc, I assume that is mapped to Document-Policy).

I think the explainer should make this clear early on

Comment by @torgo Feb 25, 2020 (See Github)

Hi @clelland apologies this is taking so long. One poinf of feedback I have is that the explainer could be a bit clearer on the user need. Also: is there anything further on the spec itself?

A bit of elaboration on the detail in the explainer. For example, example one talks about performance guardrails. What is a guardrail? The example talks about "documents" and resources, but can we state this example in terms of (for example) "a commercial web site embeds ads from different 3rd parties and wants to ensure an overall good performance for the user so makes use of this feature policy to... xyz" - basically making it more clear what we aare talking about.

Comment by @kenchris Feb 25, 2020 (See Github)

Some things are not very clear in the explainer, like "associated flag, requires-acknowledgement".

What is an associated flag? I guess it is not a header as it is lower-case, also probably not an attribute either, so I guess this is part of the value, like "image-compression;bpp=4 requires-acknowledgement" also I believe the US spelling of "acknowledgment" is without the latter e

Comment by @clelland Feb 25, 2020 (See Github)

Thanks for taking a look -- I'll see if I can update the explainer. Some of the more formal bits can probably be removed now, since they're covered in the actual spec text.

To answer the questions here in advance of that:

  1. There are three headers and an attribute, which work together like this:
  • Document-Policy: Response header which sets the policy for the document it is delivered with.
  • Require-Document-Policy: Response header which sets a minimum policy for any embedded content.
  • <iframe policy>: attribute which sets a minimum policy for any content loaded into that frame.
  • Sec-Required-Document-Policy: Request header, which details the minimum policy required for the document being requested.

Essentially, if there is a minimum policy required (in most cases there won't be, unless Require-Document-Policy or <iframe policy> has been used) then it is advertised to the server with the Sec-Required-Document-Policy header. If the document in the response doesn't meet that requirement, then it will not be loaded.

  1. The spec has been updated since I filed this request (I'll update the issue with the link there) There are still a couple of sections needing to be fleshed out, but the algorithms and structures are all there, I believe.

  2. "Guardrails" is an informal term we've been using to talk about controls that make it easier for developers to succeed, to create performant sites, either by removing poorly-performing APIs, or letting them know through reporting when they're doing something that is likely to be slow. I'll see if I can rewrite that, either to explain it or to use clearer terms.

  3. The 'requires-acknowledgment' flag is part of definition the feature itself, and not something that is up to a developer to control. We would define that flag for a feature based on whether or not it is safe to impose the policy on a subframe without requiring the subframe to explicitly set it in its own Document-Policy header.

    As a couple of examples:

    • If we define a document policy feature to disable document.write, that could have unintended consequences on pages which aren't aware that it could be disabled, potentially introducing security bugs on a previously-safe page. So that policy would require acknowledgment. You could set it on your own document, but you can't impose it on another one without its consent.
    • If we define a policy that requires images to have declared sizes, to improve layout speed, that would likely not cause any drastic consequences to a page that wasn't aware of the policy (other than maybe making it look worse). We could probably safely impose that policy without needing the embedded page to acknowledge it explicitly.
    • Also, iframe sandboxing already defines a number of similar features that can be disabled, that don't require acknowledgment, and this has generally been okay. If we want to use Document Policy to explain sandboxing, then those features should be implemented in a way that doesn't require acknowledgment.
Comment by @kenchris Mar 3, 2020 (See Github)

I think it would be nice if the spec was a bit clearer on what are request and response headers - like you could group them in different sections.

Also as Require-Document-Policy is about content couldn't we make that clearer in the name, like Content-Policy or Document-Content-Policy. Then if <iframe policy> became <iframe content-policy> - then the relation would also be clearer

Comment by @kenchris Mar 3, 2020 (See Github)

I think the specification could use more examples, for instance I have trouble understanding parts like the requires-acknowlegment:

When explicit acknowledgment of a required policy is not required, similar to iframe sandbox, this means that behaviors of existing features may be changed in published web sites, by embedding them in another document with an appropriate required policy.

Comment by @atanassov Mar 3, 2020 (See Github)

Consider adding an example with deeper (more than one level) nesting in the section on Deeper Nesting. It was unclear if the Sec-Required-Document-Policy would be carried through deeply nested iframes in the case of no policy attribute being set.

Perhaps the example of your last section can be introduced earlier?

Comment by @clelland Mar 5, 2020 (See Github)

Also as Require-Document-Policy is about content couldn't we make that clearer in the name, like Content-Policy or Document-Content-Policy. Then if <iframe policy> became <iframe content-policy> - then the relation would also be clearer

@kenchris are you suggesting renaming the overall spec from "Document Policy" or just the headers / iframe attribute?

(I'm not super attached to the name, if we can find a better one. It's pretty generic as-is)

Comment by @clelland Apr 16, 2020 (See Github)

I've rewritten big parts of the explainer, hopefully to provide clearer explanations, as suggested above. The spec is also in a better place, and should be the final word on any algorithm questions and other speccy things.

Comment by @kenchris Sep 22, 2020 (See Github)

For self sandboxing, reporting seems to be a big deal - it is supported by the spec but not mentioned at all in the explainer. I think it should be. I could see an admin setting a document policy for a whole web site, with separate teams (maybe in other countries) creating the actual content that now might be blocked due to such a policy, thus reporting is quite important

Comment by @kenchris Sep 22, 2020 (See Github)

Are other browser vendors interested in this and has it gotten a more wide review?

Discussed Nov 16, 2020 (See Github)

Dan: asked for current status - looks stalled - hopefully we get feedback by the plenary and close it off.

Ken: Sounds good to me.

Comment by @torgo Nov 17, 2020 (See Github)

Hi @clelland - could you briefly let us know what the latest status is on this and how the TAG can best provide value here?

Comment by @clelland Nov 17, 2020 (See Github)

Hi @torgo,

Regarding the spec and explainer:

  • As mentioned in previous comments, the spec and explainer have both been updated since March, to incorporate the comments from TAG. (I should still address the comments in https://github.com/w3ctag/design-reviews/issues/408#issuecomment-594227064 specifically).
  • The requires-acknowledgment bits have been removed
  • The special "no-<feature>" syntax has been replaced with standard structured-field boolean False syntax.

Regarding implementation status:

  • Chrome has shipped support for just the Document-Policy header, to provide an document-level opt-out mechanism for Scroll-to-text-fragment.
  • Chrome is considering using Document Policy to provide a similar opt-out for use of sync-xhr and document-domain, hopefully as a path to eventual deprecation of those features.

Regarding interest:

  • There has been discussion in the security community about using Document Policy as a means of lowering usage of security-negative features on the web platform, by making them opt-in. (See https://cloud.arturjanc.com/secweb-2020.pdf)
  • There is interest, but not interest, from Mozilla, on both Document Policy and its use for sync-xhr. See MSP, XHR and comments here.

For TAG: Despite Chrome shipping the initial header, there are still some outstanding issues that I would love TAG feedback on. Roughly in order of importance:

  • We've deliberately not shipped the negotiation mechanism; I'm a bit concerned that "policy" is a very generic term to use for the attribute, and would like confirmation that it's a good choice before ossifying it.
  • I'm pretty convinced that the mechanism, based on CSP-embedded-enforcement, is sound, but it would be good to get TAG's opinion on that as well.
  • There is an open question as to whether a JS API would be a good idea for introspecting the active policy.
  • There are also questions about how an enum type should work with required policies; I haven't written those down yet, but essentially, it seems easy for a single document to specify its configuration as a single value from an enumerated set of tokens. It is much harder to provide a generic mechanism to state requirements on a document about allowed enum values. In some cases, there may be a strict linear ordering between values, but in other cases, the relationship may not be so clear. I'm happy to expand on that if it's useful, or maybe the best thing is to remove all mention of enums from the spec right now and reintroduce them later when there are actual use cases.
Discussed Nov 23, 2020 (See Github)

reviewing last comment

[considering Ian's bullet points]

Ken: not sure I can think of a better name [than policy]....

Dan: I think we need to take these questions to plenary and maybe close the issue if appropriate.

Ken: worried about wide review from other browsers. Seems to be a very core thing, an architectural thing.

Comment by @torgo Nov 24, 2020 (See Github)

Thanks @clelland we are taking a look at the questions you raised and will endevour to get some thoughts back to you this week.

Discussed Dec 7, 2020 (See Github)

Dan: looking for specific feedback on 4 points listed in issue.. let's see if we can get them feedback on those points.

... Not shipped negotiation mechanism... naming issue. Ossifying.

reviewing last comment

Dan: regarding the use of the term "policy" - I agree it's confusing.

Hadley: also not very descriptive... if you came across this on its own it's not clear what it does...

Sangwhan: might suggest "features" - but that's also confusing...

Dan: the first 2 examples are about performance. Others are about security.

Sangwhan: feature policy got split up between document policy and permission policy...

Dan: it's very complex... How do you explain this to a regular web developer.

Sangwhan: don't see average web developers using this - There will be "silver bullet" policies. This is opt in as well..

Dan: maybe we don't have any useful feedback on the naming other than that the current name is not so developer-friendly (self-descriptive).

[on the API]

Sangwhan: we have a permissions API... It should be unified...

Alice: on naming: the name fits together with the use of document policy header.

Sangwhan: on the 4th point (enum) I would lean towards waiting until we see an actual consumer.

Dan: let's try to close this in plenary after leaving this feedback.

Comment by @cynthia Dec 8, 2020 (See Github)

There is an open question as to whether a JS API would be a good idea for introspecting the active policy.

Since there is already a permissions API, as long as the naming (of the permissions being queried) is consistent it feels like extending functionality that is missing on that end is more sensible. (if there is any - if it's just for querying then that's already covered?)

(Also noticed the same point was brought up in the issue - should I continue there?)

Comment by @torgo Dec 8, 2020 (See Github)

Regarding the naming - we've discussed in breakout and we don't have a better idea. However, we agree the current naming is not very self-descriptive and therefore could be confusing to developers who want to figure out what this does and how they can use this (though it does follow on from the header). We recommend you do some user-research with developers - explaining what it is and getting feedback. Regarding the mechanism, we don't see any issues with the CSP-based approach.

Comment by @cynthia Dec 8, 2020 (See Github)

There are also questions about how an enum type should work with required policies; ... maybe the best thing is to remove all mention of enums from the spec right now and reintroduce them later when there are actual use cases.

This sounds like a reasonable plan forward. (We are a bit afraid of having a mechanism that doesn't cover a use case when we actually have one - we have made these mistakes in the past.)

Comment by @clelland Dec 8, 2020 (See Github)

Thanks for the feedback!

Since there is already a permissions API, as long as the naming (of the permissions being queried) is consistent it feels like extending functionality that is missing on that end is more sensible. (if there is any - if it's just for querying then that's already covered?)

(Also noticed the same point was brought up in the issue - should I continue there?)

This sounds more appropriate for Permissions Policy (where the point was definitely brought up) -- the features covered by that mechanism are mostly suitable for inclusion in permissions.query.

The configuration space of Document Policy features may be more complex, involving at a minimum floats, ints and bools for a given configuration point. An API would probably answer questions like "what was the (minimum) required policy on this document?", "what is the current policy for this configuration point?", "If I create an iframe like this, what will its required policy be?" -- I don't know if the permissions API is suited for that.

Regarding the naming - we've discussed in breakout and we don't have a better idea. However, we agree the current naming is not very self-descriptive and therefore could be confusing to developers who want to figure out what this does and how they can use this (though it does follow on from the header). We recommend you do some user-research with developers - explaining what it is and getting feedback.

I'll see what I can do along those lines, thanks!

Regarding the mechanism, we don't see any issues with the CSP-based approach.

That's great to hear 😄

This sounds like a reasonable plan forward. (We are a bit afraid of having a mechanism that doesn't cover a use case when we actually have one - we have made these mistakes in the past.)

Sounds good, thanks 👍 I'll see about removing that from the spec until there is a clear use case.

Comment by @cynthia Jan 13, 2021 (See Github)

Thanks for taking the time to discuss this with us! We'll close this for now and revisit when the spec is closer to it's final shape.