Skip to content

Fix open redirect (CWE-601) in www-to-apex redirect middleware - #1262

Merged
BenjaminMichaelis merged 2 commits into
mainfrom
copilot/fix-code-scanning-alerts
Aug 7, 2026
Merged

Fix open redirect (CWE-601) in www-to-apex redirect middleware#1262
BenjaminMichaelis merged 2 commits into
mainfrom
copilot/fix-code-scanning-alerts

Conversation

Copilot AI commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

CodeQL alert #16: the www-to-apex redirect middleware constructed the redirect URL via string interpolation, allowing a crafted Path value (e.g. //evil.com/...) to inject an unintended host into the redirect target.

Changes

  • Program.cs: Replace free-form string interpolation with UriHelper.BuildAbsolute, which takes scheme and host as discrete typed parameters sourced exclusively from server-side config (siteSettings.BaseUrl), and treats PathBase/Path/QueryString strictly as path/query components.
// Before — user-controlled Path flows into a raw string redirect URL
string redirectUrl = $"{redirectAuthority}{context.Request.PathBase}{context.Request.Path}{context.Request.QueryString}";

// After — scheme and host are config-derived; path components cannot inject a host
string redirectUrl = UriHelper.BuildAbsolute(redirectScheme, redirectHost,
    context.Request.PathBase, context.Request.Path, context.Request.QueryString);

Co-authored-by: BenjaminMichaelis <22186029+BenjaminMichaelis@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix code scanning alert #16 Fix open redirect (CWE-601) in www-to-apex redirect middleware Aug 7, 2026
Copilot AI requested a review from BenjaminMichaelis August 7, 2026 07:43
@BenjaminMichaelis
BenjaminMichaelis marked this pull request as ready for review August 7, 2026 08:14
@BenjaminMichaelis
BenjaminMichaelis merged commit a7886f5 into main Aug 7, 2026
7 checks passed
@BenjaminMichaelis
BenjaminMichaelis deleted the copilot/fix-code-scanning-alerts branch August 7, 2026 08:53
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