(Translated by https://www.hiragana.jp/)
Correct CSP source values by wbamberg · Pull Request #35947 · mdn/content · GitHub
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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

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-09-30 05:02:31)

@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
Comment on lines +36 to +45
This directive may have either:

- the single keyword value `'none'`, meaning that no base URI may be set using a `<base>` element
- a list of _source expression_ values, meaning that a `<base>` element may set a base URI if it matches any of the given source expressions.

The syntax for each source expression is given in [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources). However, only the following subset of those values apply to `base-uri`:

This directive uses the same [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources) syntax for arguments as other CSP directives. However, only values that match URLs make sense for `base-uri`, including `<host-source>`, `<scheme-source>`, `'self'`, and `'none'`.
- `<host-source>`
- `<scheme-source>`
- the keyword value `'self'`.
Copy link
Collaborator

@hamishwillee hamishwillee Sep 30, 2024

Choose a reason for hiding this comment

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

There is nothing wrong with this, except it feels like a non-standard presentation form.
This can be done in the standard way with sources as shown below. I would prefer that, but obviously up for discussion.

### Sources

- `'none'`
  - : A single keyword value, meaning that no base URI may be set using a `<base>` element
- `<source-expression-list>`
  - : A list of _source expression_ values, meaning that a `<base>` element may set a base URI if it matches any of the given source expressions.

    The syntax for each source expression is given in [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources).
    However, only the following subset of those values apply to (make sense for) `base-uri`:

    - `<host-source>`
    - `<scheme-source>`
    - the keyword value `'self'`.

Either way we should say that the list is space separated?

This applies to the rest too. I won't modify or suggest again - just scan for consistency.

This directive uses the same [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#sources) syntax for arguments as other CSP directives. However, only values that match URLs make sense for `base-uri`, including `<host-source>`, `<scheme-source>`, `'self'`, and `'none'`.
- `<host-source>`
- `<scheme-source>`
- the keyword value `'self'`.

## Examples
Copy link
Collaborator

@hamishwillee hamishwillee Sep 30, 2024

Choose a reason for hiding this comment

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

It would be great to have one example showing multiple sources, and using the HEADER format - i.e. we show meta format here and some config stuff for apache and nginx, but in all the other cases the HTTP header is shown.


Note that this same set of values can be used in all {{Glossary("fetch directive", "fetch directives")}} (and a [number of other directives](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources#relevant_directives)).
The syntax for each source expression is given in [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources).
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is it a syntax, but it might be better to refer to it as permitted or allowed values? Further, down to here we haven't mentioned URL or keyword - just "sources". Does that seem reasonable? At this point I'm already wondering what this list might look like. At least if we mention URL it is a little less abstract.

Suggested change
The syntax for each source expression is given in [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources).
The allowed URL patterns and keyword values for each source expression are given in [CSP Source Values](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy/Sources).

If not here, it would be good to say this right up in the introduction - .e.g

The HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP)child-src directive defines the valid URL pattern and keyword sources for ...

@@ -7,8 +7,13 @@ spec-urls: https://w3c.github.io/webappsec-csp/#framework-directive-source-list

{{HTTPSidebar}}

HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) header directives that specify a `<source>` from which resources may be loaded can use any one of the values listed below.
Relevant directives include the {{Glossary("fetch directive", "fetch directives")}}, along with others [listed below](#relevant_directives).
HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) [fetch directives](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#fetch_directives) may take as a value a space-separated list of _source expressions_. Each source expression can be any of the values listed below.
Copy link
Collaborator

@hamishwillee hamishwillee Sep 30, 2024

Choose a reason for hiding this comment

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

Shouldn't we still mention none? It's not a source, but it is important and relevant.

If so, maybe this way [placeholder only]

Suggested change
HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) [fetch directives](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#fetch_directives) may take as a value a space-separated list of _source expressions_. Each source expression can be any of the values listed below.
HTTP {{HTTPHeader("Content-Security-Policy")}} (CSP) [fetch directives](/en-US/docs/Web/HTTP/Headers/Content-Security-Policy#fetch_directives) may take as a value a space-separated list of _source expressions_ or `none` (indicating that Xxxxx). Each source expression can be any of the values listed below.

Otherwise a note at the end of the intro "Not strictly a source, but the value none ..."

@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.

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