-
Notifications
You must be signed in to change notification settings - Fork 3
Potential fix for code scanning alert no. 56: Client-side URL redirect #26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1 +1,12 @@ | ||
| function relativelnk(a){var b,c;b=location.href.search(/:/)==2?14:7;c=location.href.lastIndexOf("\\")+1;a="file:///"+location.href.substring(b,c)+a;location.href=a}; | ||
| function relativelnk(a){ | ||
| // Simple path validation: allow only relative filenames (no slashes, no colon, no protocol) | ||
| if (typeof a !== 'string' || a.match(/^[a-zA-Z0-9_.-]+$/) === null) { | ||
| console.error('Invalid path for redirect'); | ||
| return; | ||
| } | ||
| var b, c; | ||
| b = location.href.search(/:/)==2 ? 14 : 7; | ||
| c = location.href.lastIndexOf("\\")+1; | ||
| a = "file:///" + location.href.substring(b, c) + a; | ||
| location.href = a; | ||
| }; | ||
Oops, something went wrong.
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.
Check warning
Code scanning / CodeQL
Client-side URL redirect Medium documentation
Copilot Autofix
AI 5 months ago
To fix the client-side URL redirect issue, we should sanitize and strictly validate all parts that contribute to the redirect URL. In particular, we should avoid using unchecked data from
location.hrefto construct file paths, and instead use a safer mechanism. Since the function intends to redirect to a locally available help file referenced by a filename, it should select from a hardcoded list of allowed filenames or simply use the provided parameteraas a relative filename, not concatenated with user-controlled path data. If directory navigation is needed, define an allowed set of directories (preferably hardcoded), and ignore any values derived from the current location. This prevents attackers from manipulating the redirect path via location.Therefore, the best way to fix the problem is to keep the allowed filenames in a white-list array, verify
ais in that array, and construct the redirect path only from trusted base directory + safe filename, avoiding the use oflocation.hreffor redirect destination construction.Edits needed: In
src/doc/files/js/chmRelative.js, update the implementation ofrelativelnksuch that:file:///C:/Program Files/HelpFiles/).ais in a whitelist of allowed filenames.location.hreffor redirect destination.The whitelist should be declared in the same file.