Possible issue with localStorage #1536
Replies: 5 comments 11 replies
-
This isn't really specific to Bluesky as much as just the overal browser extension security model, specifically host permissions, functionality permissions, and browsers' same-origin policy. When you install a browser extension, it asks you for the permissions it needs, including the sites and functionality it needs access to. Those may give it access to read those sites' cookies, run content scripts in their origins, to read their localStorage, etc. So if you grant a browser extension access to google.com or facebook.com and cookies or storage, it can often get your credentials for those sites too. Some details here have changed between manifest v2 and v3, some significantly, but the overall security model is still roughly the same. |
Beta Was this translation helpful? Give feedback.
-
But again... the localStorage item for Bluesky has not only the access token, it also has the refresh token. So it's not just a short-lived token we're talking about, since it can be refreshed. And again, even if someone could only get access for a short time, they have complete control of the user's account at that point and can do a lot of damage if they're malicious. Yes, I already do know more than a little about keeping access tokens out of public view, which is why I'm bringing up this point for discussion. Keeping API access and refresh tokens in a place the general internet can see is simply a bad practice -- again, unless I'm missing a security measure that isn't obvious. |
Beta Was this translation helpful? Give feedback.
-
Hey @GreenFootballs thanks for raising the concern. Browser extensions are in general are rife with security complications. They could also, for instance, log your key strikes to find your password. Unfortunately, as @snarfed pointed out, user credentials do need to be stored somewhere accessible by the application & generally if it's accessible by the application, it's also accessible by XSS attacks or malicious browser extensions. One step we take to guard against attacks is to rotate your refresh token every time you get a new access token. This means that refresh tokens are short-lived as the current refresh token is invalidated every time you get a new access token. These things evolve of course, but I would say it's industry standard to store refresh tokens for SPAs in local storage (here's an auth0 blog post on the topic) with the caveat that you should be rotating your refresh token (which we are). I'm curious what alternatives you might recommend? |
Beta Was this translation helpful? Give feedback.
-
Yes, it was new to me as well! That's what I meant by "a security measure that isn't obvious." This does go a long way toward mitigating the token hijacking issue if I understand it correctly. I plan on experimenting with it a bit. In my own projects I never have API tokens in a web client; I usually use a session token that authenticates the user with the server, and all the API calls are proxied server-side, so that tokens are never exposed to the web at all. Thanks for the replies. |
Beta Was this translation helpful? Give feedback.
-
iiuc, OAuth can/will fix this, if clients implement DPoP using non-extractable WebCrypto keys |
Beta Was this translation helpful? Give feedback.
-
I've noticed that the Bluesky web app uses localStorage for user profile info and other things, but I also see the API access and refresh tokens in that root item. Are they supposed to be there? Seems like this could be a security problem because browser extensions can easily view the contents of localStorage, and potentially hijack a user's tokens. Am I missing something that would prevent this?
Beta Was this translation helpful? Give feedback.
All reactions