nitrojs / nitrojs/nitro

Nitro Content Negotiation fails

Open
#3,077 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug v2
Dominant language
TypeScript
Stars
11.2k
Forks
899
Avg merge
2d 24m
Merged PRs (30d)
40

Description

Environment

nitro.config.js is

//https://nitro.unjs.io/config
export default defineNitroConfig({
  srcDir: "server",
  compressPublicAssets: true,
  compatibilityDate: "2025-02-07"
});

Nitropack is 2.10.4

node --version
v20.18.0

Reproduction

https://github.com/paulcrussell/minimal-nitro
To reproduce you will need to have a chrome extension which strips the Accept-Encoding header.
Or you could request one of the public assets with Postman and omit the Accept-Encoding header.

Describe the bug

Nitro performs content negotiation however if the Accept-Encoding request header is stripped then the server returns the plain text version yet sets no Vary header in the response
This makes it possible for a client to poison a shared cache for all other clients with the plain text version

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the minimal-nitro reproduction and the nitro.config.js configuration, then request a public asset without the Accept-Encoding header using Postman or the described Chrome extension. Inspect the content-negotiation response headers and verify that the plain-text response includes the appropriate Vary behavior so it cannot poison a shared cache.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, typescript
Domain
backend, security
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.