oauth-2.0oauth2clientyii2-api

oAuth2 security issue with clinet_id and secret key : user can press inspect element and earn clinet_id and secret key


I write a rest api with yii2 and i am using oAuth2 , the problem is when user want login , client web application should send request to get token , request should contain client_id and secret_key and username and password in this case user can simply inspect element and click to network and see posted parameter to the server this means user can see client_id and secret_key. client_id and secret_key are signature for each application and server can find out witch application use api. how to handle this security issue?


Solution

  • It seems you have missed out one key element of OAuth 2.0, client type.

    OAuth 2.0 defines two types of clients, public clients and confidentiatl clients.

    2.1. Client Types

    confidential

    These are the clients which can protect a credential. They have the full potential to use authorization code grant type, which obtain token from backchannel request. Because they use backchannel to obtain tokens, their credentials are never exposed to end user(via user agent)

    public

    Clients which cannot protect credentials. For example SPA clients and mobile apps comes to this category.

    In your case, you seems to have a public client (user agent based application in broswer as it seems). In such case, you should set your client type to a public client. If this is not the case, you are not utilizing a proper back channel call from your web application.

    Additionally, public clients which use authorization code flow can use PKCE to avoid authorization code theft attacks. Related RFC can be found from RFC7636