TL;DR
TL;DR
React apps run entirely in the browser, so never put secrets in your code. Before launch, verify no API keys are exposed, check that sensitive operations go through a backend, test authentication flows, and ensure your build doesn't include source maps in production.
React is a client-side framework. Everything in your React code is visible to anyone who views your site. This fundamental fact drives most security concerns for React apps. This checklist covers what you need to verify before launch.
API Keys and Secrets 4
API and Backend Security 4
Authentication 4
Build and Deployment 3
Is React secure by default?
React escapes content by default, which prevents most XSS attacks. However, React apps can still have security issues: exposed API keys, insecure API calls, improper use of dangerouslySetInnerHTML, and authentication handled only on the client side.
::
How do I secure API keys in a React app?
Never put secret API keys in React code. All code sent to the browser is visible. For sensitive operations, create a backend API that makes the calls with your secret keys, and have React call your backend instead.
Should I use localStorage for auth tokens?
LocalStorage is vulnerable to XSS attacks. If an attacker can run JavaScript on your page, they can read localStorage. HttpOnly cookies are more secure for auth tokens because JavaScript can't access them.
::
Scan Your React App
Find exposed secrets and security issues automatically.
Start Free Scan