Skip to content

Conversation

hbenl
Copy link
Contributor

@hbenl hbenl commented Oct 7, 2025

#36932 filters the host header from overrides to fix intercepted redirects in Firefox/Juggler (#36719).
This broke network intercepts in Firefox/BiDi because Firefox expects the host header to be present in overrides.
With this PR:

  • the host header is only filtered for Firefox/Juggler and Safari (the latter only to maintain the behavior documented here - we could also update the test expectation instead)
  • for BiDi, the host header override is updated with the value from the redirected request so that Firefox/BiDi doesn't run into the same issue that Firefox/Juggler had

Fixes the following tests in Firefox:

  • tests/page/page-network-request.spec.ts:
    • "should override post data content type"
  • tests/page/page-request-continue.spec.ts:
    • "should amend HTTP headers"
    • "should delete header with undefined value"
    • "post data > should compute content-length from post data"
    • "should delete the origin header"
    • "should continue preload link requests"
    • "redirect after continue should be able to delete cookie"
    • "continue should propagate headers to redirects"
    • "continue should delete headers on redirects"
    • "propagate headers cross origin redirect after interception"
    • "should not forward Host header on cross-origin redirect"
  • tests/page/page-request-fallback.spec.ts:
    • "should amend HTTP headers"
    • "should delete header with undefined value"
  • tests/page/page-request-fulfill.spec.ts:
    • "should not modify the headers sent to the server"
  • tests/page/page-route.spec.ts:
    • "should be able to remove headers"

Copy link
Contributor

github-actions bot commented Oct 7, 2025

Test results for "tests 1"

5 flaky ⚠️ [firefox-library] › library/inspector/cli-codegen-1.spec.ts:1079 › cli codegen › should not throw csp directive violation errors `@firefox-ubuntu-22.04-node18`
⚠️ [firefox-library] › library/inspector/cli-codegen-pick-locator.spec.ts:35 › should update locator highlight `@firefox-ubuntu-22.04-node18`
⚠️ [firefox-page] › page/page-event-request.spec.ts:182 › should return response body when Cross-Origin-Opener-Policy is set `@firefox-ubuntu-22.04-node18`
⚠️ [playwright-test] › ui-mode-test-progress.spec.ts:22 › should update trace live `@macos-latest-node18-1`
⚠️ [playwright-test] › ui-mode-test-output.spec.ts:80 › should show console messages for test `@ubuntu-latest-node24-1`

46926 passed, 816 skipped


Merge workflow run.

if (redirectedFrom._originalRequestRoute?._alreadyContinuedHeaders) {
const { headers } = toBidiRequestHeaders(redirectedFrom._originalRequestRoute._alreadyContinuedHeaders ?? []);
const hostHeader = headers.find(header => header.name.toLowerCase() === 'host');
if (hostHeader) {
Copy link
Member

Choose a reason for hiding this comment

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

Why is this different from juggler and simply not providing an override is not sufficient? Is it because we always preserve the original in this code ?

What is the semantics of overridden headers passed to network.continueRequest in Firefox - will overrides always replace all original headers or they are merged and if a header is present on the original request but not in the overrides, it will be preserved on the request? I believe for most of the network service headers if there is no explicit override, the default value will be sent (at least in Chromium and WebKit). If in Firefox Bidi the headers must contain all final headers then I believe we should change the logic and merge original headers with the overrides. In this particular case it would mean that we always add the host header regardless of wether it is in _alreadyContinuedHeaders or not (it should probably not be there as we don't allow to override it).

Copy link
Member

Choose a reason for hiding this comment

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

To provide a bit more context, the header overrides is a mess for the headers that are added by the network service. I believe what we settled on is that we don't want to support overrides of any of the forbidden headers and want them to be propagated as is. I don't think we currently enforce that in all browsers though, so the behavior may vary. For the host and cookie headers there were explicit reports, so we have special handling of those.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In Firefox BiDi the overrides always replace all original headers (and network requests stall if the overrides don't contain a Host header) whereas Chrome BiDi currently doesn't expect the overrides to contain a Host header (the network request stalls if they do). But the consensus on the BiDi spec seems to be that Firefox' behavior is the correct one ("We should consider data from the BiDi client safe, and provide whatever they want to.").
To get the desired Playwright behavior that you described with BiDi, I think we should

  • use the original request values for the forbidden headers and ignore overrides for those
  • use the override values for all other headers and ignore the original request values for those

Do you agree?

Copy link
Member

Choose a reason for hiding this comment

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

I mostly agree with the exception that I don't think anyone would appreciate stalling when an unexpected override is passed or expected header is not passed, immediately throwing a validation error in that case sounds more user friendly.

use the original request values for the forbidden headers and ignore overrides for those

I would throw in this case. There is also an option of not throwing an applying overrides in best effort manner, basically not reporting an error when the override is lost.

use the override values for all other headers and ignore the original request values for those

Yes, agree with this.

But the consensus on the BiDi spec seems to be that Firefox' behavior is the correct one (w3c/webdriver-bidi#983 (comment)).

As far as I know in Chromium at the interception time we don't have headers added by the network stack. There is a special dance for fetching "would be sent" cookies, but there are other headers too added by the network service. Due to this limitation the user cannot easily pass complete set of the headers where they override say just one.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants