Skip to content

fix(web): sanitize agent rerun modal HTML against stored XSS - #16516

Merged
wangq8 merged 2 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/agent-rerun-modal-xss
Jul 1, 2026
Merged

wangq8 merged 2 commits into
infiniflow:mainfrom
Harsh23Kashyap:Harsh23Kashyap/fix/agent-rerun-modal-xss

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown
Collaborator

Problem

Agent pipeline node names (data.name in the DSL graph) are stored as plain strings and rendered in the dataflow "Rerun from current step" confirmation modal. The modal uses dangerouslySetInnerHTML with an i18next template where escapeValue: false, so a malicious node name can execute script in another user's browser (stored XSS). Reported in #16507 / GHSA-9hj6-h23v-37hx.

Fix

Sanitize the interpolated modal HTML with DOMPurify before rendering, consistent with other dataflow UI components (chunk-card, category-panel, etc.).

Verification

cd web
npm ci
npm test -- --testPathPattern=rerun-button --no-coverage
npx eslint src/pages/dataflow-result/components/rerun-button/index.tsx

Fixes #16507

@dosubot dosubot Bot added size:S This PR changes 10-29 lines, ignoring generated files. 🐞 bug Something isn't working, pull request that fix bug. labels Jul 1, 2026
@coderabbitai

coderabbitai Bot commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds DOMPurify sanitization of translated HTML content before rendering it via dangerouslySetInnerHTML in the rerun confirmation modal, simplifies props destructuring in the RerunButton component, and adds a unit test verifying that unsafe attributes and script tags are stripped while benign markup is preserved.

Changes

XSS Sanitization Fix

Layer / File(s) Summary
Sanitize modal HTML and verify with test
web/src/pages/dataflow-result/components/rerun-button/index.tsx, web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx
Imports DOMPurify and wraps the translated modal content string with DOMPurify.sanitize(...) before assigning it to dangerouslySetInnerHTML.__html, simplifies props destructuring to step, onRerun, loading, and adds a test confirming unsafe handler attributes and <script> tags are removed while benign markup like img is retained.

Estimated code review effort: 1 (Trivial) | ~5 minutes

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant RerunButton
  participant i18n as "t()"
  participant DOMPurify

  User->>RerunButton: Click "Rerun from current step"
  RerunButton->>i18n: t('confirmRerunModalContent', { step: step.title })
  i18n-->>RerunButton: interpolated HTML string
  RerunButton->>DOMPurify: sanitize(interpolated string)
  DOMPurify-->>RerunButton: sanitized HTML
  RerunButton->>User: render sanitized HTML in modal
Loading

Poem

A step name once carried a sneaky bite,
<script> and onerror, hiding in plain sight.
Along hopped DOMPurify, whiskers held high,
Scrubbed every tag till the danger did die.
Now modals bloom clean under carrot-patch light! 🐰✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: sanitizing the rerun modal HTML to prevent stored XSS.
Description check ✅ Passed The PR description covers the problem, fix, and verification, which is enough for the repository's brief summary template.
Linked Issues check ✅ Passed The change sanitizes the vulnerable rerun modal content and adds coverage, matching the XSS remediation requested in #16507.
Out of Scope Changes check ✅ Passed The only extra change is a small prop destructuring cleanup, which is incidental and still within scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Harsh Kashyap added 2 commits July 1, 2026 08:45
Pipeline node names are interpolated into the rerun confirmation modal without escaping. Sanitize the rendered HTML before dangerouslySetInnerHTML, matching other dataflow UI components.

Fixes infiniflow#16507
@Harsh23Kashyap
Harsh23Kashyap force-pushed the Harsh23Kashyap/fix/agent-rerun-modal-xss branch from 0df298f to a1f9081 Compare July 1, 2026 03:15

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx (1)

1-13: 🎯 Functional Correctness | 🔵 Trivial | 🏗️ Heavy lift

Test doesn't exercise the actual fix.

This test only checks that DOMPurify.sanitize sanitizes a manually-built string — it never renders RerunButton or calls clickFunc/Modal.show. If the DOMPurify.sanitize(...) wrapper is later removed from index.tsx, this test would still pass, so it doesn't actually regression-guard the vulnerability it's meant to cover.

Consider rendering the component (mocking Modal.show to capture the dangerouslySetInnerHTML content) or extracting the modal HTML-building logic into a small testable function that the component calls, then asserting on that.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx`
around lines 1 - 13, The current test only sanitizes a hand-built string and
never exercises the real RerunButton flow, so it won’t fail if the
DOMPurify.sanitize call is removed from the component. Update the test to cover
the actual implementation by rendering RerunButton and mocking Modal.show (or by
extracting the modal HTML construction into a small helper used by clickFunc) so
you can assert on the HTML passed through the real code path. Use the existing
RerunButton, clickFunc, and Modal.show symbols to locate the fix and verify the
sanitized content comes from the component behavior, not a standalone DOMPurify
call.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx`:
- Around line 1-13: The current test only sanitizes a hand-built string and
never exercises the real RerunButton flow, so it won’t fail if the
DOMPurify.sanitize call is removed from the component. Update the test to cover
the actual implementation by rendering RerunButton and mocking Modal.show (or by
extracting the modal HTML construction into a small helper used by clickFunc) so
you can assert on the HTML passed through the real code path. Use the existing
RerunButton, clickFunc, and Modal.show symbols to locate the fix and verify the
sanitized content comes from the component behavior, not a standalone DOMPurify
call.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: df955b24-1cdf-46a7-b5b9-20366bfadd26

📥 Commits

Reviewing files that changed from the base of the PR and between 828c578 and a1f9081.

📒 Files selected for processing (2)
  • web/src/pages/dataflow-result/components/rerun-button/__tests__/index.test.tsx
  • web/src/pages/dataflow-result/components/rerun-button/index.tsx

@wangq8
wangq8 requested a review from cike8899 July 1, 2026 05:36
@wangq8
wangq8 merged commit 572f1ea into infiniflow:main Jul 1, 2026
3 checks passed
@Harsh23Kashyap
Harsh23Kashyap deleted the Harsh23Kashyap/fix/agent-rerun-modal-xss branch July 1, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🐞 bug Something isn't working, pull request that fix bug. size:S This PR changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stored XSS via Agent Pipeline Node Name

3 participants