Skip to content

Security implications #1

@psibean

Description

@psibean

Coupling this repo along with this article. There are a few concerns.

Firstly, in regards to the article, you should note that logging sensitive data, such as an access token, is not okay and specifically mention you are only doing it for demonstration purposes. And that, for logging, people should follow the OWASP Logging Cheatsheet.

Secondly:

addCookieToRes(res, user, twitterOAuthToken.access_token)

The whole point of PKCE is that the access token should not be received by the frontend. If you're using OAuth2 to authenticate on an SPA, you should use session authentication using a secure, signed, http only cookie, with it's name prefixed with __Host- for additional security. Ideally, you use the access token to receive what you need and confirm the user against their session, store any info against their session, and then revoke the tokens immediately. If you need access to the identity providers protected resources again, have the user re-authorize.

Even if you set the access token cookie to be secure and http only you would still then need to introduce adequate CSRF protection. And you have to do that with session authentication anyway.

I can see it's adding a JWT, but even if you follow oauth.coms self encoded JWT example and their base page, they do not use an access token as part of the JWT. The idea is to use the identity claims as the JWT payload, not the access token itself.

Additionally, you should make it extremely clear that a JWT should only be stored in memory, and ideally it should not be stored in either localStorage or sessionStorage.

The idea is, once you've got what you needed through OAuth2 - you've identified who the user is on your system, and you should be using that information to then construct your JWT. If you want to use a JWT specific workflow, then use the OpenID Connect (OIDC) workflow, which provides you an ID JWT in addition to an access token.

OAuth2 is for authorization not authentication. They are two very different problems. The OpenID Connect attempts to use OAuth2 as an authentication solution.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions