w3ctag / design-principles

A small-but-growing set of design principles collected by the TAG while reviewing specifications
https://w3ctag.github.io/design-principles
178 stars 46 forks source link

guidance on inheritance between contexts #111

Open wanderview opened 6 years ago

wanderview commented 6 years ago

There are a number of places in the web platform where some policy or state is inherited from one context to another. Its up to each feature in the platform to define how it gets inherited or not. The result is that there are a number of inconsistent inheritance behaviors.

Some downsides of this inconsistent behavior are:

  1. Confusing API surface for developers.
  2. Special case logic is required in implementations resulting in brittleness and increased security risk. (Many of the policies have security implications.)
  3. Increased cost to specifying a new feature because inheritance must be figured out again for each feature individually.

It might be nice to have some guidance on how inheritance should work on the web platform to produce a more consistent system.

Off the top of my head I can think of the following types of inheritance:

There are probably more cases to consider.

My personal preference would be to make all inheritable attributes align to the same source. So if a local URL inherits an origin from a context, then all other attributes are inherited from that same source context. If a context has its own URL that defines its own origin, then nothing is inherited from other contexts.

Thanks for your help sorting this out!

annevk commented 6 years ago

(Note that I've found at least one case where we have to inherit into dedicated workers (though alternatively we could treat this header as setting a policy for the agent cluster, which seems somewhat attractive in a way and would sidestep this inheritance question): Upgrade-No-CORS.)

nhiroki commented 5 years ago
  • referrer policy: I believe referrer policy is inherited from documents to a dedicated worker, but I'm less sure about this one.

In the current HTML spec, a dedicated worker doesn't inherit its parent's referrer policy (whatwg/html#3270)

nhiroki commented 5 years ago
  1. Special case logic is required in implementations resulting in brittleness and increased security risk. (Many of the policies have security implications.)

+1. This inconsistency makes the Blink implementation and WPT complicated. cc: @hiroshige-g

annevk commented 5 years ago

@nhiroki did you see https://github.com/whatwg/html/issues/4916?

nhiroki commented 5 years ago

@annevk Sorry for the late reply. Yes, I read the issue.

I heard there was a discussion about the policy inheritance at TPAC from @hiroshige-g. I'll update/close whatwg/html#3270 based on the final decision.

hiroshige-g commented 5 years ago

We (mainly @mikewest @annevk @wanderview @hiroshige-g) had a discussion around TPAC 2019, and reached a consensus: NOT to inherit parent context's policy, except for <iframe srcdoc>, <iframe src="about:blank">, data: dedicated workers etc., and use the same inheritance rule across policies (CSP, referrer policy, etc). @annevk's https://github.com/whatwg/html/issues/4926 is based on the discussion.

More detailed summary is here: https://docs.google.com/document/d/1CAegq63QY0HMW-66zG4wgawIaWGi33MHtmU3azQQNz8/edit?usp=sharing

hiroshige-g commented 5 years ago

@annevk please let me know if I'm missing something or not summarizing correctly.

annevk commented 5 years ago

Thanks for writing that up @hiroshige-g, looks good to me!

hober commented 4 years ago

@kenchris and I took a look at this during the TAG F2F this week. We're really happy that the TPAC discussion was so fruitful. We'll hold off on adding something to the Design Principles document until whatwg/html#4926 is resolved. Thanks!

hiroshige-g commented 4 years ago

FYI some updates: I'm doing some investigation to see how policies etc. are set in different contexts and how (in)consistent they are. I've found some issues (e.g. https://github.com/whatwg/html/issues/5474 https://github.com/whatwg/html/issues/421) but they look relatively minor.

I also investigated the of feasibility of changing CSP inheritance rule. Originally I was wondering comparing CSPs of parent Documents and worker script's response headers and seeing whether they are the same, but when I looked at some major websites, they set different policies (due to nonce, due to minor diffs, or just setting completely different CSPs).

kenchris commented 4 years ago

@hiroshige-g Do you think some recommendations can be crafted from your investigation? In which case what would they be?

kenchris commented 4 years ago

Friendly ping @hiroshige-g !