Fix for value stripping during WSGI path lookup#319
Open
grindsa wants to merge 5 commits into
Open
Conversation
Co-authored-by: Copilot <copilot@github.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses incorrect path stripping in the WSGI app when Directory:url_prefix is configured (the str.lstrip() misuse described in #313), by introducing a version-agnostic prefix-removal helper and adding tests around WSGI path matching.
Changes:
- Add
get_path_with_prefix()helper to normalizePATH_INFOand safely remove a configuredurl_prefix. - Update
application()to useget_path_with_prefix()instead oflstrip(prefix). - Add new WSGI routing/path tests (and additionally add a large block of PKCS7-to-PEM related tests in
test_helper.py).
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 8 comments.
| File | Description |
|---|---|
examples/acme2certifier_wsgi.py |
Adds get_path_with_prefix() and uses it in application() to avoid over-stripping paths. |
test/test_wsgi_acme2certifier.py |
Adds coverage for path normalization/prefix stripping and some WSGI routing behaviors. |
test/test_helper.py |
Adds multiple PKCS7-to-PEM tests (not described in the PR) plus additional helper-related tests. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <copilot@github.com>
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.
as decribed in #313
When starting a WSGI Server with the Directory:url_prefix configured: If the url_prefix contains characters from the requested path, too much is stripped from the path and some URLs become unreachable.
https://docs.python.org/3/library/stdtypes.html#str.lstrip
"The chars argument is not a prefix; rather, all combinations of its values are stripped."
"/directory".lstrip("/devel-base")
The proposed
removeprefix()fix is safe but does not work in python versions earlier than 3.9 (which might be the case when using Redhat8). This PR introduces a version-agnostic fix addressing the issue