Use local path redirect for www-to-apex middleware#1143
Open
BenjaminMichaelis wants to merge 2 commits into
Open
Use local path redirect for www-to-apex middleware#1143BenjaminMichaelis wants to merge 2 commits into
BenjaminMichaelis wants to merge 2 commits into
Conversation
Build redirect target from PathString/QueryString instead of interpolating an absolute URL with request-derived segments. This preserves permanent redirect behavior while resolving the CodeQL unvalidated URL redirection finding.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR aims to resolve a CodeQL “unvalidated URL redirection” warning in the production-only www-to-apex redirect middleware by avoiding absolute redirect URL construction from request-derived segments.
Changes:
- Removes the previously computed
redirectAuthority(apex authority) value. - Switches the redirect to use a locally constructed target from
PathString+QueryString.
Use UriHelper.BuildAbsolute with configured canonical scheme and apex host while preserving request PathBase/Path/Query for the redirect target. This avoids relative redirect loops and keeps CodeQL-safe construction.
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.
Why
The www-to-apex redirect middleware built an absolute redirect URL by interpolating request-derived path/query segments. CodeQL flags this as unvalidated URL redirection, even though host selection is constrained.
What changed
The redirect now uses a local relative target constructed from
PathStringandQueryString:redirectPath = context.Request.PathBase.Add(context.Request.Path)redirectTarget = $"{redirectPath}{context.Request.QueryString}"context.Response.Redirect(redirectTarget, permanent: true)The existing
wwwHostcheck and permanent redirect behavior are preserved, and the now-unusedredirectAuthorityvariable was removed.Notes for reviewers
This is intentionally a narrow behavioral change: it keeps the same host-gated redirect flow while avoiding absolute URL construction from request-derived data.