Skip to content

tanstack: DEFAULT_SECURITY_HEADERS ships HSTS with preload (irreversible) and only on text/html #649

Open

Description

@aline-pereira

What

DEFAULT_SECURITY_HEADERS in packages/tanstack/src/sdk/workerEntry.ts ships

Strict-Transport-Security: max-age=63072000; includeSubDomains; preload

and applySecurityHeaders only decorates responses whose content-type includes text/html.

Two concerns, raised as an issue rather than a PR because the default is a product/security decision for every site on the framework:

1. preload as a default is practically irreversible

preload is the opt-in token for the browsers' hardcoded HSTS preload list (hstspreload.org). Once a domain is submitted (and anyone can submit a domain that serves this header), removal takes months to propagate through browser releases, and includeSubDomains means every subdomain — including ones not served by this worker (legacy hosts, third-party CNAMEs, staging on a subdomain) — must be HTTPS or it breaks. A framework default should not make that choice for a site. Reference: Fresh/deco-runtime did not emit HSTS at all; sites set it themselves. The oficina site in production deliberately ships max-age=2592000 (30 days) while a domain migration settles (routes/_middleware.ts: "HSTS temporário (30 dias) até migração para oficina.com"), and on @decocms/tanstack has to override via securityHeaders: { "Strict-Transport-Security": ... } to avoid the preload default.

Proposal: default max-age=63072000; includeSubDomains (2 years, what the preload list requires anyway), without preload; document how a site adds preload once it has actually submitted the domain. Alternatively keep the value but document the irreversibility prominently on DEFAULT_SECURITY_HEADERS / securityHeaders.

2. HSTS only on text/html

HSTS is a host-level policy; browsers accept it on any response over TLS. Applying it only to HTML means a visitor whose first (or only) hit is a proxied VTEX JSON, an XML sitemap, a ?renderJson response or a 404 never gets the policy — and the max-age is only refreshed on HTML navigations. Production (Fresh middleware) applies it to every response except redirects and WebSocket upgrades; the site reproduces that on TanStack with a wrapper around the worker (withProdHsts).

Proposal: apply Strict-Transport-Security (and only it — CSP/COOP/etc. stay HTML-only) to every non-redirect, non-upgrade response, set-if-absent. Redirects are excluded because an http:// → https:// redirect must not carry HSTS (the header is ignored over plain HTTP anyway) and because proxied redirects may already carry the origin's own value.

Happy to open the PR for either part once the default is decided.

Found while validating deco-sites/oficina-tanstack#479.

🤖 Generated with Claude Code

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions