-
Notifications
You must be signed in to change notification settings - Fork 56
Why OAuth? #12
Comments
Please say I'm missing something |
ASAR archives are simply a concatenation of source files... it is easy to extract any original plain text. Still, OAuth can be used also in JavaScript-centric applications. |
@marcoancona but this package doesn't follow those guidelines from google, right? |
I am not sure, I am not an expert of OAuth nor of this library. What do you think it's not matching the guideline? |
@mmathys you can use it for electron for example, that way you can hide the secret |
@AlexandreKilian do you store the secret inside the electron application source code? |
Having the secret inside of the client is a huge no no, this library should either be using the implicit grant flow or it should be retrieving a code which get's sent up to an intermediate api which then exchanges it for an access token using the secret. I'd recommend removing the function which can exchange the code for a token as the secret should never be inside of the client. |
The authorization_code flow is the correct decision, but because the client is a public client, you should also implement the Proof Key for Code Exchange (PKCE) Here's the RFC called This is also what google recommends - https://developers.google.com/identity/protocols/OAuth2InstalledApp |
After researching OAuth solutions for Electron apps for several weeks and trying to determine if this library was safe for production, I don't think it is. +1 for what @mcastany said. RFC 8252 (also known as BCP 212) is where the industry seems to be going. That doc, along with Google's recommendation for Native Apps, are very good explanations of all the intricacies. I would add to @mcastany's comment that you should not use a secret with Google or other services. From RFC 8252, Section 8.5:
google-auth-library-nodejs recommends using the iOS setting in the Google API Console so the server doesn't require a secret:
Including a client ID and secret in your Electron app makes it trivial for other developers/hackers to impersonate your app. It's not as simple as "use the authorization code flow", because the server-side way of using the authentication code flow and the client-side (i.e. Electron) way of using authorization code flow have different security vulnerabilities (i.e. in Electron a secret cannot be kept!). The way around this is using a loopback IP address as the redirect URL, along with a few other tricks (PKCE, state parameter) to ensure that only your app can receive authentication responses. RFC 8252 is actually a very simple read and if you're doing anything in this ballpark is worth your 20 minutes. From working on OAuth in Electron for several weeks, I believe these practices should be followed:
Basically, setting up OAuth with Electron the right way is pretty involved, and not something that is easy to provide out-of-the-box. This repo no longer supports the best practices. I haven't had time to mess with it, but AppAuth is an effort to implement these patterns in iOS, macOS, Android, and JavaScript. AppAuth-JS looks very promising as a successor to this project. An AppAuth-Electron build on top of AppAuth-JS would be very interesting. @mawie81 At this point, given that there are official IETF recommendations on how to do OAuth in Native Apps, I'd recommend that a very large, prominent disclaimer is put at the top of the README saying: IMPORTANT SECURITY NOTICE: This repo was a proof of concept and unfortunately it is not secure to use for production purposes. If you're trying to implement OAuth in an Electron app, please see IETF RFC 8252, Google's recommendations (here and here), or AppAuth-JS.It's important to protect the reputation of Electron and the Electron community by ensuring that the highest number of apps possible support security best practices, especially when it comes to authenticating with 3rd party services. |
@aguynamedben, thanks for the detailed analysis. |
Thank you @aguynamedben for looking so deeply into this. To make it even more clear I'll look into deprecating the package on npm and will most likely put the whole repo into read-only mode in a couple of days. Ones again thanks for your support and putting time into this. |
@marcoancona For what's it's worth, there are some notes about the loopback IP and firewalls in RFC 8252, Section 8.3:
So it's recommended to use 127.0.0.1, not localhost. I have not yet run into any issues using 127.0.0.1 aside from it's a little awkward looking for a user to land on a 127.0.0.1 address in their web browser after they OAuth. From there, I use JavaScript to open a deep-linked URL (i.e. myapp://oauth/finished) that opens my app again (see app.setAsDefaultProtocolClient()). @mawie81 Thanks for doing that, and thanks for the effort you took in originally releasing this helpful code. It helped me get my project off the ground very quickly going down the OAuth rabbit hole until that was appropriate. 🙏 |
@aguynamedben appreciate the research, @mawie81 submitted it to nodesecurity.io |
Why would you authenticate a public client with OAuth?
You have nowhere to hide the client secret so in the end everyone has access to all the data of all the users.
The text was updated successfully, but these errors were encountered: