Potential fix for code scanning alert no. 316: URL redirection from remote source#640
Merged
KrzysztofPajak merged 1 commit intodevelopfrom Jan 9, 2026
Merged
Potential fix for code scanning alert no. 316: URL redirection from remote source#640KrzysztofPajak merged 1 commit intodevelopfrom
KrzysztofPajak merged 1 commit intodevelopfrom
Conversation
…emote source Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
|
There was a problem hiding this comment.
Pull request overview
This pull request addresses a security vulnerability (code scanning alert #316) related to URL redirection from a remote source in the SetStore method. The fix implements a safer pattern by introducing a separate variable for the redirect URL that is initialized with a safe default value and only assigned user input after validation.
Key Changes
- Introduces a dedicated
redirectUrlvariable initialized with a safe default route - Inverts the validation logic to assign the user-provided
returnUrlonly when it passes theIsLocalUrlcheck - Ensures untrusted user input is never passed directly to the
Redirectmethod
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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.



Potential fix for https://github.com/grandnode/grandnode2/security/code-scanning/316
In general, the safest fix is to never pass the raw user input directly to
Redirect. Instead, validate the input and construct a new, trusted redirect URL based on the result of that validation. A common pattern is to introduce a separate local variable (e.g.,redirectUrl) that is initialized with a safe default and only ever assigned validated values (such as a local URL or a known-good route), leaving the original user input unchanged.For this specific case in
SetStore(lines 248–273), the logic is already doing a local URL check, but it reuses thereturnUrlvariable for both the untrusted input and the trusted redirect target. To make the code clearer and more robust, we should:redirectUrl, set initially toUrl.RouteUrl("HomePage").Url.IsLocalUrl(returnUrl)is true, assignredirectUrl = returnUrl; otherwise leave it as the safe default.return Redirect(redirectUrl);instead ofRedirect(returnUrl).This change occurs only within
SetStoreinsrc/Web/Grand.Web/Controllers/CommonController.cs, around lines 268–272. No new imports or helpers are needed; we reuse the existingUrlhelper and routing.Suggested fixes powered by Copilot Autofix. Review carefully before merging.