starlette icon indicating copy to clipboard operation
starlette copied to clipboard

405 Allow header ordering is nondeterministic (varies with PYTHONHASHSEED)

Open Lushiyao5 opened this issue 2 weeks ago • 0 comments

Route.handle builds the 405 Allow header with ", ".join(self.methods), but Route.methods is a set. The join order varies with the process hash seed: the same route returns GET, POST in one server process and POST, GET in another (reproduced across 4 worker processes with different PYTHONHASHSEED values on current main).

HTTP caches, clients and tests that compare header values see inconsistent 405 responses for identical conditions.

Fix: one line - ", ".join(sorted(self.methods)) (content unchanged, ordering becomes deterministic).

A ready branch with the fix plus a regression test that asserts the exact header value (the existing tests compared against a set, which tolerated the nondeterminism):

https://github.com/Lushiyao5/starlette/tree/fix/allow-header-order-20261115

Full suite on the branch: 1409 passed (the 14 pre-existing Windows environment failures match baseline). Happy to open a PR if maintainers prefer - noting that PR creation appears limited to collaborators for this repository (the API returns 404/FORBIDDEN for create_pull_request).

Lushiyao5 avatar Nov 15 '26 11:11 Lushiyao5