Skip to content

Sec-Fetch-* headers use hardcoded values that don't match the spec #1152

Description

@duonglaiquang

Problem in brief

HtmlUnit sets the Fetch Metadata and Client Hint request headers as fixed defaults in WebClient.addDefaultHeaders(...) so requests end up with wrong header values, or with headers a real browser would never send.

1. Sec-Fetch-Site is always same-origin
Should be none for a user-initiated top-level navigation, and cross-site / same-site for cross-origin requests.

2. Sec-Fetch-Mode is always navigate
Should also reflect the request mode like cors and no-cors.

3. Sec-Fetch-User is sent on every request
The spec says to only send it on navigation requests that had user activation, and to omit it otherwise. HtmlUnit hardcodes ?1 on all requests, so images, CSS, XHR, etc. get a Sec-Fetch-User header that a real browser would never send.

4. Sec-Fetch-Dest is always document
Should match the request destination.

5. Headers are also sent over plain HTTP
Specs say these headers only go to potentially trustworthy origins. HtmlUnit adds them regardless of scheme.

Specs: https://www.w3.org/TR/fetch-metadata/

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions