Skip to content
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

Correct CSP source values #35947

Merged
merged 8 commits into from
Oct 4, 2024
Merged

Conversation

wbamberg
Copy link
Collaborator

@wbamberg wbamberg commented Sep 18, 2024

This PR fixes a few errors in the documentation of CSP directive syntax.

The page for frame-ancestors does not point to https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources, instead redefining the values. I have left this as it is for now, because the definition for this directive does use a different type (https://w3c.github.io/webappsec-csp/#directive-frame-ancestors) although it seems to be functionally identical. I think we should update this to point to the "sources" page, but before doing that I want to check there isn't some subtle reason why the syntax is redefined for this directive.

The changes are quite repetitive for the directives pages: I changed/corrected the syntax and removed the ### Sources heading, as it seemed easier to talk about 'none' without it.

In https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources I removed the list of fetch directives, since we already have that in https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#fetch_directives, so that's just 2 places we have to maintain it.

@wbamberg wbamberg requested a review from a team as a code owner September 18, 2024 23:25
@wbamberg wbamberg requested review from hamishwillee and removed request for a team September 18, 2024 23:25
@github-actions github-actions bot added Content:HTTP HTTP docs size/m [PR only] 51-500 LoC changed labels Sep 18, 2024
Copy link
Contributor

github-actions bot commented Sep 18, 2024

Preview URLs (22 pages)

(comment last updated: 2024-10-02 18:55:49)

@wbamberg wbamberg requested a review from a team as a code owner September 18, 2024 23:31
@wbamberg wbamberg requested review from jpmedley and removed request for a team September 18, 2024 23:31
@github-actions github-actions bot added the Content:WebExt WebExtensions docs label Sep 18, 2024
@hamishwillee
Copy link
Collaborator

Yes/agree to everything you said in the introduction - I wandered the same path through the spec you must have and agree.

Not sure about the pattern you adopted though. I would have preferred the more familiar DL list approach (comment above).
A few other minor points which you might choose to ignore, but I think we could look at while we're here - specifically, in all the directive docs we refer to the sources, but you don't get the idea that these are URL patterns or keywords until you get down to the examples. That seems a bit wrong.

@wbamberg
Copy link
Collaborator Author

wbamberg commented Oct 2, 2024

Thanks for your comments Hamish, very helpful. This is ready for another round.

Copy link
Collaborator

@hamishwillee hamishwillee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @wbamberg - whole thing much better. Merging.

Two slight niggles since they are on my mind, is that when you're on the Source page,

  • we refer that they are used by fetch directives, and those are listed in the sidebar - but if you click the link you get taken to a completely different context that does not include the directives. So if you aren't sure about what directives are you'll be out of context. We might have listed a couple here (i.e. "fetch directives such as ...")
  • The sources page is very abstract - showing an example using one of them in this context might have been useful.

I'm just niggling, as you say, so much that might be done around this area.

@hamishwillee hamishwillee merged commit be48127 into mdn:main Oct 4, 2024
8 checks passed
@wbamberg
Copy link
Collaborator Author

wbamberg commented Oct 4, 2024

Thanks @wbamberg - whole thing much better. Merging.

Two slight niggles since they are on my mind, is that when you're on the Source page,

  • we refer that they are used by fetch directives, and those are listed in the sidebar - but if you click the link you get taken to a completely different context that does not include the directives. So if you aren't sure about what directives are you'll be out of context. We might have listed a couple here (i.e. "fetch directives such as ...")

  • The sources page is very abstract - showing an example using one of them in this context might have been useful.

I'm just niggling, as you say, so much that might be done around this area.

Happy for you to file issues for these two. I think nav/IA for the CSP docs is a bit tricky though. It might be better to subsume the "Sources" page inside the CSP header page - currently "Sources" appears under "CSP directives" (and has that page type) but it isn't a directive of course.

@hamishwillee
Copy link
Collaborator

hamishwillee commented Oct 6, 2024

It might be better to subsume the "Sources" page inside the CSP header page - currently "Sources" appears under "CSP directives" (and has that page type) but it isn't a directive of course.

I was going to say "no, that's a huge page and this would make it even more monolithic. "
However on reflection I do think it would be significantly better because I find the sources page to be so isolated from its context.

My reasoning is that the page already has a values section: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#values . That section makes sense to me because you have the context and examples. The additional information that you'd add by merging would not make this much bigger.

@wbamberg
Copy link
Collaborator Author

wbamberg commented Oct 8, 2024

It might be better to subsume the "Sources" page inside the CSP header page - currently "Sources" appears under "CSP directives" (and has that page type) but it isn't a directive of course.

I was going to say "no, that's a huge page and this would make it even more monolithic. " However on reflection I do think it would be significantly better because I find the sources page to be so isolated from its context.

My reasoning is that the page already has a values section: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#values . That section makes sense to me because you have the context and examples. The additional information that you'd add by merging would not make this much bigger.

Having spent some time with this "source values" page, another option, which you might not like but bear with me.

The history of this page is something like: back in the days of the {{page}} macro:

  • the script-src* and style-src* pages transcluded their content from default-src
  • the other directives transcluded their content from connect-src

Then through #5732 and #11185, we ended up factoring the source value syntax into a single separate page.

Although I advocated for this at the time, I didn't understand directive syntax very well and now I wonder if this was a mistake.

In particular, the script-src* and style-src* directives are the only ones that support the keywords (except 'self'). So in all cases like connect-src, font-src etc, people have to read this page and mentally exclude all those keywords, making it more complicated than it needs to be.

Apart from that, there are smaller differences, to accommodate which means we end up being quite elliptical or misleading in our language. For instance, in the doc for <host-source> we say things like "Matches all attempts to load ..." but with base-uri we're not loading anything.

Maybe we should after all duplicate this syntax in all the directives. I think we could also streamline some of the existing items here (e.g. I think the list of schemes at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#scheme-source is odd - are these the only possible values? I don't think so, so why are just these ones listed? Similarly most of https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#host-source is taken up with a list of examples, maybe we could find a single place to have some examples?).

@hamishwillee
Copy link
Collaborator

@wbamberg Re ^^^ #35947 (comment)

Either subsuming the source page into the header page or splitting the sources into the directive pages would vastly improve the context problem.

For readers duplicating would easily be the best solution if we can live with the duplication/maintenance.

Might we consider reverting to the original pattern for script-src* and style-src* pages default-src, but linking rather than transcluding?
In other words

  • move all of this source doc to default-src and link to that from script-src* and style-src* pages.
  • Duplicate the host-source, scheme source, self for all the other cases, fixing up as needed to be specific.

I think the list of schemes at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#scheme-source is odd - are these the only possible values? I don't think so, so why are just these ones listed?

Yes. That's the same as any other list case - we either need to cut this back and link to or provide info about the comprehensive support, or provide a full list.

Similarly most of https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#host-source is taken up with a list of examples, maybe we could find a single place to have some examples?).

I think I'd cut the examples back to 2 say, and link to the default source for more?

@wbamberg
Copy link
Collaborator Author

@wbamberg Re ^^^ #35947 (comment)

Either subsuming the source page into the header page or splitting the sources into the directive pages would vastly improve the context problem.

For readers duplicating would easily be the best solution if we can live with the duplication/maintenance.

Might we consider reverting to the original pattern for script-src* and style-src* pages default-src, but linking rather than transcluding? In other words

* move all of this source doc to `default-src` and **link** to that from `script-src*` and `style-src*` pages.

* Duplicate the host-source, scheme source, self for all the other cases, fixing up as needed to be specific.

This would effectively revert the fix for #5286, although we could fix that in the prose by talking about "scripts or styles" although that's kind of what I meant about "elliptical and misleading language". But maybe that's a better tradeoff that full duplication.

Main thing I think is for non-script and style directives to omit the keyword values, as this adds a lot of stuff to ignore.

I think the list of schemes at https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#scheme-source is odd - are these the only possible values? I don't think so, so why are just these ones listed?

Yes. That's the same as any other list case - we either need to cut this back and link to or provide info about the comprehensive support, or provide a full list.

Exactly. Presenting things a list always seems to carry the expectation that it will be exhaustive. Better IMO to give the commonest examples and warn people about data:.

Maybe I will repurpose #36198 to try out some version of this plan.

@hamishwillee
Copy link
Collaborator

Maybe I will repurpose #36198 to try out some version of this plan.

Sure. I think trying a minimal version and getting feedback would be good - i.e. update default-src and link from scrip-src. That would tell us if this is acceptable cross linking.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Content:HTTP HTTP docs Content:WebExt WebExtensions docs size/m [PR only] 51-500 LoC changed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants