Skip to content

fix(gin): root the trailing-slash redirect after X-Forwarded-Prefix is sanitized - #4923

Open
arpitjain099 wants to merge 1 commit into
gin-gonic:masterfrom
arpitjain099:fix/forwarded-prefix-redirect-root
Open

arpitjain099 wants to merge 1 commit into
gin-gonic:masterfrom
arpitjain099:fix/forwarded-prefix-redirect-root

Conversation

@arpitjain099

Copy link
Copy Markdown

redirectTrailingSlash prepends the sanitized X-Forwarded-Prefix to the path and never re-roots the result. sanitizePathChars keeps only [A-Za-z0-9/-], so the prefix can come back empty or without its leading slash. Empty leaves Location: //path, which a client reads as a host. #api leaves a relative api/api/path, because the client resolves it against the request path that was just rewritten. Anchoring at one leading slash fixes both, and rooted prefixes such as /api are unaffected. Three assertions in TestRouteRedirectTrailingSlash held the old values, so I updated them and added the empty-prefix case.

…s sanitized

Co-Authored-By: Claude <noreply@anthropic.com>
Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
@codecov

codecov Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.65%. Comparing base (0f09c3a) to head (814d053).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #4923   +/-   ##
=======================================
  Coverage   98.65%   98.65%           
=======================================
  Files          48       48           
  Lines        3188     3189    +1     
=======================================
+ Hits         3145     3146    +1     
  Misses         43       43           
Flag Coverage Δ
--ldflags="-checklinkname=0" -tags sonic 98.64% <100.00%> (+<0.01%) ⬆️
-tags go_json 98.57% <100.00%> (+<0.01%) ⬆️
-tags nomsgpack 98.63% <100.00%> (+<0.01%) ⬆️
go-1.26 98.33% <100.00%> (+<0.01%) ⬆️
go-1.27 98.67% <100.00%> (+<0.01%) ⬆️
macos-latest 98.65% <100.00%> (+<0.01%) ⬆️
ubuntu-latest 98.65% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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.

1 participant