CSP: Fork url hash tests into url-sources/ and strict-dynamic-url/
The tentative tests in content-security-policy/script-src/tentative test url
hashes, but most of them would equally apply to other syntaxes of sources which
allow a script by its URL string, which are being discussed in the issue
below. They also aren't limited to script-src, e.g. worker-src applies to
workers. And 'strict-dynamic-url' isn't about matching URLs at all.
So fork them into two new directories, like the existing ones for other kinds
of sources and keywords (e.g. unsafe-hashes):
- content-security-policy/url-sources/tentative/ for sources which allow a
script by its URL string ("url sources"). Each test file has a variant for
each syntax, given in the source parameter; for now only ?source=hash for
url hashes. url_source() in support/util.js returns the url source for a URL
string in the syntax of the variant, and assert_url_source_report() checks
the members of a violation report for it.
- content-security-policy/strict-dynamic-url/tentative/ for the behavior of
'strict-dynamic-url' which doesn't depend on url sources. The behavior with
scripts allowed by url sources is tested in url-sources/.
The tests are the same as the existing ones, with these changes:
- They're .window.js files, with the support code shared in support/util.js.
Tests which load a script with a policy and check whether it ran use
url_string_test() there, which takes the URL string the script is requested
with, the URL strings its url sources allow, and the directive and other
sources of the policy. The tests of more than one policy, of violation
reports and of 'strict-dynamic-url' keep their own promise_test().
- Test names say "url source" rather than "url hash", unless they're about a
hash of something else, e.g. of an inline script.
- Scripts are allowed by the url source of the URL string they're requested
with (e.g. the value of the src attribute), as discussed in the issue below,
rather than of the absolute URL it resolves to. Where the existing tests
request a script with an absolute URL string, both are the same. The worker
violation report tests now import the blocked script with an absolute URL
string too, so that the reported url source doesn't depend on which of the
two it's computed from. So none of the forked tests depend on whether the
absolute URL is matched: they pass both when matching as in the spec PR and
when only the URL string is matched.
- The relative URL tests are in forms.https.window.js, run with the policy in
the header only, as delivering it in a meta tag is tested by the other
files.
- The violation report tests are in one file for documents and each type of
worker, with the policies delivered as headers through pipes, and only check
the members relevant for url sources. The evalHash member will be tested
with eval hashes.
The existing tests are left as they are for now, and can be removed once the
new ones have landed.
Explainer: https://github.com/explainers-by-googlers/script-src-v2
Spec PR: https://github.com/w3c/webappsec-csp/pull/784
Issue: https://github.com/w3c/webappsec-csp/issues/826
The web-platform-tests Project is a cross-browser test suite for the Web-platform stack. Writing tests in a way that allows them to be run in all browsers gives browser projects confidence that they are shipping software that is compatible with other implementations, and that later implementations will be compatible with their implementations. This in turn gives Web authors/developers confidence that they can actually rely on the Web platform to deliver on the promise of working across browsers and devices without needing extra layers of abstraction to paper over the gaps left by specification editors and implementors.
The most important sources of information and activity are:
wpt:matrix.org matrix channel; includes participants located around the world, but busiest during the European working day.If you'd like clarification about anything, don't hesitate to ask in the chat room or on the mailing list.
Clone or otherwise get https://github.com/web-platform-tests/wpt.
Note: because of the frequent creation and deletion of branches in this repo, it is recommended to “prune” stale branches when fetching updates, i.e. use git pull --prune (or git fetch -p && git merge).
See the documentation website and in particular the system setup for running tests locally.
The wpt command provides a frontend to a variety of tools for working with and running web-platform-tests. Some of the most useful commands are:
wpt serve - For starting the wpt http serverwpt run - For running tests in a browserwpt lint - For running the lint against all testswpt manifest - For updating or generating a MANIFEST.json test manifestwpt install - For installing the latest release of a browser or webdriver server on the local machine.wpt serve-wave - For starting the wpt http server and the WAVE test runner. For more details on how to use the WAVE test runner see the documentation.On Windows wpt commands must be prefixed with python or the path to the python binary (if python is not in your %PATH%).
python wpt [command]
Alternatively, you may also use Bash on Ubuntu on Windows in the Windows 10 Anniversary Update build, then access your windows partition from there to launch wpt commands.
Please make sure git and your text editor do not automatically convert line endings, as it will cause lint errors. For git, please set git config core.autocrlf false in your working tree.
The master branch is automatically synced to wpt.live and w3c-test.org.
Save the Web, Write Some Tests!
Absolutely everyone is welcome to contribute to test development. No test is too small or too simple, especially if it corresponds to something for which you've noted an interoperability bug in a browser.
The way to contribute is just as usual:
git checkout -b topic../wpt lint as described above.Use of LLMs to help author tests is generally acceptable, but every change must be attributable to a human who understands and can take responsibility for the proposed change.
Use of LLMs to participate in discussions is generally not acceptable; any LLM-generated content must either be from a bot account or contained inside a <blockquote> (for short contributions of at most one paragraph) or <details> element.
For full details see the Policy for LLM Use
If you spot an issue with a test and are not comfortable providing a pull request per above to fix it, please file a new issue. Thank you!