You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: draft-ietf-oauth-browser-based-apps.md
+32Lines changed: 32 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -376,6 +376,38 @@ Remarks and mitigations:
376
376
* To avoid information disclosure from ID Tokens, the application SHOULD be designed to not have any claim that isn't used by the frontend.
377
377
* The application designer SHOULD consider not having refresh tokens at all to avoid the risk of giving prolonged access to the attacker.
378
378
379
+
### Tokens Securely Handled by a Service worker
380
+
In this scenario, a [Service Worker](https://developer.mozilla.org/en-US/docs/Web/API/Service_Worker_API) is responsible for obtaining tokens from the authorization server and passing them to the resource API.
381
+
382
+
Service workers are inherently safe from XSS, because the browser APIs allowing to register one take an origin-constrained URL.
383
+
They can thus be used as a safe store for tokens.
384
+
385
+
In this architecture, a service worker intercepts calls from the frontend to the resource server. As such, it completely isolates calls to the authorization server from XSS attack surface, as all tokens and PKCE secrets are safely kept there without any access from other JavaScript contexts. The service worker is then solely responsible for adding authentication headers to calls to the resource server.
| |-------------------> resource request with token | |
400
+
| | | ---------------------------->| |
401
+
| | | | |
402
+
User Application Service Worker Resource Authorization
403
+
server server
404
+
405
+
#### Security Considerations
406
+
* The service worker MUST initiate the OAuth 2.0 Authorization Code grant with PKCE itself.
407
+
* The service worker MUST intercept the authorization code when the *authorization server* redirects to the application. This makes this architecture completely safe from token or session leaks in case of XSS.
408
+
* The service worker implementation MUST then initiate the token request itself.
409
+
* The service worker MUST not transmit tokens, authorization codes or PKCE secrets (e.g. code verifier) to the frontend application.
410
+
* The service worker MUST block /token or /authorize calls initiating from the frontend application in order to avoid any front-end side-channel for getting credentials: the only way of starting the authorization flow is through the service worker. This protects against re-authorization from XSS-injected code.
0 commit comments