Skip to content

fix: only use plain path segments as the section Surrogate-Key - #3214

Open
Alc-Alc wants to merge 2 commits into
python:mainfrom
Alc-Alc:surrogate-key-newline-500
Open

Alc-Alc wants to merge 2 commits into
python:mainfrom
Alc-Alc:surrogate-key-newline-500

Conversation

@Alc-Alc

@Alc-Alc Alc-Alc commented Nov 23, 2026

Copy link
Copy Markdown
Contributor
  • a path with an encoded CR or LF in its first segment was copied into the Surrogate-Key header, django raised BadHeaderError and the 404 became a 500.
  • Most probably regressed in feat: allow section-based Surrogate-Key to purge chunks #2851, the first event is around the time this was merged.
  • the first path segment is now only used as a section key when it is letters, digits, ., _ or -, anything else gets pydotorg-app only
    • real pages are not affected by this change

Some sample paths that triggered this

  • /downloads.%20%0D3
  • /%0AURL-%D0%B0%D0%B4%D1%80%D0%B5%D1%81
  • /%0ASet-Cookie:crlfinjection=crlfinjection
  • /downloads.%203, /URL-%D0%B0%D0%B4%D1%80%D0%B5%D1%81 (not original events, caught during local development)

Fixes PYDOTORG-PROD-1M5 (~62k events / ~25k in 90 days)
Fixes PYDOTORG-PROD-1M9 (~1.4k events / 205 in 90 days)

Before / after (status code, Surrogate-Key header)
path before after
/downloads.%203 404, pydotorg-app downloads. 3 404, pydotorg-app
/downloads.%20%0D3 500, no Surrogate-Key 404, pydotorg-app
/%0AURL-%D0%B0%D0%B4%D1%80%D0%B5%D1%81 500, no Surrogate-Key 404, pydotorg-app
/URL-%D0%B0%D0%B4%D1%80%D0%B5%D1%81 404, =?utf-8?b?cHlkb3RvcmctYXBwIFVSTC3QsNC00YDQtdGB?= 404, pydotorg-app

@Alc-Alc
Alc-Alc marked this pull request as ready for review November 24, 2026 03:54
@Alc-Alc
Alc-Alc requested a review from JacobCoffee as a code owner November 24, 2026 03:54

@Alc-Alc Alc-Alc left a comment •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To reviewers

  • does anyone purge by hand (fastly ui or api) using a key with any character other than letters, digits, ., _ or -?
  • does any script or job outside this repo do the same?

if the answer to all of the above is no, the PR can be merged as is. if not, i'll add those characters to the pattern

This branch has not been deployed

No deployments
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