Skip to content

[Bug]: extraHTTPHeaders silently drops a valid proto header #44342

Not planned

Description

@himanshug189-sketch

Version

Playwright main (local source build)

Steps to reproduce

const headers = Object.fromEntries([
['proto', 'test-value'],
]);

const context = await browser.newContext({
extraHTTPHeaders: headers,
});

const page = await context.newPage();
await page.goto('http://localhost:3000');

Inspect the incoming request on the server using request.rawHeaders.
The request should contain the proto header with value "test-value",
but the header is missing.

Expected behavior

The proto header should be preserved and sent like other valid HTTP headers.

The issue occurs because headersArrayToObject() uses ordinary property assignment, which invokes the inherited proto setter instead of creating an own property.

Actual behavior

The proto header is silently dropped and does not appear in the incoming HTTP request's rawHeaders.

Additional context

No response

Environment

- OS: Ubuntu Linux
- Node.js: v22.23.5
- Browsers tested: Chromium, Firefox, WebKit
- Playwright: Local development build from main branch

Activity

  1. microsoft-playwright-automation commented on Nov 24, 2026

    @microsoft-playwright-automation
  2. microsoft-playwright-automation commented on Nov 24, 2026

    @microsoft-playwright-automation
    Contributor

    Hi, I'm the Playwright bot and I reproduced this.

    The header is dropped in Chromium and WebKit; Firefox sends it correctly. Tested on Linux at d70f422f491cfb875dd5dc05f01c61207e7382b4 (1.66.0-next). Assignment in headersArrayToObject() invokes the inherited __proto__ setter instead of creating a header property. The proposed fix uses Object.fromEntries() and extends the existing context-header test.

    Reproduction and checks

    The existing test now creates these context headers, overrides Foo on the page, and checks the incoming request:

    const context = await browser.newContext({
      extraHTTPHeaders: Object.fromEntries([
        ['fOo', 'bAr'],
        ['baR', 'foO'],
        ['__proto__', 'test-value'],
      ]),
    });
    const page = await context.newPage();
    await page.setExtraHTTPHeaders({ 'Foo': 'Bar' });
    const [request] = await Promise.all([
      server.waitForRequest('/empty.html'),
      page.goto(server.EMPTY_PAGE),
    ]);
    await context.close();
    expect(request.headers['foo']).toBe('Bar');
    expect(request.headers['bar']).toBe('foO');
    expect(request.rawHeaders).toEqual(expect.arrayContaining(['__proto__', 'test-value']));
    Browser, headless on Linux Without fix With fix
    Chromium Header missing Passed
    WebKit Header missing Passed
    Firefox Passed Passed

    Removing only the production fix reproduced the same failures again. With the fix restored, all 21 tests in browsercontext-set-extra-http-headers.spec.ts and page-set-extra-http-headers.spec.ts passed across the three browsers. npm run build and npm run flint passed.

    Draft PR: #44351

  3. himanshug189-sketch commented on Nov 24, 2026

    @himanshug189-sketch
    Author

    Hi Playwright Team,

    Thanks for investigating and reproducing this issue.

    I independently investigated this bug and implemented a fix in my local Playwright source.

    My Investigation

    The issue occurs in headersArrayToObject() in packages/isomorphic/headers.ts.

    When a header named __proto__ is assigned using ordinary property assignment (result[key] = value), JavaScript invokes the inherited __proto__ setter instead of creating an own property. As a result, the header is silently dropped.

    My Implementation

    I implemented a fix using Object.defineProperty() for the __proto__ key, ensuring that it is preserved as an enumerable own property without changing the object's prototype.

    I also added a regression test in:

    tests/library/browsercontext-set-extra-http-headers.spec.ts

    The test verifies that the __proto__ header reaches the server with the expected value by inspecting request.rawHeaders.

    Validation Performed

    I successfully completed the following checks:

    • npm run build
    • Targeted regression test in Chromium, Firefox, and WebKit.
    • Full browsercontext-set-extra-http-headers.spec.ts test file in Chromium, Firefox, and WebKit.
    • ESLint on both modified files.
    • git diff --check

    All the above checks passed.

    My Implementation

    I noticed that the Playwright automation bot has also created Draft PR #44351 with an alternative implementation using Object.fromEntries().

    I understand that both approaches aim to solve the same issue. I am sharing my implementation and validation results for the maintainers' reference.

    I would be happy to receive feedback on my implementation or make any additional changes if needed.

    Thanks!

  4. dgozman commented on Nov 24, 2026

    @dgozman
    Collaborator

    This seems like not a real scenario, because it's unlikely that anyone will send a __proto__ header. Closing as not worth fixing.

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    agent-triage-done

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions