Skip to main content
These rules help prevent common security vulnerabilities like code injection and exposed secrets.

Rules

Severity: error
Rule ID: react-doctor/no-eval
Prevents eval(), new Function(), and string-based code execution. These are major code injection risks.Why it’s dangerous:
  • Allows arbitrary code execution
  • Common XSS vector
  • Bypasses Content Security Policy
  • Opens door to injection attacks
Bad:
Good:
If you absolutely need dynamic code execution, use a sandboxed environment like VM2 or Web Workers with restricted permissions.
Severity: error
Rule ID: react-doctor/no-secrets-in-client-code
Detects hardcoded secrets, API keys, and tokens in client-side code. Client code is public and secrets should never be embedded.Why it’s dangerous:
  • Anyone can view client-side code
  • API keys can be extracted and abused
  • Can lead to unauthorized access
  • May violate service ToS
Patterns detected:
  • Stripe keys: sk_live_*, sk_test_*
  • AWS keys: AKIA[0-9A-Z]{16}
  • GitHub tokens: ghp_*, gho_*, github_pat_*
  • GitLab tokens: glpat-*
  • Slack tokens: xox[bporas]-*
  • OpenAI keys: sk-[a-zA-Z0-9]{32,}
  • Variables named: apiKey, secret, token, password, credential
Bad:
Good:
In Next.js, only variables prefixed with NEXT_PUBLIC_ are exposed to the client. Never prefix secret keys with NEXT_PUBLIC_.
Environment variable setup:
False positive reduction: This rule ignores variables ending with common UI-related suffixes like _LABEL, _TEXT, _TITLE, _NAME, _ID, _URL, etc.

Additional Security Best Practices

While these rules catch common issues, follow these practices for secure React apps:

API Keys

  • Never commit .env files to git
  • Use .env.local for local development
  • Use platform environment variables in production
  • Rotate leaked keys immediately

Client vs Server

Content Security Policy

Implement CSP headers to prevent XSS:

Input Sanitization

Always sanitize user input:

React Security

  • Avoid dangerouslySetInnerHTML
  • Use the jsx-a11y/no-script-url rule
  • Enable the react/no-danger rule
  • Validate all user input server-side