RFC 10017 recommends keeping OAuth tokens out of the browser

In short

3 architecture patterns, ranked by security; BCP 212 the document's Best Current Practice number; minutes to hours typical access-token lifetime in a browser client; hours or days how long a refresh token often stays valid

What does OAuth do in a web page?

OAuth 2.0 is the system behind "sign in with a third party" and behind many apps that call an API for you. The app (the client) sends you to an authorization server, you log in there, and the app receives a token. An access token is a short-lived key that a resource server (the API) accepts. A refresh token is a longer-lived key the app can swap for new access tokens without asking you again.

A page running in your browser is a public client: it cannot keep a secret. The RFC says today's best practice is the Authorization Code grant with PKCE, and then asks where the tokens should live.

The threat: code that is not isolated

Section 5 starts from an uncomfortable assumption. Even with output encoding, a Content Security Policy and Subresource Integrity, "there is a risk that the attacker might find a way to trigger the execution of malicious JavaScript" (cross-site scripting, or a compromised third-party script). Once it runs, it can read localStorage and IndexedDB, call functions, and override built-in behaviour.

The RFC lists four things such code can do:

Consequences are ranked too. A stolen refresh token allows "long-term impersonation", and the attack stops only when the server refuses the token because it has expired, rotated or been revoked. The RFC says it is "not uncommon" for a refresh token to stay valid "for multiple hours or even days". A stolen access token gives short-term impersonation, with lifetimes "ranging from minutes to hours". Hijacking the running client is the least powerful, because the attacker is still bound by the client's own policies, such as CORS rules on the server.

Which OAuth design is safest for a web app?

The BFF. The RFC stresses that the BFF is "a component of the frontend application", not an API gateway. It handles the OAuth flow, keeps tokens against a cookie-based session, and attaches the right access token to each request. The browser never sees a token. Because the BFF is a confidential client, script in the page cannot start a new flow to get its own. The RFC says the architecture "ensures that the application's attack surface does not increase by using OAuth": what remains is hijacking the client, "a problem inherent to web applications". The cost is stated openly: it is "significantly more complicated" than a browser-only app, and proxying can add "a significant burden" on servers.

The token-mediating backend. The backend obtains tokens but gives the access token to the page, which calls APIs directly. This stops refresh-token abuse and new-flow attacks, but "the attacker still has the ability to gain direct access to resource servers".

The browser-based client. Simple, and it "results in a significant increase in the attack surface": the attacker can extract "a full-featured set of tokens".

Hardening a browser-only client

For teams that stay with pattern 3, the RFC lists mitigations and is candid about their limits.

Isolating tokens does not close the biggest hole. The RFC repeats that a fully isolated store, a Service Worker or a Web Worker still cannot stop script from running its own Authorization Code flow and getting a fresh set of tokens.

What it rules out

Section 7 lists patterns it discourages or forbids.

Terms in plain English

Where things stand

RFC 10017 is a published Best Current Practice, so it is guidance, not a protocol change. It builds on the OAuth security BCP, RFC 9700, and restricts some of its advice further. We did not check which libraries, identity providers or frameworks follow its three-pattern ranking, so this story makes no claim about adoption.

Sources

Sources

Related stories

More from Wi-Fi Wizards

All stories from Wi-Fi Wizards