Q20: What is the Backend-for-Frontend (BFF) Pattern and how does it optimize SPA security?
The Backend-for-Frontend (BFF) security pattern introduces a lightweight server-side proxy component between a Single Page Application (SPA) and downstream microservices.
Operational Flow:
- The SPA interacts strictly with the BFF proxy using secure,
httpOnly,SameSiteencrypted session cookies. - The BFF server handles the OAuth 2.0 PKCE token exchange flow and stores Access/Refresh Tokens securely in server-side session memory.
- When the SPA calls an API, the BFF intercepts the cookie request, attaches the stored Bearer Access Token server-side, and proxies the request to the target backend API.
Backend-for-Frontend (BFF) Token Isolation Architecture
Key Takeaways
BFF isolates raw OAuth tokens entirely on the server side, keeping them out of browser DOM memory.
The browser talks to the BFF via httpOnly cookies, eliminating token theft via XSS.