Client-side checks are suggestions
A ProtectedRoute component or a conditional that hides the 'Delete user' button does nothing to stop a direct request. Any check that matters must be repeated on the server. Testers start by collecting every endpoint the SPA calls, then replaying those calls as a lower-privileged user, as another tenant and with no token at all.
What the bundle leaks
- Build-time variables (VITE_*, REACT_APP_*) are inlined into public JavaScript. Third-party secret keys, admin tokens and internal URLs regularly turn up there.
- Source maps shipped to production reveal original source, comments and unlinked routes.
- Feature-flagged or admin-only pages still ship their API calls, which maps endpoints the UI never shows to ordinary users.
React-specific injection sinks
- dangerouslySetInnerHTML with user or CMS content is the classic React XSS sink.
- href and src attributes built from user input can carry javascript: URLs.
- Markdown or rich-text renderers configured to allow raw HTML reintroduce the problem React solved.
- Tokens kept in localStorage are readable by any script that runs, so a single XSS becomes session theft.
The API behind the SPA
Expect the common API flaws: object IDs in URLs that are not checked against the caller (BOLA), admin functions that only check that you are logged in (BFLA), and update endpoints that accept fields like role or isAdmin (mass assignment). Permissive CORS with credentials allowed is worth checking too, because it lets other origins act as the user.
Pointing Pentest-Swarm at a React SPA
Pentest-Swarm tests the deployed app over HTTP. For SPAs the important part is reaching the backend calls that only appear once JavaScript runs.
- Enable
--browserso recon renders the app in headless Chrome and harvests the API calls the frontend makes, rather than seeing an empty HTML shell. - If the backend publishes an OpenAPI document at a common path, recon discovers it and turns each documented path into a test target.
- Supply a test account's bearer token with
--authso the api-security playbook can try cross-user and cross-role access. - Keep scope to the SPA host and its API host; anything outside scope is refused in code.
Where it falls short
A black-box run sees the bundle that ships and the API that answers, but not your repository, so it cannot audit components that never render for the test account. Use a linter rule or SAST for dangerouslySetInnerHTML and secret scanning in CI for keys that should never reach a build. Automated testing also struggles with flows that need a human, such as CAPTCHA or hardware MFA.
Questions
Is a React app secure by default against XSS?
React escapes text it renders, which prevents most reflected and stored XSS. It does not protect dangerouslySetInnerHTML, javascript: URLs or third-party HTML renderers, so those remain the places to test.
Is an API key in my React bundle a vulnerability?
It depends on the key. Publishable keys designed for browsers are fine if the backend enforces access rules. Secret keys, admin tokens or keys with write access are exposed to anyone who opens developer tools.
Do I need a headless browser to test an SPA?
It helps a lot. Without rendering, a crawler sees a near-empty HTML page; with it, the tester observes the real API calls and their parameters.