OAuth2.0进阶

请求授权页面时的state防止的是什么跨站请求伪造

看起来分两种:

  1. A CSRF attack against the client’s redirection URI allows an attacker to inject its own authorization code or access token
    防止的是在redirectURI跨站请求伪造,攻击者把客户端与自己的code,refreshToken注入进而关联起来。
    The client MUST implement CSRF protection for its redirection URI
    重定向URI可能重定向到前端域名,也能重定向到后端接口,从CSRF角度来说,这里影响是什么?
  2. A CSRF attack against the authorization server’s authorization endpoint can result in an attacker obtaining end-user authorization for a malicious client without involving or alerting the end-user.
    基于认证端点的CSRF攻击,从恶意客户端中拿走受害者的凭证,认证服务器也要防止CSRF,避免在用户不知情的情况下授权

分析CSRF攻击的防护措施与原理时,需要明白CSRF攻击是指是用户主动或不经意在恶意UI级应用(如此处指具体恶意网站,而不是恶意浏览器)触发了本应该是正常网站发出的请求,导致授权错误;跨站请求伪造,就是在非期望的网站发出了正常网站的请求,此时不要考虑到什么code窃取,脚本代替发送等概念严重混乱的情况。 所以授权发起端要发出 state并且检查重定向回来时带的state是不是自己发出去的

PKCE协议

这个协议简单来说就是在发起鉴权请求时,先发密文(可由明文计算出),后面code换token时,再发明文,以此来确认发起授权的换token的是同一个客户端,防止CSRF和code注入攻击
协议解释:https://blog.csdn.net/weixin_43333483/article/details/126256938?utm_source=pocket_saves
解释2:这个人就乱说了,他说用了PKCE就不需要client_secret https://juejin.cn/post/7037403929063194638?utm_source=pocket_saves
而我们实践中,在用code换取token时也要传code,这相当于是采用明文的code_challenge, 实际OAuth2.0没要求在换token时带state

用PKCE还需要client_secret吗?需要的,掘金文章那个人在乱说

这里就摆明了:https://oauth.net/2/pkce/

PKCE (RFC 7636) is an extension to the Authorization Code flow to prevent CSRF and authorization code injection attacks.PKCE is not a form of client authentication, and PKCE is not a replacement for a client secret or other client authentication. PKCE is recommended even if a client is using a client secret or other form of client authentication like private_key_jwt.

RFC https://www.rfc-editor.org/rfc/rfc7636

有PKCE了还需要state吗?

如果不知道,那就"抄": AWS的登录链接

https://signin.aws.amazon.com/signin?
redirect_uri=https://us-east-1.console.aws.amazon.com/billing/home?region=ap-southeast-1
&state=hashArgs%23%2Fbills&isauthcode=true
&client_id=arn:aws:iam::8888888888:user/portal-aws-auth
&forceMobileApp=0
&code_challenge=MWS_YzKH0m7imyomWgNjU2GKGm5tlTNOHZCz0ZWoyuU
&code_challenge_method=SHA-256

都是需要的 state保护的是发起授权接受code这个流程,让客户端保证授权请求时它发起的,code_challenge保护的是,发起授权使用code这一流程,让服务端确认获取code和使用code的是同一个客户端。
参考链接:https://security.stackexchange.com/questions/214980/does-pkce-replace-state-in-the-authorization-code-oauth-flow?utm_source=pocket_saves

进一步OIDC实现SSO
reidect_uri应该是到前端地址还是后端?

首先明确的是谁发起的authentication请求,就应该重定向到谁,我们实践中,为了让前端感知到账号已登出进行本地存储清理,所以是前端跳转发起SSO登录/authencation请求

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值