react-security
Installation
SKILL.md
React Security
Priority: P0 (CRITICAL)
Preventing vulnerabilities in client-side apps.
Implementation Guidelines
- XSS Prevention: Never use
dangerouslySetInnerHTMLwithout sanitization. UseDOMPurify.sanitize(input)for all user-provided HTML. Avoidjavascript:protocols inhreforsrc. - Authentication: Store JWT/Sessions in
HttpOnlyandSecurecookies to prevent theft via XSS. Never store secrets inlocalStorageor in the built JS bundle. - Data Flow: Escape all serialized state if injecting into the HTML (e.g., in SSR). Use a Content Security Policy (CSP) to restrict script sources and prevent inline execution.
- CSRF Protection: Use CSRF tokens for state-changing requests (PUT/POST/DELETE). Implement SameSite=Strict cookies where applicable.
- Input Sanitization: Always validate and sanitize user inputs on the backend. Frontend validation is for UX only.
- Dependency Management: Run
npm audit/pnpm auditregularly. Pin specific dependency versions and usenpm-check-updates. - Security Headers: Ensure the server sends
X-Frame-Options: DENY,X-Content-Type-Options: nosniff, andPermissions-Policy.