clinet_id 和密钥的 oAuth2 安全问题:用户可以按检查元素并获得 clinet_id 和密钥
oAuth2 security issue with clinet_id and secret key : user can press inspect element and earn clinet_id and secret key
我用 yii2 写了一个休息 api 我正在使用 oAuth2 ,问题是当用户想要 login , 客户端 web 应用程序 应发送请求以获取 token ,请求应包含 client_id 和 secret_key 以及username 和 password 在这种情况下,用户可以简单地检查元素并单击网络并查看发布到服务器的参数,这意味着用户可以看到 client_id 和 secret_key。
client_id 和 secret_key 是每个应用程序的签名,服务器可以找出 应用程序使用 api。
如何处理这个安全问题?
您似乎错过了 OAuth 2.0 的一个关键要素,客户端类型。
OAuth 2.0 定义了两种类型的客户端,public clients 和 confidentiatl clients.
机密
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.
在你的情况下,你似乎有一个 public 客户端(看起来是浏览器中基于用户代理的应用程序)。在这种情况下,您应该将客户端类型设置为 public 客户端。如果不是这种情况,则说明您没有使用来自 Web 应用程序的正确反向通道调用。
此外,public使用授权码流的客户端可以使用PKCE来避免授权码窃取攻击。相关的 RFC 可以从 RFC7636
找到
我用 yii2 写了一个休息 api 我正在使用 oAuth2 ,问题是当用户想要 login , 客户端 web 应用程序 应发送请求以获取 token ,请求应包含 client_id 和 secret_key 以及username 和 password 在这种情况下,用户可以简单地检查元素并单击网络并查看发布到服务器的参数,这意味着用户可以看到 client_id 和 secret_key。 client_id 和 secret_key 是每个应用程序的签名,服务器可以找出 应用程序使用 api。 如何处理这个安全问题?
您似乎错过了 OAuth 2.0 的一个关键要素,客户端类型。
OAuth 2.0 定义了两种类型的客户端,public clients 和 confidentiatl clients.
机密
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.
在你的情况下,你似乎有一个 public 客户端(看起来是浏览器中基于用户代理的应用程序)。在这种情况下,您应该将客户端类型设置为 public 客户端。如果不是这种情况,则说明您没有使用来自 Web 应用程序的正确反向通道调用。
此外,public使用授权码流的客户端可以使用PKCE来避免授权码窃取攻击。相关的 RFC 可以从 RFC7636
找到