-
(This is an expanded version of mdn/content#35947 (comment), which I thought deserved wider consideration.) I've been doing some work on CSP lately, and have some suggestions for how we document CSP source expressions. BackgroundCSP consists of a number of directives, each of which controls some aspect of the security policy. Each directive has its own syntax. The biggest group of directives are the fetch directives, which control the resources - images, fonts, scripts, stylesheets, workers, etc - that a document may load. According to the spec, fetch directives all have the same syntax: https://w3c.github.io/webappsec-csp/#grammardef-serialized-source-list. This is: either the keyword value HistoryObviously, we need to document the source expression values that each directive may take. Back in the days of the
Then through mdn/content#5732 and mdn/content#11185, we ended up factoring the source value syntax into a single separate page: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources. All fetch directives (plus a couple of other directives that have the same grammar) point to this page for the syntax. For example: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/font-src#source-expression-list . Although I advocated for this at the time, I didn't understand fetch directive syntax very well and now I think this was a mistake. ProblemsAlthough per spec, source expressions all have the same syntax, in practice they don't: although you are allowed to use, say, So I think listing all source expression values as valid values for all fetch directives is confusing: it makes the syntax seem more complex than it really is, while forcing developers to understand that depending on the directive they're looking at, many of the listed values aren't actually applicable. I've tried to look at this systematically in https://docs.google.com/spreadsheets/d/1UtOEWR4j-lxClWwbxOMLEjFwIBnSgO0L9x-VXgKHiCc/edit?gid=0#gid=0: columns are source expression values, and rows are fetch directives. As far as I can tell:
ProposalMy proposal is something like:
|
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 6 replies
-
Interesting proposal, @wbamberg. Thanks for writing, and sharing with all of us! Hope this will be discussed in the Content call next Monday. 👍 |
Beta Was this translation helpful? Give feedback.
-
As per mdn/content#35947 (comment) I agree that what we do not doesn't work - the sources are too separated from where they are used and so context is lost. We can solve this either by choosing to duplicate content, or link as you are suggesting. Duplicating is best for readers, linking is best for maintainers. Either is better than what is there now. I am not sure about having the sources in the directive page vs in default-src. I kind of like the default-src since it can take all the arguments anyway, that means you don't have to link elsewhere for more information in that page.
If it were entirely up to me, I would be inconsistent and do limited duplication on the cases where we have only a few options.
|
Beta Was this translation helpful? Give feedback.
Thanks for this response!