Skip to content

gateway: expose Content-Encoding to cross-origin readers on a public gateway #2817

Closed

Description

@thiras

Component

decdn gateway --public-url: the CORS headers on content responses (PUBLIC_EXPOSED in crates/cli/src/commands/gateway.rs).

Version

v0.3.0 and main (e7e67e6).

Steps to reproduce

  1. Run a public gateway behind its TLS-terminating proxy, with the proxy set to compress responses (gzip/br). The gateway itself never encodes, but any compressing proxy or CDN in front of it does.
  2. From a page on another origin, fetch an unverified or unsized body from the gateway, e.g. through @decdn/client with verify: false.
  3. Read response.headers.get("content-encoding").

Expected behavior

The page can tell that the body was decoded on the way. PUBLIC_EXPOSED lists Content-Encoding:

Content-Length, Content-Encoding, Content-Range, Accept-Ranges, Content-Type, Content-Disposition, ETag, Retry-After, Link

Actual behavior

Content-Encoding is not CORS-safelisted, and the gateway does not expose it, so a cross-origin page reads null. Content-Length is exposed, but it counts the encoded bytes. A reader can't tell those bytes apart from the decoded body's length.

@decdn/client uses Content-Length as a lower bound on a body it can't hash. It skips that bound when Content-Encoding is set (decdn/sdk-typescript#21). On a cross-origin page it can't see the header, so:

  • A small or incompressible body, whose encoded form is larger than the body, fails with a false TRUNCATED.
  • A range the gateway answers whole (200, e.g. a page a site rewrites) has its window and contentRange.size computed from the encoded length.
  • DecdnResponse.contentLength reports the encoded length.

Same-origin readers (a site page through /_decdn/) and Node aren't affected: they see every header.

Logs

n/a. The header list is at crates/cli/src/commands/gateway.rs (PUBLIC_EXPOSED), inserted in the public CORS headers (Access-Control-Expose-Headers).

Notes

  • This is an SDK-observable gateway change. The SDK's contract suite (test/contract/public.test.ts) can assert content-encoding is listed in access-control-expose-headers, and its fake gateway's EXPOSED mirrors the list. So the fix needs a matching sdk-typescript PR, and decdn.gatewayFloor stays below it until it ships.
  • appendix-gateway.md should list the header with the others, if it enumerates them.

Activity

  1. added
    kind:bug
    area:cli
    on Nov 1, 2026
  2. moved this from Backlog to In progress in deCDNon Nov 11, 2026
  3. moved this from In progress to Done in deCDNon Nov 11, 2026
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

    area:clikind:bug

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions