Potential fix for code scanning alert no. 24: Server-side URL redirect - #82
Merged
Merged
Conversation
Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
MarkProminic
marked this pull request as ready for review
October 1, 2025 02:17
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/STARTcloud/armor/security/code-scanning/24
To reliably fix this issue, we must ensure that redirects based on user-provided values (such as
req.path) do not allow untrusted or unsafe paths. The best practice is to use a dedicated whitelist of allowed redirect paths or—given the usage context—validate that the destination is both relative and remains within the application, disallowing redirects to external hosts, protocol-relative URLs, or other attacker-controlled URLs.You should:
isLocalUrlonly passes "safe" paths (relative paths, not containing things like.., not starting with//or including external hosts)./, not containing any path traversal)./).You only need to change the region in
routes/fileServer.jsstarting at line 1094 wherenewPathis created from user input and validated. Specifically, improve the validation ofnewPathto ensure it cannot be abused for open redirects by validating against stricter rules. You may also need to implement or update theisLocalUrlhelper for this purpose, but you can only work with code shown directly in the file.Required changes:
newPath(possibly with a stronger local URL check).isLocalUrlto strictly check for only relative, non-traversal paths.Suggested fixes powered by Copilot Autofix. Review carefully before merging.