Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion app/main.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# SPDX-License-Identifier: FSL-1.1-MIT
import asyncio
import datetime
import logging
Expand Down Expand Up @@ -140,12 +141,17 @@ async def http_redirect_middleware(request: Request, call_next):
host = request.headers.get("x-forwarded-host")
protocol = request.headers.get("x-forwarded-proto")
port = request.headers.get("x-forwarded-port")
new_path = (
prefix + original_url.path
if not original_url.path.startswith(prefix)
else original_url.path
Comment on lines +145 to +147

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Check prefix match on segment boundary

The new startswith(prefix) guard can suppress required prefixing when the redirect path merely shares a textual prefix. For example, with x-forwarded-prefix=/safe and Location path /safe-decoder/api, this condition evaluates true and skips rewriting, so clients receive /safe-decoder/api instead of /safe/safe-decoder/api. This regression is introduced by the new guard; it should only treat the path as already prefixed when path == prefix or path.startswith(prefix + "/").

Useful? React with 👍 / 👎.

)
response.headers["location"] = str(
original_url.replace(
scheme=protocol,
hostname=host,
port=port,
path=prefix + original_url.path,
path=new_path,
)
)
return response
Expand Down
Loading