Skip to content

Conversation

nelsonjr
Copy link
Contributor

@nelsonjr nelsonjr commented Sep 9, 2025

No description provided.

{isLoggedIn ? (
<p>
Console:{' '}
<a href={consoleUrl} target="_blank">

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

DOM text
is reinterpreted as HTML without escaping meta-characters.

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 of consoleUrl, ensuring it starts with expected roots (e.g., /v2 or https:// or http://), 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.


Suggested changeset 1
flyte-sdk/typescript/react/src/projects.tsx

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/flyte-sdk/typescript/react/src/projects.tsx b/flyte-sdk/typescript/react/src/projects.tsx
--- a/flyte-sdk/typescript/react/src/projects.tsx
+++ b/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>
EOF
@@ -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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant