- React
- Frontend Security, Taint APIs, and Web Accessibility
React Security & Accessibility Interview Questions
React security & accessibility interview questions matter because both are non-negotiable hiring criteria at Apple, Google, Meta, and Airbnb. Candidates must understand how client-side vulnerabilities manifest and how to make interfaces accessible to assistive technologies.
Analyze XSS prevention in React, sanitize dynamic HTML with DOMPurify, learn how React 19 server taint APIs prevent secret leaks, and implement accessible keyboard navigation with roving tabindex and focus trapping for modal dialogs.
React escapes text in JSX, which stops most cross-site scripting, but not all of it: raw HTML passed to dangerouslySetInnerHTML is inserted as is, and URLs built from user input still need checking. The security lessons cover where those holes are, how to sanitize HTML, and React 19's taint APIs, which stop server data such as tokens from being passed to the client by mistake.
The accessibility lessons cover keyboard navigation and focus management, then the accessible modal dialog: trapping focus inside it, rendering it through a portal and returning focus to the trigger when it closes. Both are common machine-coding questions in frontend interviews.
React Security & Accessibility Interview Questions: 4 lessons
React Security: XSS & dangerouslySetInnerHTML
React automatically defends against Cross-Site Scripting (XSS) by escaping all string values inside JSX before rendering to the DOM. Vulnerabilities occur when developers bypass this with dangerouslySetInnerHTML without DOMPurify sanitization, or render user-controlled javascript: URLs in href attributes.
React 19 Security: Server Action Taint APIs
React 19 introduces experimental Taint APIs (experimental_taintObjectReference and experimental_taintUniqueValue) in Server Components to explicitly mark sensitive data like user passwords, tokens, or private keys, causing React to throw a build-time or runtime security error if that data is passed to a Client Component.
Accessible Components: Focus & Keyboard Nav
Accessible React components comply with WAI-ARIA authoring practices by utilizing semantic HTML, proper ARIA states (aria-expanded, aria-selected), managing keyboard events (Arrow navigation, Escape, Enter), and programmatic focus management via useRef and focus() to guarantee screen reader and keyboard parity.
Accessible Modal Dialog with Focus Trapping
An accessible Modal Dialog must be rendered into a React Portal, apply role="dialog" and aria-modal="true", trap keyboard Tab focus strictly within the dialog, close on Escape key or backdrop click, prevent background scrolling, and restore focus to the trigger on close.
Frequently asked questions
Is dangerouslySetInnerHTML safe in React?
Only if the HTML is trusted or sanitized first. React does not escape anything passed through it, so user content must go through a sanitizer such as DOMPurify, which removes scripts, event handlers and javascript: URLs before it is rendered.
Does React prevent XSS automatically?
For text rendered in JSX, yes: React escapes strings before inserting them into the DOM. It does not protect raw HTML inserted with dangerouslySetInnerHTML, or values you hand to third-party code that writes to the DOM itself.
How do you trap focus in a modal dialog in React?
When the dialog opens, move focus into it; on Tab and Shift+Tab, wrap focus between its first and last focusable elements; close it on Escape; and when it closes, return focus to the element that opened it. The native dialog element opened with showModal() handles most of this for you.
