TL;DR
This 20-item checklist covers critical React security configurations: XSS prevention, form security, state management, dependencies, and API calls. 5 critical items must be fixed before launch, 8 important items within the first week, and 7 recommended items when you can.
Quick Checklist (5 Critical Items)
XSS Prevention 4
::checklist-item{label="External links use rel="noopener noreferrer"" description="Prevents window.opener access from external pages. How to secure external links"} ::
Form Security 4
::checklist-item{label="Autocomplete attributes set correctly" description="autocomplete="off" for sensitive fields if needed. How to configure autocomplete"} :: ::checklist-item{label="Password fields use type="password"" description="Don't use type="text" for passwords. How to secure password fields"} ::
State Management 4
Dependencies 4
API Calls 4
React Security Best Practices
React's default escaping prevents most XSS attacks, making it safer than vanilla JavaScript. However, certain patterns like dangerouslySetInnerHTML, user-provided URLs in href, and storing secrets in state can introduce vulnerabilities.
Is React safe from XSS attacks?
React escapes content by default, preventing most XSS attacks. However, using dangerouslySetInnerHTML bypasses this protection. If you must render user HTML, sanitize it with DOMPurify first. Also validate user-provided URLs before using them in href attributes.
Should I store tokens in React state?
Avoid storing sensitive tokens in React state or localStorage. State can be accessed via React DevTools, and localStorage is accessible to any XSS attack. Use HttpOnly cookies for sensitive tokens instead - they can't be accessed by JavaScript.
How do I prevent CSRF in React?
Use SameSite cookies (Strict or Lax) for session management. If you need additional protection, implement anti-CSRF tokens: generate a token on the server, store it in a cookie, and include it in form submissions or request headers.
Scan Your React Project
Our scanner checks for XSS vulnerabilities, insecure patterns, and dependency issues.
Start Free Scan