3 ms·
Yup, a SPA can't really keep a secret, right? That's why the best option is to set up a secure middleware layer to hold your secrets. Here's an example using r
by mooreds 7y ago
Yup, a SPA can't really keep a secret, right?
That's why the best option is to set up a secure middleware layer to hold your secrets. Here's an example using react: https://fusionauth.io/blog/2020/03/10/securely-implement-oauth-in-react https://fusionauth.io/blog/2020/03/10/securely-implement-oau...
(Full disclosure, this is a post on the blog of the companyfor which I work.)
- tptacek 7y agoPeople build SPAs with the OAuth2 code flow (and PKCE) all the time.
- mooreds 7y agoSorry, I misspoke. Those SPAs always have middleware to handle the authorization code, right? It's really the implicit grant (where access tokens are available to the client) that should be avoided.
- thecopy 7y agoNo, with PKCE you can do auth code from an SPA
- mooreds 7y agoWith the implicit grant? I read the RFC recently and thought it was only for the Authorization Code grant. From https://tools.ietf.org/html/rfc7636 https://tools.ietf.org/html/rfc7636 "OAuth 2.0 public clients utilizing the Authorization Code Grant are susceptible to the authorization code interception attack. This specification describes the attack as well as a technique to mitigate against the threat through the use of Proof Key for Code Exchange (PKCE, pronounced "pixy")." At the end of the day, no matter what the grant, if you store the access tokens (or refresh tokens) in the browser running an SPA, it is vulnerable to an XSS attack, right?
- krooj 7y agoWith PKCE you can use the authorzation_code grant flow. The whole issue with SPAs and the authorization_code grant flow isn't the presence or absence of middleware; rather, it's the lack of a confidential client. PKCE gets around the requirement for a client to securely store it's secret.
- mooreds 7y agoRight, but even after the authorization code flow, the access token is stored somewhere on the client. My understanding is that that is suboptimal because the browser has such a large surface area to secure.
- jimdigriz 7y agoThis is solvable by use of a web worker as a key vault: https://gitlab.com/jimdigriz/oauth2-worker https://gitlab.com/jimdigriz/oauth2-worker
- mooreds 7y agoThat is very cool, thanks for sharing! Edit: This seems pretty new, any timeline for a release?
- jimdigriz 7y agoThanks. I am not wholly convinced of the benefits of releases for a project of this scale, I suspect most will just reimplement the moving parts in their own code for a variety of (usually NIH) reasons.