Skip to content

Fix for value stripping during WSGI path lookup#319

Open
grindsa wants to merge 5 commits into
min-develfrom
min_fix_lstrip
Open

Fix for value stripping during WSGI path lookup#319
grindsa wants to merge 5 commits into
min-develfrom
min_fix_lstrip

Conversation

@grindsa
Copy link
Copy Markdown
Owner

@grindsa grindsa commented May 1, 2026

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

grindsa and others added 2 commits May 1, 2026 07:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 normalize PATH_INFO and safely remove a configured url_prefix.
  • Update application() to use get_path_with_prefix() instead of lstrip(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.

Comment thread examples/acme2certifier_wsgi.py Outdated
Comment thread test/test_wsgi_acme2certifier.py
Comment thread test/test_wsgi_acme2certifier.py
Comment thread test/test_helper.py
Comment thread test/test_helper.py
Comment thread examples/acme2certifier_wsgi.py Outdated
Comment thread test/test_wsgi_acme2certifier.py Outdated
Comment thread test/test_helper.py
grindsa and others added 3 commits May 1, 2026 07:49
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.

2 participants