Skip to content

Use local path redirect for www-to-apex middleware#1143

Open
BenjaminMichaelis wants to merge 2 commits into
mainfrom
benjaminmichaelis/redirect-alert-check
Open

Use local path redirect for www-to-apex middleware#1143
BenjaminMichaelis wants to merge 2 commits into
mainfrom
benjaminmichaelis/redirect-alert-check

Conversation

@BenjaminMichaelis
Copy link
Copy Markdown
Member

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 PathString and QueryString:

  • redirectPath = context.Request.PathBase.Add(context.Request.Path)
  • redirectTarget = $"{redirectPath}{context.Request.QueryString}"
  • context.Response.Redirect(redirectTarget, permanent: true)

The existing wwwHost check and permanent redirect behavior are preserved, and the now-unused redirectAuthority variable 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.

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.
Copilot AI review requested due to automatic review settings May 20, 2026 04:32
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 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.

Comment thread EssentialCSharp.Web/Program.cs Outdated
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.
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