WICG / document-policy

https://wicg.github.io/document-policy/
Other
19 stars 8 forks source link

Nested context required document policy never appears to be set? #38

Closed domfarolino closed 2 years ago

domfarolino commented 3 years ago

Create a required policy for a browsing context appears to be the algorithm where we acatually create the Document Policy that contains a union of all document policies (for duplicates, we take the strictest) from the following two sources:

Only nested context required document policy never appears to be set anywhere, so I can't imagine the "Create a required policy for a browsing context" ever does the correct thing, right?

domfarolino commented 3 years ago

OK I dug into this a bit more today and I have some more critiques and thoughts. It is a bit confusing to track how Document Polices combine/coalesce throughout various levels of the subframe hierarchy, for a few reasons:

Bugs

In terms of bugs I've spotted in the spec, there are at least a few:

Confusing/duplicate members

My read of the spec is the following (and please read the -> syntax as if it were C++ pointer syntax):

Now we get to the members stored on the browsing context concept

It is (2) + (3) that I think the spec's concept of the nested context required document policy meant to represent. In other words, when a document loads we know it had to at least meet the bar set by its browsing context's required document policy, but if that document was sent with additional restrictions in the form of the Required-Document-Policy response header that should begin to take effect for subframes rooted at this document, then we need to make sure the nested browsing context of any subframes we have, has a required document policy of at least our bc's required document policy plus the restrictions in the form of our R-D-P header! We should fix this!

//cc @domenic

clelland commented 2 years ago

Thanks for the very thorough review, @domfarolino! The spec is in pretty sad shape, but I think I have some time to take care of the most egregious issues now.

To the specific points:

  1. Yes, nested context required document policy is not set anywhere. That's this issue.
  2. Opener vs top-level is relevant to sandboxing; there was a plan (see https://github.com/WICG/document-policy/issues/22#issuecomment-562612153) is to propagate document policies to sandboxed frames. In that case. only top-level contexts with no opener are guaranteed to start with a blank policy. The statement there is probably not needed, and all of the logic for determining the initial state should go into the algorithms.
  3. Require-Document-Policy does need to be read, at the same time as Document-Policy.
  4. The document should have the policy; The 'declared policy' is intended to be the policy which was declared in the Document-Policy response header, and that is necessarily the policy in effect (If there were stricter requirements, then the document would not have loaded). The HTML integration section should actually set that somewhere.
clelland commented 2 years ago

I've updated the spec to fix most of these issues, I think. Take a look and see what's still outstanding: