Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SaToken的Oauth2模块存在开放重定向漏洞风险 #529

Closed
m4ra7h0n opened this issue Oct 23, 2023 · 2 comments
Closed

SaToken的Oauth2模块存在开放重定向漏洞风险 #529

m4ra7h0n opened this issue Oct 23, 2023 · 2 comments

Comments

@m4ra7h0n
Copy link

m4ra7h0n commented Oct 23, 2023

使用版本:

version <= 1.37.0

复现步骤:

需要先配置一个client信息,这个时候我们设置跳转的url位如下模式

@Component
public class SaOAuth2TemplateImpl extends SaOAuth2Template {
    
    // 根据 id 获取 Client 信息 
    @Override
    public SaClientModel getClientModel(String clientId) {
        // 此为模拟数据,真实环境需要从数据库查询 
        if("1001".equals(clientId)) {
            return new SaClientModel()
                    .setClientId("1001")
                    .setClientSecret("aaaa-bbbb-cccc-dddd-eeee")
                    .setAllowUrl("*")
//                    .setAllowUrl("https://*sa-token.cc/") // https://www.baidu.com/sa-token.cc/
//                    .setAllowUrl("https://sa-token.cc*") // https://[email protected]
                    .setContractScope("userinfo")
                    .setIsAutoMode(true);
        } 
        return null;
    }
    
    // 根据ClientId 和 LoginId 获取openid 
    @Override
    public String getOpenid(String clientId, Object loginId) {
        // 此为模拟数据,真实环境需要从数据库查询 
        return "gr_SwoIN0MC1ewxHX_vfCW3BothWDZMMtx__";
    }
    
}

1.我们网站的子域名https://*sa-token.cc/
2.我们网站的子目录https://sa-token.cc*(有可能配置的时候没有加/
分别可以使用如下来绕过
1.https://www.baidu.com/sa-token.cc/
2.https://[email protected]

然后通过正常的oauth2认证流程走,假设使用code模式,到我们接收code的地址就变成了https://www.baidu.com
如果这是一个恶意的网站那么就可以劫持用户。

我去spring-security-oauth中翻了一下,他们的的服务端有一个默认的接受code的地址叫做RedirectionEndPoint,默认接收下面模式的uri:/login/oauth2/code/*,具体的重定向地址可以配置比如http://127.0.0.1:8080/login/oauth2/code/google,google是registrationId,是注册的需要获取用户资源的客户端,而配置的时候需要一个具体的地址,不能填*
我觉得本质问题是这块不应该使用*,而使用*的位置只能是服务端的匹配端,比如文档中的/oauth2/*处理所有oauth2请求,具体可以将此细分,比如参考spring-security的方式。而且如果文档中默认使用的是*也有可能造成一定风险,如果用户不知道有这个漏洞的话,他有可能直接拷贝过来不加修改。

如果包含了重定向的白名单校验部分,仍然可以参考spring中
路径中包括{scheme}://{userinfo}@{host}:{port}/{path}/?{p1=v1}#{fragment}
spring中是进行了严格的匹配,可以看其相关重定向漏洞修复:CVE-2019-3778
以及CVE-2019-11269默认禁用子域名跳转

我不确定哈,你如果觉得有风险就修复一下。或者这个只是用户自己配置的问题。感谢。

@click33
Copy link
Collaborator

click33 commented Oct 24, 2023

收到

@Ardep79
Copy link

Ardep79 commented Nov 1, 2023

使用版本:

versión <= 1.37.0

复现步骤:

需要先配置一个client信息,这个时候我们设置跳转的url位如下模式

@Component
public class SaOAuth2TemplateImpl extends SaOAuth2Template {
    
    // 根据 id 获取 Client 信息 
    @Override
    public SaClientModel getClientModel(String clientId) {
        // 此为模拟数据,真实环境需要从数据库查询 
        if("1001".equals(clientId)) {
            return new SaClientModel()
                    .setClientId("1001")
                    .setClientSecret("aaaa-bbbb-cccc-dddd-eeee")
                    .setAllowUrl("*")
//                    .setAllowUrl("https://*sa-token.cc/") // https://www.baidu.com/sa-token.cc/
//                    .setAllowUrl("https://sa-token.cc*") // https://[email protected]
                    .setContractScope("userinfo")
                    .setIsAutoMode(true);
        } 
        return null;
    }
    
    // 根据ClientId 和 LoginId 获取openid 
    @Override
    public String getOpenid(String clientId, Object loginId) {
        // 此为模拟数据,真实环境需要从数据库查询 
        return "gr_SwoIN0MC1ewxHX_vfCW3BothWDZMMtx__";
    }
    
}

1.我们网站的子域名https://*sa-token.cc/ 2.我们网站的子目录https://sa-token.cc*(有可能配置的时候没有加/) 分别可以使用如下来绕过 1. https://www.baidu.com/sa-token.cc/ 2.https://[email protected]

https://www.baidu.com如果这[是](https://www.baidu.com) 一个恶意的网站那么就可以劫持用户.

我去spring-security-oauth中翻了一下,他们的的服务端有一个默认的接受code的地址叫做,默认接收下面模式RedirectionEndPoint的uri:/login/oauth2/code/*,具体的重定向地址可以配置比如http://127.0.0.1:8080/login/oauth2/code/google, google 是registrationId, 是注册我觉得本质问题是*这块 不应该使用*,而使用的位置*只能是服务端的匹配端,比如文档中的/oauth2/*处理所有oauth2请求,具体可以将此细分,比如参考spring-security的方式。而且如果文档中默认使用的是也有可能造成*一定风险,如果用户不知道有这个漏洞的话,他有可能直接拷贝过来不加修改。

{esquema}://{ userinfo }@{host}:{puerto}/{ruta}/?{p1=v1}#{ fragmento} primavera中是进行了严格的匹配,可以看其相关重定向漏洞修复:CVE-2019-3778 以及CVE-2019-11269默认禁用子域名跳转

我不确定哈,你如果觉得有风险就修复一下。或者这个只是用户自己配置的问题。感谢。

♥️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants