Skip to content

Set creation URL of worker settings to final URL after redirect #12038

Merged
domfarolino merged 1 commit intowhatwg:mainfrom
TimvdLippe:update-creation-url-for-workers
Jan 20, 2026
Merged

Set creation URL of worker settings to final URL after redirect #12038
domfarolino merged 1 commit intowhatwg:mainfrom
TimvdLippe:update-creation-url-for-workers

Conversation

@TimvdLippe
Copy link
Copy Markdown
Contributor

@TimvdLippe TimvdLippe commented Dec 22, 2025

To determine the request referrer for a worker global scope 1
it uses the creation URL. This URL is initialized for workers in
"set up a worker environment settings object" 2 which is
called at the start of "run a worker" 3.

However, per the WPT tests 4 the referrer should use the
final URL after redirection. This is available in
"processResponseConsumeBody" 5 where we already
update the URL for the worker.

To match browser behavior, we should also update the
creation URL here.

(See WHATWG Working Mode: Changes for more details.)


/workers.html ( diff )

@TimvdLippe
Copy link
Copy Markdown
Contributor Author

Discovered this while correcting the determining of the referrer value in Servo for workers: servo/servo#41458

@TimvdLippe
Copy link
Copy Markdown
Contributor Author

Turns out that this patch is wrong, see tests in web-platform-tests/wpt#56921

Instead, the request referrer should use https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url instead of creation URL, as that's what browsers actually do. That also makes a lot more sense to me.

TimvdLippe added a commit to TimvdLippe/webappsec-referrer-policy that referenced this pull request Dec 25, 2025
Based on an investigation as to why Servo
doesn't use the correct URL per the spec [1]
I thought that HTML was incorrectly setting
the creation URL [2].

However, after writing a WPT test [3] it turns
out that the creation URL is correctly set in
HTML, but incorrectly used in Referrer Policy.
Browsers don't use the creation URL to
determine the referrer policy, per another
WPT test [4].

Instead of the creation URL, browsers use the
url of the worker, which is the same as the
API base URL [5].

[1]: servo/servo#41458
[2]: whatwg/html#12038
[3]: web-platform-tests/wpt#56921
[4]: https://wpt.fyi/results/fetch/api/basic/request-referrer-redirected-worker.html?label=master&label=experimental&aligned
[5]: https://html.spec.whatwg.org/multipage/workers.html#script-settings-for-workers:api-base-url
@TimvdLippe
Copy link
Copy Markdown
Contributor Author

Opened a PR for that spec: w3c/webappsec-referrer-policy#177

@domfarolino
Copy link
Copy Markdown
Member

Instead, the request referrer should use https://html.spec.whatwg.org/multipage/webappapis.html#api-base-url instead of creation URL, as that's what browsers actually do. That also makes a lot more sense to me.

See w3c/webappsec-referrer-policy#177 (comment) for why I don't think we can do that. I think the direction of this PR might be right after all.

@TimvdLippe
Copy link
Copy Markdown
Contributor Author

Other specifications such as the reporting API rely on the creation URL being the URL prior to redirects. See step 2 of https://w3c.github.io/reporting/#generate-a-report That's what web-platform-tests/wpt#56921 confirms is the existing behavior in browsers.

@TimvdLippe
Copy link
Copy Markdown
Contributor Author

Per our investigation in w3c/webappsec-referrer-policy#177 it turns out that this PR is valid after all. Servo passes all existing WPT tests including the new one with this change.

@domfarolino
Copy link
Copy Markdown
Member

I think this PR is in the right direction. But please restore the PR template and fill everything necessary out, including a link to any tests that you write, and ideally even those whose expectations might change due to this PR.

It would be great to know if any engines currently rely on the state of things before this PR, or if this PR is simply fixing a spec bug that engines don't have. I assume the latter.

@TimvdLippe
Copy link
Copy Markdown
Contributor Author

@domfarolino Do you know anybody from Webkit/Gecko who can review this change?

@wanderview
Copy link
Copy Markdown
Member

@asutherland or @bakulf Can you review from gecko side?

@asutherland
Copy link
Copy Markdown

asutherland commented Jan 12, 2026

The spec change makes sense. Our reporting API situation is not great for the test case in the sense that it doesn't work[1], but I manually ran the test under rr (mozilla pernosco trace) to understand the situation better and that did allow me to validate that I believe we would pass the test if our reporting API glue was working. Specifically, for the 2 worker spawns we see an aViolationEventInit.mDocumentURI of:

  1. http://web-platform.test:8000/content-security-policy/reporting-api/support/dedicatedworker-report-url.sub.js
  2. http://web-platform.test:8000/content-security-policy/reporting-api/support/dedicatedworker-report-url.sub.js?location=%2Fcontent-security-policy%2Freporting-api%2Fsupport%2Fdedicatedworker-report-url.sub.js&test-name=%27+%28with+redirect%29%27&count=1

In that second case if we weren't updating after the redirect, we would be seeing http://web-platform.test:8000/fetch/api/resources/redirect.py?location=%2Fcontent-security-policy%2Freporting-api%2Fsupport%2Fdedicatedworker-report-url.sub.js&test-name=%27%20(with%20redirect)%27 instead (which is what the principal is for the worker prior to WorkerLoadInfo::SetPrincipalsAndCSPOnMainThread clobbering the updated principal into place after verifying they're same-origin (AKA equivalent principals).

1: We do enable our reporting API impl in-tree for WPTs and we do try and report the error, but in our workers impl the fetch() call is remoted from the content process to the parent process and gets reported in the parent process but nothing propagates it back down to the content process AFAICT.

@annevk
Copy link
Copy Markdown
Member

annevk commented Jan 14, 2026

I suppose this solution is okay, but this is really a bandaid solution. The real problem is that we are creating the environment before we have a response. We should really wait for the response and only then create an environment. (There's some older issues explaining that.)

@TimvdLippe
Copy link
Copy Markdown
Contributor Author

@annevk ack, do you consider that blocking here? Unfortunately I don't know what the implications are for such an overhaul and Servo is currently not in a position to prototype with that. We have other fundamental projects going on before we can make that happen.

CountBleck added a commit to CountBleck/ladybird that referenced this pull request Jan 18, 2026
This originally was part of a FIXME in step 5 of "setup a worker
environment settings object". Since the worker global scope's url isn't
populated at this point, we set the creation_url as soon as it is. This
step will be added to the spec in whatwg/html#12038. After this change,
all the WPT subtests in...
https://wpt.live/referrer-policy/gen/worker-classic.http-rp/no-referrer-when-downgrade/fetch.http.html
...will pass!
CountBleck added a commit to CountBleck/ladybird that referenced this pull request Jan 19, 2026
This originally was part of a FIXME in step 5 of "setup a worker
environment settings object". Since the worker global scope's url isn't
populated at this point, we set the creation_url as soon as it is. This
step will be added to the spec in whatwg/html#12038. After this change,
all the WPT subtests in...
https://wpt.live/referrer-policy/gen/worker-classic.http-rp/no-referrer-when-downgrade/fetch.http.html
...will pass!
Copy link
Copy Markdown
Member

@domfarolino domfarolino left a comment

Choose a reason for hiding this comment

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

I also think this is a bandaid, but I think this is better than nothing, so I'm OK with landing it. I'll give @annevk a day to object, but otherwise I think we're alright to land this.

@annevk
Copy link
Copy Markdown
Member

annevk commented Jan 20, 2026

It's fine. We're tracking the root cause through #5362 and I suspect some other related issues.

@domfarolino domfarolino merged commit adc0ede into whatwg:main Jan 20, 2026
2 checks passed
@TimvdLippe
Copy link
Copy Markdown
Contributor Author

@theIDinside the test uses ReportingObserver to obtain the report, not an endpoint. As far as I understand the spec, ReportingObservers are available in HTTP context. The test passes in both Chromium and Servo.

@theIDinside
Copy link
Copy Markdown

@theIDinside the test uses ReportingObserver to obtain the report, not an endpoint. As far as I understand the spec, ReportingObservers are available in HTTP context. The test passes in both Chromium and Servo.

Deleted the comments, as they were just red herrings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

6 participants