-
Notifications
You must be signed in to change notification settings - Fork 74
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
Per-type enforcement #66
Comments
To update: we'll need per-type enforcement, given that the new types are likely to appear, and e.g. some authors may wish to control |
Semantically, can't this be done via a default policy that has the identity function for conversions that the application wants to opt out of? Is that not practical? |
That would still break applications if new types are being added. |
So the tradeoff then is CSP policy complexity vs flexibility in adding new types? One way to avoid that tradeoff is with a catchall: createTrustedDefault. |
Correct. |
I'm against specifying more than the bare minimum in header content. We ought prefer moving the complex portion of a policy in a general purpose programming language, not an ad-hoc language in a header. It seems that a catchall like Lengthy policies should be shipped in cacheable body content, not header content. If most CSP policies are written in As argued in #139 (comment) I think we should bias against adding new trusted types, but acknowledge that some will probably be necessary. |
Ack, those are valid points, though I think we can generalize the issue at hand to declarative vs programmatic configuration. (e.g. the fact that the header is not cacheable is a separate issue we could fix by e.g. putting the configuration in an Origin Policy or a well-known file). Parts of TT are already programmatic (e.g.
We can't go fully declarative either, as we'll quickly end up with a complex DSL - CSP demonstrates what happens then. For now the line is drawn that only the allowed policy names, reporting URL and the enforce/report/ignore behavior are configured declaratively. I want to explore whether it makes sense to have per-type enforcement be declarative as well. This changes the syntax of the configuration a bit, but maybe not so much (especially with option 2). That's for practical reasons: I end up almost always writing a default policy that is an equivalent of no cc @mikewest @otherdaniel - is there a canonical bug for the 'csp as a compilation target' idea? |
FWIW: I would very much like origin policy to be the solution here when it exists. I would love for us collectively to stop abusing response headers as policy configuration mechanisms.
Just the only-kidding-but-no-really-we-should-do-this "spec" at https://mikewest.github.io/artur-yes/. |
@mikewest, while I'm looking forward to the origin-policy existing, it will apply site-wide, so I only see it as being a baseline (or set of fallbacks) for the whole site. Whereas individual response headers (for each page) can be customised to lock that page down as much as possible. Or am I missing something? In my case, most pages do not use any trusted types (so it can use So for my origin-policy, I'd have to include the full list of 14 trusted types for the baseline (not ideal if I can't lock it down any further); or, as per your current CSP experiments, I'd prefer to provide a fallback of |
The current plan is to ship 4 types that focus on DOM XSS only ( There are no custom (user-defined) types planned, authors might use an approach like https://gist.github.com/koto/1d044f6029ee337beffb4487b80f8b02 to add a support for them. If additional types will surface (e.g. something for wasm), or we'd need another breaking (i.e the API introduces new enforcements) change in the future, we can introduce it via a new CSP directive keyword. But for now it seems like per-type enforcement is not needed - the types are "stable". |
Right now all the types can be enforced as a group. This happens for good reasons:
trusted-types
CSP directive), or not.However, it has one downside: the type list needs to be complete from the get go, as adding new types would break existing TT sites. We can already see interesting candidates for next batch of types -
TrustedTemplate
, orTrustedStylesheet
,TrustedStylesheetURL
, and if our approach turns out successful, I'm sure there will be more.This issue is to explore how we can change the enforcement declarative syntax to accomodate for potential new types.
Option 1: Enforce each type separately via keywords
trusted-types 'enforce-html' 'enforce-url' 'enforce-script-url
Adding new types becomes then just adding new policy
create*
functions and a new keyword. The downside is, the secure setting requires you to know about all possible types, although we can simplyfy this, and just assume that existing DOM-XSS related types are enabled by default iftrusted-types
directive is present, and leave theenforce-*
keywords for new, optional types. (e.g.TrustedURL
might be optional - see #65).Option 2: Tie type enforcement into existing CSP directives
Under this definition, scripts sinks would have to be typed, on top of their existing restrictions. Stylesheets, when introduced, would just add
style-src 'require-trusted'
. It's a bit clunky, as there's no 1:1 mapping between directives and types (e.g. there's no setting forTrustedHTML
, bothTrustedScript
andTrustedScriptURL
are underscript-src
), and it ties the whole TT quite deeply into existing CSP syntax with all its problems.Application could live on the edge by specifying
default-src: 'require-trusted'
to be opted into all possible types.The text was updated successfully, but these errors were encountered: