-
Notifications
You must be signed in to change notification settings - Fork 7
Simple react app to see V2 runs #150
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
base: main
Are you sure you want to change the base?
Conversation
{isLoggedIn ? ( | ||
<p> | ||
Console:{' '} | ||
<a href={consoleUrl} target="_blank"> |
Check warning
Code scanning / CodeQL
DOM text reinterpreted as HTML Medium
DOM text
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI about 1 month 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.,/v2
orhttps://
orhttp://
), and defaults to a safe value if not. - In the code, wrap the calculated
consoleUrl
with 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.
-
Copy modified lines R8-R22 -
Copy modified line R73
@@ -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> |
No description provided.