Back to all reviewers

Sanitize untrusted content

RooCodeInc/Roo-Code
Based on 3 comments
TSX

Always sanitize user-generated or externally sourced content before rendering it to prevent Cross-Site Scripting (XSS) vulnerabilities. Never use `dangerouslySetInnerHTML` with unsanitized content.

Security TSX

Reviewer Prompt

Always sanitize user-generated or externally sourced content before rendering it to prevent Cross-Site Scripting (XSS) vulnerabilities. Never use dangerouslySetInnerHTML with unsanitized content.

When handling user input or external data:

  1. Use a trusted HTML sanitization library (such as DOMPurify)
  2. Validate and sanitize URLs before rendering images or links
  3. Consider alternative rendering methods that don’t require raw HTML injection

Bad practice:

// Dangerous - susceptible to XSS attacks
const renderTableCell = (content: string) => {
  return <div dangerouslySetInnerHTML= />;
};

Good practice:

import DOMPurify from 'dompurify';

// Safe - content is sanitized before rendering
const renderTableCell = (content: string) => {
  if (needsHtmlRendering(content)) {
    const sanitizedContent = DOMPurify.sanitize(content);
    return <div dangerouslySetInnerHTML= />;
  }
  return <span>{content}</span>;
};

// For image URLs
const renderImage = (imageUrl: string) => {
  const sanitizedUrl = sanitizeImageUrl(imageUrl);
  // Skip rendering if URL is invalid/unsafe
  if (!sanitizedUrl) {
    return null;
  }
  return <img src={sanitizedUrl} alt="User content" />;
};
3
Comments Analyzed
TSX
Primary Language
Security
Category

Source Discussions