Fix: NotAllowedResponse accepts an arbitrary unvalidated status_code despite being the 405 response - #120
Open
pullapprove5[bot] wants to merge 1 commit into
Open
Fix: NotAllowedResponse accepts an arbitrary unvalidated status_code despite being the 405 response#120pullapprove5[bot] wants to merge 1 commit into
pullapprove5[bot] wants to merge 1 commit into
Conversation
…despite being the 405 response
Reproduced the finding: `NotAllowedResponse(["GET"], status_code=200)` succeeded and returned a response with `status_code == 200`, despite the class being documented as "HTTP 405 response" — the constructor's `status_code` parameter passed straight through to the base `Response.__init__` with only the generic 200–599 range check, no constraint to 405. Fixed by following the exact precedent the finding pointed at (`NotModifiedResponse`): removed the `status_code` parameter from `NotAllowedResponse.__init__` entirely, so the class always constructs with its `status_code = 405` class default. Confirmed the sole caller (`plain/views/base.py:130`) never passed `status_code`, so no call site needed updating. Added a docstring note mirroring `NotModifiedResponse`'s ("constructor is pinned") and a public test `test_not_allowed_response_signature_is_pinned` in `plain/tests/public/test_http_bodiless_responses.py`, asserting `NotAllowedResponse(["GET"], status_code=200)` now raises `TypeError` for the unexpected keyword argument. Ran `./scripts/fix plain` (clean, no changes) and the full `plain` package test suite directly via `uv run --isolated --package plain python -m pytest` (698 passed, including the new test and all existing view-dispatch/405 tests) — the sandbox has no Docker/Postgres available, so I could not run `./scripts/test` (it requires spinning up Postgres for the example project and other packages), but the change is confined to `plain/plain/http/response.py` and its own package's suite passed in full.
Author
PENDING: 1 review scope pending, 1 agent approved
✅ codex approved Next steps:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reproduced the finding:
NotAllowedResponse(["GET"], status_code=200)succeeded and returned a response withstatus_code == 200, despite the class being documented as "HTTP 405 response" — the constructor'sstatus_codeparameter passed straight through to the baseResponse.__init__with only the generic 200–599 range check, no constraint to 405. Fixed by following the exact precedent the finding pointed at (NotModifiedResponse): removed thestatus_codeparameter fromNotAllowedResponse.__init__entirely, so the class always constructs with itsstatus_code = 405class default. Confirmed the sole caller (plain/views/base.py:130) never passedstatus_code, so no call site needed updating. Added a docstring note mirroringNotModifiedResponse's ("constructor is pinned") and a public testtest_not_allowed_response_signature_is_pinnedinplain/tests/public/test_http_bodiless_responses.py, assertingNotAllowedResponse(["GET"], status_code=200)now raisesTypeErrorfor the unexpected keyword argument. Ran./scripts/fix plain(clean, no changes) and the fullplainpackage test suite directly viauv run --isolated --package plain python -m pytest(698 passed, including the new test and all existing view-dispatch/405 tests) — the sandbox has no Docker/Postgres available, so I could not run./scripts/test(it requires spinning up Postgres for the example project and other packages), but the change is confined toplain/plain/http/response.pyand its own package's suite passed in full.Opened by a PullApprove implementation run (implement-finding v4) for:
Merging this is what closes them as fixed.