Skip to content

Conversation

@amaannawab923
Copy link
Owner

SUMMARY

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

const paragraphConfig = { rows: 1, width: 150 };

const AnchorLink: FC<LinkProps> = ({ to, children }) => (
<a href={to}>{children}</a>

Check warning

Code scanning / CodeQL

DOM text reinterpreted as HTML Medium

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

Copilot Autofix

AI 5 months ago

To fix the issue, we need to ensure that the url value passed to the to prop of the AnchorLink component is properly sanitized or escaped to prevent XSS vulnerabilities. The best approach is to use a utility function to validate and sanitize the url before it is used. This function should ensure that the url is a valid and safe URL.

  1. Add a utility function, sanitizeUrl, to validate and sanitize the url value. This function can use the URL constructor to parse and validate the URL.
  2. Update the AnchorLink component to sanitize the to prop before using it in the href attribute.
  3. Ensure that all instances where url is passed to AnchorLink or similar components are sanitized.

Suggested changeset 2
superset-frontend/packages/superset-ui-core/src/components/ListViewCard/index.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/superset-frontend/packages/superset-ui-core/src/components/ListViewCard/index.tsx b/superset-frontend/packages/superset-ui-core/src/components/ListViewCard/index.tsx
--- a/superset-frontend/packages/superset-ui-core/src/components/ListViewCard/index.tsx
+++ b/superset-frontend/packages/superset-ui-core/src/components/ListViewCard/index.tsx
@@ -136,4 +136,14 @@
 
+const sanitizeUrl = (url: string): string => {
+  try {
+    const parsedUrl = new URL(url, window.location.origin);
+    return parsedUrl.href;
+  } catch (e) {
+    console.error('Invalid URL:', url);
+    return '#';
+  }
+};
+
 const AnchorLink: FC<LinkProps> = ({ to, children }) => (
-  <a href={to}>{children}</a>
+  <a href={sanitizeUrl(to)}>{children}</a>
 );
EOF
@@ -136,4 +136,14 @@

const sanitizeUrl = (url: string): string => {
try {
const parsedUrl = new URL(url, window.location.origin);
return parsedUrl.href;
} catch (e) {
console.error('Invalid URL:', url);
return '#';
}
};

const AnchorLink: FC<LinkProps> = ({ to, children }) => (
<a href={to}>{children}</a>
<a href={sanitizeUrl(to)}>{children}</a>
);
superset-frontend/src/utils/pathUtils.ts
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/superset-frontend/src/utils/pathUtils.ts b/superset-frontend/src/utils/pathUtils.ts
--- a/superset-frontend/src/utils/pathUtils.ts
+++ b/superset-frontend/src/utils/pathUtils.ts
@@ -19,2 +19,3 @@
 import { applicationRoot } from 'src/utils/getBootstrapData';
+import { sanitizeUrl } from 'src/utils/sanitizeUtils';
 
@@ -26,3 +27,4 @@
 export function ensureAppRoot(path: string): string {
-  return `${applicationRoot()}${path.startsWith('/') ? path : `/${path}`}`;
+  const sanitizedPath = path.startsWith('/') ? path : `/${path}`;
+  return sanitizeUrl(`${applicationRoot()}${sanitizedPath}`);
 }
EOF
@@ -19,2 +19,3 @@
import { applicationRoot } from 'src/utils/getBootstrapData';
import { sanitizeUrl } from 'src/utils/sanitizeUtils';

@@ -26,3 +27,4 @@
export function ensureAppRoot(path: string): string {
return `${applicationRoot()}${path.startsWith('/') ? path : `/${path}`}`;
const sanitizedPath = path.startsWith('/') ? path : `/${path}`;
return sanitizeUrl(`${applicationRoot()}${sanitizedPath}`);
}
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.