Skip to content

[BUG] Cache interceptor returns etag with incorrect syntax #1183

Description

@henry-wang-nzx

The response header for the etag in packages/open-next/src/core/routing/cacheInterceptor.ts returns an etag of an incorrect syntax.
cacheInterceptor.ts is used when the following config is enabled:

const config = {
  default: {},
  dangerous: {
    enableCacheInterception: true,
  },
} satisfies OpenNextConfig;

Currently it returns etag: <etag_value>, while the correct syntax requires <etag_value> to be surrounded by double quotes: i.e. etag: "<etag_value>".
See https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/ETag#syntax

This causes issues with Cloudfront CDN compression, as it will remove invalid etags after the compression.
See CloudFront Serve compressed files

Suggested fix
packages/open-next/src/core/routing/cacheInterceptor.ts#L61 creates the etag value as:

const etag = hash(body);

Instead it should be replaced with the correct etag syntax:

const etag = `"${hash(body)}"`

The suggested fix has been tested through patching locally and deployment.

Environment: sst@4.14.3, @opennextjs/aws@4.0.3, next@16.2.6

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