refactor(nvd3): extract testable generateAnnotationTooltipContent helper#40620
Conversation
Code Review Agent Run #f953c7Actionable Suggestions - 0Additional Suggestions - 1
Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
✅ Deploy Preview for superset-docs-preview ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the legacy NVD3 annotation-layer tooltip rendering against XSS by sanitizing the HTML passed to d3-tip (which is inserted via innerHTML). It aligns the annotation tooltip path with other tooltip helpers in the same module that already use dompurify.
Changes:
- Added
generateAnnotationTooltipContent(layer, d)to build and sanitize annotation tooltip HTML. - Updated
tipFactory()to use the new helper (preserving the existing falsy-dguard behavior). - Added Jest coverage for normal rendering, title fallback, and common XSS payload stripping.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
superset-frontend/plugins/legacy-preset-chart-nvd3/src/utils.ts |
Extracts annotation tooltip HTML generation and sanitizes output via dompurify before d3-tip renders it. |
superset-frontend/plugins/legacy-preset-chart-nvd3/test/utils.test.ts |
Adds unit tests validating expected tooltip content and that sanitization removes unsafe markup/attributes. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #40620 +/- ##
=======================================
Coverage 63.40% 63.40%
=======================================
Files 2662 2662
Lines 143254 143253 -1
Branches 32941 32941
=======================================
+ Hits 90835 90836 +1
+ Misses 50816 50814 -2
Partials 1603 1603
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The annotation-tooltip sanitization landed in #40502 (inline in tipFactory). This extracts that logic into a pure, exported generateAnnotationTooltipContent helper — matching the file's existing standalone tooltip-content helpers and making the annotation path independently unit-testable without d3-tip — and adds coverage #40502 lacks: title/description rendering, fallback to the layer name when the title column is empty, and an explicit title-column XSS strip. No behavior change; output is still run through dompurify before reaching d3-tip. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
eb8f9f8 to
24c1f15
Compare
Code Review Agent Run #22ac10Actionable Suggestions - 0Review Details
Bito Usage GuideCommands Type the following command in the pull request comment and save the comment.
Refer to the documentation for additional commands. Configuration This repository uses Documentation & Help |
SUMMARY
The annotation-tooltip XSS fix this PR originally proposed already landed in #40502, which wrapped
tipFactory's annotation HTML (along with the other nvd3 tooltip sinks) indompurify.sanitize. Rather than close this as a duplicate, I've trimmed it to the part that adds value on top of #40502:tipFactory's inline.html()callback into a pure, exportedgenerateAnnotationTooltipContent(layer, d)helper. This matches the file's existing pattern of standalone tooltip-content helpers (generateCompareTooltipContent,generateMultiLineTooltipContent, etc.) and makes the annotation path independently unit-testable without standing up d3-tip.No behavior change — the output is still run through
dompurify.sanitizebefore d3-tip inserts it via.html().BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A — no visual change.
TESTING INSTRUCTIONS
17/17 pass (master's 13 + 4 net-new annotation-path tests).
ADDITIONAL INFORMATION
🤖 Generated with Claude Code