Skip to content

web: set the configured headers on rate limited responses - #440

Open
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/security-headers-on-rate-limited-responses
Open

web: set the configured headers on rate limited responses#440
mrueg wants to merge 1 commit into
prometheus:masterfrom
mrueg:fix/security-headers-on-rate-limited-responses

Conversation

@mrueg

@mrueg mrueg commented Sep 2, 2026

Copy link
Copy Markdown
Contributor

The rate limiter is checked before the loop that applies http_server_config.headers, so a 429 is written without them. A request that is served carries the operator's Strict-Transport-Security, Content-Security-Policy and X-Frame-Options; a request from the same client a moment later does not.

A header policy is meant to hold for every response from the endpoint, so apply the headers first and turn the request away afterwards.

One note for anyone checking this by hand: X-Content-Type-Options hides the difference, because http.Error sets nosniff itself, so it was present on the 429 either way. The test uses X-Frame-Options and Strict-Transport-Security.

Tests

Added a test that spends a burst of 1, then compares the headers on the served response with those on the rate-limited one. It fails against master with both headers empty.

🤖 Generated with Claude Code

The rate limiter was checked before the loop that applies
http_server_config.headers, so a 429 was written without them. A request
that was served carried the operator's Strict-Transport-Security,
Content-Security-Policy and X-Frame-Options, and a request from the same
client a moment later did not.

A header policy is meant to hold for every response from the endpoint, so
apply the headers first and turn the request away afterwards.

Note when testing this by hand that X-Content-Type-Options hides the
difference: http.Error sets nosniff itself, so it was present on the 429
either way.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Signed-off-by: Manuel Rüger <manuel@rueg.eu>
@mrueg
mrueg force-pushed the fix/security-headers-on-rate-limited-responses branch from 4be8058 to 12cc1db Compare September 2, 2026 13:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant