Open
Conversation
| {isLoggedIn ? ( | ||
| <p> | ||
| Console:{' '} | ||
| <a href={consoleUrl} target="_blank"> |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 7 months ago
The best way to fix the problem is to ensure that the constructed consoleUrl is always a safe URL—specifically, that it uses the desired protocol and does not allow for injection of dangerous values (such as javascript: or data:). This is usually achieved by performing output encoding or protocol checking before using a value as an anchor href. In this particular case:
- We can implement a helper function, e.g.,
sanitizeUrl, that checks the format/protocol ofconsoleUrl, ensuring it starts with expected roots (e.g.,/v2orhttps://orhttp://), and defaults to a safe value if not. - In the code, wrap the calculated
consoleUrlwith this sanitization function to guarantee that even if user-controlled data is used in the URL, it cannot result in an unsafe link. - The fix only affects the construction and use of
consoleUrl, requiring at most a helper function and minor changes to the returned anchor tag in JSX. - No change in visible behavior for valid URLs; only malicious (or invalid) URLs will be neutralized.
For best security and clarity, place the sanitizeUrl function in this file above the component definition, with clear documentation.
Suggested changeset
1
flyte-sdk/typescript/react/src/projects.tsx
| @@ -5,6 +5,21 @@ | ||
| import { Context } from './auth' | ||
| import { Runs } from './runs' | ||
|
|
||
|
|
||
| // Returns a safe URL for use in href attributes, guarding against javascript: or data: protocols. | ||
| function sanitizeUrl(url: string): string { | ||
| // Only allow http(s) and relative URLs | ||
| if ( | ||
| url.startsWith('http://') || | ||
| url.startsWith('https://') || | ||
| url.startsWith('/') | ||
| ) { | ||
| return url | ||
| } | ||
| // Otherwise, return root or a placeholder | ||
| return '/' | ||
| } | ||
|
|
||
| export const Projects = () => { | ||
| const { isLoggedIn } = useContext(Context) | ||
| const [projects, setProjects] = useState<Project[]>() | ||
| @@ -55,7 +70,7 @@ | ||
| {isLoggedIn ? ( | ||
| <p> | ||
| Console:{' '} | ||
| <a href={consoleUrl} target="_blank"> | ||
| <a href={sanitizeUrl(consoleUrl)} target="_blank" rel="noopener noreferrer"> | ||
| {consoleUrl} | ||
| </a> | ||
| </p> |
Copilot is powered by AI and may make mistakes. Always verify output.
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.
No description provided.