Skip to content

Conversation

@devin-ai-integration
Copy link
Contributor

fix: Add XSS protection to flow visualization (issue #4326)

Summary

This PR addresses a potential XSS vulnerability in the flow visualization component (interactive.js) as reported in issue #4326. The visualization uses innerHTML to render drawer content including source code and metadata, which could originate from AI agent outputs.

Changes:

  • Added DOMPurify library (v3.0.6) via CDN for HTML sanitization
  • Created escapeHtml() helper function to escape user-controlled text values
  • Created sanitizeHtml() function using DOMPurify with an allowlist of safe tags/attributes
  • Applied sanitizeHtml() to drawer content before setting innerHTML
  • Applied escapeHtml() to user-controlled values in renderTriggerCondition, renderConditionTree, and renderMetadata methods
  • Added 4 tests to verify XSS protection is in place

Review & Testing Checklist for Human

  • Verify the DOMPurify allowlist is complete: Check that ALLOWED_TAGS and ALLOWED_ATTR in sanitizeHtml() include all legitimate tags/attributes needed for the drawer UI. Note: onmouseover and onmouseout are included - verify these are safe with DOMPurify's handling.
  • Test the fallback behavior: If DOMPurify fails to load, sanitizeHtml() returns unsanitized HTML. Consider whether this is acceptable or if it should throw/return empty string instead.
  • Manual XSS testing: Generate a flow visualization and attempt to inject XSS payloads (e.g., <script>alert(1)</script>, <img onerror=alert(1)>) through node names or metadata to verify they are properly sanitized.
  • Verify visualization still works: Open a flow visualization and confirm the drawer content renders correctly with syntax highlighting, trigger conditions, and router paths.

Notes

  • The Python tests verify code structure but cannot test actual browser runtime behavior
  • DOMPurify is loaded from cdnjs CDN - offline usage will not have XSS protection

Closes #4326

Link to Devin run: https://app.devin.ai/sessions/9a0daac8e60c4f76a0f0e4371ec78644
Requested by: João

- Add DOMPurify CDN to HTML template for sanitizing HTML content
- Add escapeHtml helper function to escape user-controlled text
- Add sanitizeHtml function using DOMPurify with allowed tags/attributes
- Apply sanitization to drawer content before setting innerHTML
- Escape user-controlled values in renderTriggerCondition, renderConditionTree, and renderMetadata methods
- Add tests to verify XSS protection is in place

Co-Authored-By: João <joao@crewai.com>
@devin-ai-integration
Copy link
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

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.

Potential XSS vulnerability in flow visualization (interactive.js)

0 participants