Fixed #36940 -- Improved ASGI script prefix path_info handling.#20749
Fixed #36940 -- Improved ASGI script prefix path_info handling.#20749jacobtylerwalls merged 1 commit intodjango:mainfrom
Conversation
77e6a42 to
8534ec7
Compare
There was a problem hiding this comment.
Hello! Thank you for your contribution 💪
As it's your first contribution be sure to check out the patch review checklist.
If you're fixing a ticket from Trac make sure to set the "Has patch" flag and include a link to this PR in the ticket!
If you have any design or process questions then you can ask in the Django forum.
Welcome aboard ⛵️!
|
Hi @KhadyotTakale , |
jacobtylerwalls
left a comment
There was a problem hiding this comment.
Thanks for the PR. A regression test is required. Please place it near the related tests in AsyncHandlerRequestTests.
8534ec7 to
b51ce2a
Compare
Paths that happened to begin with the script name were inappropriately stripped, instead of checking that script name preceded a slash.
b51ce2a to
d0245dd
Compare
jacobtylerwalls
left a comment
There was a problem hiding this comment.
Thanks for the updates. Welcome aboard! ⛵
I pushed teeny cosmetic updates to blend in with project style.
PR: django#20749 Issue: django#20749 Base commit: 864850b Changed lines: 29
Trac ticket number
ticket-36940
Branch description
The current
ASGIRequest.__init__usesstr.removeprefix()to strip the script name from the request path to computepath_info. This is fragile becauseremoveprefixis a pure string operation — it doesn't verify that the prefix is a proper path segment boundary.For example, if
script_nameis/myappand the path is/myapplication/page,removeprefixwould incorrectly producelication/page.This patch replaces
removeprefixwith a check that ensures the script name is followed by/or is the exact path, before stripping it. This addresses the inline TODO comment.AI Assistance Disclosure (REQUIRED)
AI tools (Claude) were used to understand the issue and guide the approach. The code was reviewed and verified manually.
Checklist
mainbranch.