我一直在用小丑做实验。我已经将我的应用程序配置为与oauth2一起工作。为此,我的application.yml中有一个客户端秘密
根据我在这个话题上发现的几篇文章,客户的秘密应该随时保密。例如,检查https://aaronparecki.com/articles/2012/07/29/1/oauth2-simplified
客户的秘密必须保密。如果部署的应用程序不能保密,比如Javascript或本地应用程序,那么这个秘密就不会被使用。
不过,我注意到生成的auth.oauth2.service.js包含纯文本中的秘密:
return {
login: function(credentials) {
var data = "username=" + credentials.username + "&password="
+ credentials.password + "&grant_type=password&scope=read%20write&" +
"client_secret=mySecretOAuthSecret&client_id=myapp";
return $http.post('oauth/token', data, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"Authorization": "Basic " + Base64.encode("myapp" + ':' + "mySecretOAuthSecret")
}
}).success(function (response) {
var expiredAt = new Date();
expiredAt.setSeconds(expiredAt.getSeconds() + response.expires_in);
response.expires_at = expiredAt.getTime();
localStorageService.set('token', response);
return response;
});
},
我知道在小型化的javascript中很难找到它,但是任何寻找'client_secret‘的人都会很快得到回报。
我是不是遗漏了什么?还是jHipster oauth实现不安全?
谢谢你,安迪
发布于 2015-08-18 02:09:24
由于JS客户端(如jhipster的客户端)无法保守客户端的“秘密”,因此使用客户端机密是毫无意义的。jhipster使用的OAuth2资源所有者密码凭据授予流是针对非常受信任的客户端的-- jhipster的客户端也是如此。它允许您跳过正常的“授权”端点,直接转到“令牌”端点,以获得带有用户凭据的令牌。如果(AS)定义了一个客户端秘密,则需要从客户端JS中传递该秘密。但是,如果您在AS中从内存中的客户端设置中删除了秘密定义(例如,在OAuth2ServerConfiguration.java中注释掉该行),您可以在JS中完全删除它(见下文)。
return {
login: function(credentials) {
var data = "username=" + credentials.username + "&password=" + credentials.password + "&grant_type=password&scope=read%20write&";
return $http.post('oauth/token', data, {
headers: {
"Content-Type": "application/x-www-form-urlencoded",
"Accept": "application/json",
"Authorization": "Basic " + Base64.encode("myapp" + ':' + "")
}
}).success(function (response) {
var expiredAt = new Date();
expiredAt.setSeconds(expiredAt.getSeconds() + response.expires_in);
response.expires_at = expiredAt.getTime();
localStorageService.set('token', response);
return response;
});
},
在删除了你的客户秘密之后,我不认为你的应用程序真的更安全,但它感觉有点干净和诚实--因为你承认使用一个只使用JS的客户端,你只能如此安全。对于JS和本地客户端,通常使用隐式流,它不需要处理客户端秘密。它从更健壮的授权代码授予流中得到简化,因为使用JS或本机客户端不能保密。
无论如何,jhipster可能不应该在JS源代码中包含客户端秘密,但我不认为它会造成任何伤害(因为唯一的选择是拥有一个空白的客户端秘密,而这个秘密并不安全)。您并不是不安全的(因为规范允许这样的事情),但是使用授权代码流(这将需要在jhipster实现中做一些工作)或者让一个小型服务器代理将客户机秘密添加到“令牌”端点,而不是直接从JS添加到请求中,这样会更安全。服务器到服务器之间的通信(例如通过代理)使秘密远离浏览器的视图。
有关使用oauth2:http://alexbilbie.com/2014/11/oauth-and-javascript/的JS专用客户端的陷阱的详细讨论,请参阅本文。
下面是在代理上使用oauth2与angularjs和spring的示例:https://spring.io/blog/2015/02/03/sso-with-oauth2-angular-js-and-spring-security-part-v
https://stackoverflow.com/questions/32038904
复制相似问题