Skip to content

refactor(nvd3): extract testable generateAnnotationTooltipContent helper#40620

Merged
rusackas merged 1 commit into
masterfrom
fix/nvd3-annotation-tooltip-sanitize
Jun 3, 2026
Merged

refactor(nvd3): extract testable generateAnnotationTooltipContent helper#40620
rusackas merged 1 commit into
masterfrom
fix/nvd3-annotation-tooltip-sanitize

Conversation

@rusackas
Copy link
Copy Markdown
Member

@rusackas rusackas commented Jun 1, 2026

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) in dompurify.sanitize. Rather than close this as a duplicate, I've trimmed it to the part that adds value on top of #40502:

No behavior change — the output is still run through dompurify.sanitize before d3-tip inserts it via .html().

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

N/A — no visual change.

TESTING INSTRUCTIONS

cd superset-frontend && npx jest plugins/legacy-preset-chart-nvd3/test/utils.test.ts

17/17 pass (master's 13 + 4 net-new annotation-path tests).

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

🤖 Generated with Claude Code

@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Jun 1, 2026

Code Review Agent Run #f953c7

Actionable Suggestions - 0
Additional Suggestions - 1
  • superset-frontend/plugins/legacy-preset-chart-nvd3/test/utils.test.ts - 1
    • Missing test: Object.values fallback · Line 126-166
      The new test suite for `generateAnnotationTooltipContent()` covers the array path (line 281: `Array.isArray(layer.descriptionColumns)`) but the `Object.values(d)` fallback (line 283) is never exercised. Per rule [6262], tests should verify all logical paths. Add a test with `descriptionColumns` omitted or set to a non-array value to cover this branch.
      Code suggestion
       @@ -159,10 +159,23 @@
            test('strips a script payload from a description column', () => {
              const html = generateAnnotationTooltipContent(layer, {
                title: 'Release',
                description: '<script>alert(document.cookie)</script>',
              });
              expect(html).not.toContain('<script>');
            });
      +
      +    test('falls back to Object.values when descriptionColumns is not an array', () => {
      +      const layerWithoutDescriptionColumns = {
      +        name: 'My annotations',
      +        titleColumn: 'title',
      +      };
      +      const html = generateAnnotationTooltipContent(layerWithoutDescriptionColumns, {
      +        title: 'Release',
      +        description: 'Shipped v1',
      +      });
      +      expect(html).toContain('Release - My annotations');
      +      expect(html).toContain('Shipped v1');
      +    });
          });
Review Details
  • Files reviewed - 2 · Commit Range: eb8f9f8..eb8f9f8
    • superset-frontend/plugins/legacy-preset-chart-nvd3/src/utils.ts
    • superset-frontend/plugins/legacy-preset-chart-nvd3/test/utils.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@netlify
Copy link
Copy Markdown

netlify Bot commented Jun 1, 2026

Deploy Preview for superset-docs-preview ready!

Name Link
🔨 Latest commit 24c1f15
🔍 Latest deploy log https://app.netlify.com/projects/superset-docs-preview/deploys/6a1f73bc172ab70008e5c9d4
😎 Deploy Preview https://deploy-preview-40620--superset-docs-preview.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-d guard 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
Copy link
Copy Markdown

codecov Bot commented Jun 1, 2026

Codecov Report

❌ Patch coverage is 88.88889% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 63.40%. Comparing base (3bbb35e) to head (24c1f15).

Files with missing lines Patch % Lines
...tend/plugins/legacy-preset-chart-nvd3/src/utils.ts 88.88% 1 Missing ⚠️
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           
Flag Coverage Δ
javascript 67.51% <88.88%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@rusackas rusackas requested a review from dpgaspar June 1, 2026 23:35
@rusackas rusackas moved this from Needs Review to Needs Follow-Up Work in Superset Review Help Wanted Jun 2, 2026
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>
@rusackas rusackas force-pushed the fix/nvd3-annotation-tooltip-sanitize branch from eb8f9f8 to 24c1f15 Compare June 3, 2026 00:22
@rusackas rusackas changed the title fix(nvd3): sanitize annotation tooltip HTML in tipFactory refactor(nvd3): extract testable generateAnnotationTooltipContent helper Jun 3, 2026
@bito-code-review
Copy link
Copy Markdown
Contributor

bito-code-review Bot commented Jun 3, 2026

Code Review Agent Run #22ac10

Actionable Suggestions - 0
Review Details
  • Files reviewed - 2 · Commit Range: 24c1f15..24c1f15
    • superset-frontend/plugins/legacy-preset-chart-nvd3/src/utils.ts
    • superset-frontend/plugins/legacy-preset-chart-nvd3/test/utils.test.ts
  • Files skipped - 0
  • Tools
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful
    • Eslint (Linter) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at evan@preset.io.

Documentation & Help

AI Code Review powered by Bito Logo

@rusackas rusackas merged commit 6ea4e22 into master Jun 3, 2026
73 of 74 checks passed
@rusackas rusackas deleted the fix/nvd3-annotation-tooltip-sanitize branch June 3, 2026 18:56
@github-project-automation github-project-automation Bot moved this from Needs Follow-Up Work to Approved and/or Merged in Superset Review Help Wanted Jun 3, 2026
@sha174n sha174n added the merge-if-green If approved and tests are green, please go ahead and merge it for me label Jun 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-if-green If approved and tests are green, please go ahead and merge it for me plugins preset-io size/M

Projects

Status: Approved and/or Merged

Development

Successfully merging this pull request may close these issues.

3 participants