codeant-ai-for-open-source[bot] commented on code in PR #43397:
URL: https://github.com/apache/superset/pull/43397#discussion_r3831878166


##########
superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx:
##########
@@ -33,6 +33,27 @@ import { WmsLayerConf, WfsLayerConf, LayerConf, XyzLayerConf 
} from '../types';
 import { isWfsLayerConf, isWmsLayerConf, isXyzLayerConf } from '../typeguards';
 import { isVersionBelow } from './serviceUtil';
 
+/**
+ * Escape HTML special characters in a layer attribution string.
+ *
+ * OpenLayers' Attribution control renders attribution strings via innerHTML,
+ * and the attribution here comes from creator-supplied chart form data, so it
+ * must be treated as untrusted text rather than markup to prevent stored XSS.
+ *
+ * @param attribution The attribution string from the layer configuration
+ *
+ * @returns The attribution with HTML special characters escaped
+ */
+export const escapeAttribution = (attribution?: string): string | undefined =>
+  attribution === undefined
+    ? undefined
+    : attribution
+        .replace(/&/g, '&')
+        .replace(/</g, '&lt;')
+        .replace(/>/g, '&gt;')
+        .replace(/"/g, '&quot;')
+        .replace(/'/g, '&#039;');

Review Comment:
   **Suggestion:** Escaping the entire attribution string converts 
intentionally supported HTML, such as the OpenStreetMap copyright link used by 
the chart's default layer, into literal text. OpenLayers renders attribution 
strings as HTML, so this removes clickable provider links and displays entities 
such as `&copy;` visibly. Sanitize attribution markup with an allowlist of safe 
elements and URL schemes instead of escaping all markup. [api mismatch]
   
   <details>
   <summary><b>Severity Level:</b> Major ⚠️</summary>
   
   ```mdx
   - ⚠️ Production Cartodiagram attributions lose clickable provider links.
   - ⚠️ OpenStreetMap copyright entities display as literal text.
   - ⚠️ Custom HTML attribution formatting is removed from map controls.
   ```
   </details>
   
   [![Use CodeAnt 
Skill](https://new-codeant-butcket.s3.us-west-1.amazonaws.com/badges/use-codeant-skill-flat-v2.svg)](https://docs.codeant.ai/cli/resolve-pr-comments-skill)
   <details>
   <summary><b>Prompt for AI Agent 🤖 </b></summary>
   
   ```mdx
   This is a comment left during a code review.
   
   **Path:** 
superset-frontend/plugins/plugin-chart-cartodiagram/src/util/layerUtil.tsx
   **Line:** 47:55
   **Comment:**
        *Api Mismatch: Escaping the entire attribution string converts 
intentionally supported HTML, such as the OpenStreetMap copyright link used by 
the chart's default layer, into literal text. OpenLayers renders attribution 
strings as HTML, so this removes clickable provider links and displays entities 
such as `&copy;` visibly. Sanitize attribution markup with an allowlist of safe 
elements and URL schemes instead of escaping all markup.
   
   Validate the correctness of the flagged issue. If correct, How can I resolve 
this? If you propose a fix, implement it and please make it concise.
   Once fix is implemented, also check other comments on the same PR, and ask 
user if the user wants to fix the rest of the comments as well. if said yes, 
then fetch all the comments validate the correctness and implement a minimal fix
   ```
   </details>
   <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43397&comment_hash=03fa02462c387248a0e5c576865c4cdae0d736563d3311ea3efc99819ad4c62c&reaction=like'>👍</a>
 | <a 
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F43397&comment_hash=03fa02462c387248a0e5c576865c4cdae0d736563d3311ea3efc99819ad4c62c&reaction=dislike'>👎</a>



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to