`_headers` drops the headers of earlier blocks when a path appears twice
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 80/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
Research direction
Start in packages/workers-shared/utils/configuration/constructConfiguration.ts: compare what parseHeaders returns for both blocks with what constructHeaders keeps once it assigns rules[rule.path], then make repeated paths accumulate their header entries instead of being overwritten. The existing configuration tests in the same package are the place to add the two-block repro, and the _redirects duplicate-rule warning shows the message style if you add one. Run the package's test suite, and check createMetadataObject and the Vite/Miniflare consumers still agree. Done means both blocks' headers appear on the response.
Written by the indexing model from the issue text.
Description
When the same path appears in more than one block of a _headers file, only the last block is applied. The headers from the earlier blocks are dropped with no warning.
Repro:
mkdir public && echo hi > public/index.html
printf '/*\n X-Frame-Options: DENY\n X-Content-Type-Options: nosniff\n\n/*\n Cache-Control: public, max-age=3600\n' > public/_headers
echo '{ "name": "t", "compatibility_date": "2025-01-01", "assets": { "directory": "./public" } }' > wrangler.jsonc
npx wrangler dev
curl -i http://localhost:8787/
Expected: the response has x-frame-options, x-content-type-options and cache-control. The docs say a request that matches multiple rules inherits the headers of all of them, and repeated header names inside a single block are already combined.
Actual: only cache-control is returned; the two security headers are gone. _redirects reports Ignoring duplicate rule for path ... for the same situation, _headers says nothing.
Cause: constructHeaders in packages/workers-shared/utils/configuration/constructConfiguration.ts stores rules in an object keyed by path (rules[rule.path] = configuredRule), so a second block for the same path replaces the first. parseHeaders returns both blocks. Pages (createMetadataObject), the Vite plugin and Miniflare all go through constructHeaders.
Reproducible on main at de6b171 and with wrangler 4.167.0.
- Dominant language
- TypeScript
- Stars
- 4.7k
- Forks
- 1.7k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 292
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/workers-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
cloudflare/workers-sdk#17112 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
cloudflare/workers-sdk#17110 ·
Maintainers usually reply within 1 day
-
D1 Time Travel restore help advertises 30 days without a plan qualifierPossibly taken @akhil9tiet claimed this 6 days ago. Openbug package:wrangler product:d1
Difficulty 1/5 1-3 hours Newbie friendliness 78/100
cloudflare/workers-sdk#17000 · 2 comments ·
Maintainers usually reply within 1 day
-
[workers-shared] `_redirects` targets like `https://host?query` and `https://host#hash` get a trailing slash appended after the query/fragmentMay be free again @Titan-M claimed this 10 days ago, and no pull request is open. Openbug package:workers-shared
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
cloudflare/workers-sdk#16924 · 2 comments ·
Maintainers usually reply within 1 day
-
D1 upload serialization emits deprecated id instead of required database_idPossibly taken @petebacondarwin claimed this 4 days ago. Openbug product:d1
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
cloudflare/workers-sdk#16958 · 1 comment ·
Maintainers usually reply within 1 day
All issues in cloudflare/workers-sdk
Similar issues
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
External sources always come back in English: `lc` isn't passed to `/api/v3/external_sources`Possibly taken @Anurag1428 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
openfoodfacts/openfoodfacts-explorer#2264 · 1 comment ·
Maintainers usually reply within 1 day
-
area: editor P3 type: feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
halisonworks/mod-codeling#290 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
colinhacks/zod#6776 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
aws/aws-sdk-js-v3#8441 ·
Maintainers usually reply within 1 day