Spring boot 使用Spring security解决声纳关键问题
我正在使用SpringBoot2和OktaStarter。我的安全配置如下Spring boot 使用Spring security解决声纳关键问题,spring-boot,spring-security,sonarqube,okta,Spring Boot,Spring Security,Sonarqube,Okta,我正在使用SpringBoot2和OktaStarter。我的安全配置如下 @Override protected void configure(HttpSecurity http) throws Exception { http.authorizeRequests().anyRequest().authenticated().and().oauth2ResourceServer().jwt(); // Send a 401 message to the
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().anyRequest().authenticated().and().oauth2ResourceServer().jwt();
// Send a 401 message to the browser (w/o this, you'll see a blank page)
Okta.configureResourceServer401ResponseBody(http);
}
所有工作正常,但sonar在authorizeRequest()上提供以下安全热点,如下所示
“请确保在此安全地控制权限
控制权限是安全敏感的。它在过去导致了以下漏洞:
CVE-2018-12999
CVE-2018-10285
CVE-2017-7455
攻击者只能破坏他们可以访问的内容。因此,限制他们的访问是防止他们造成破坏的一个好方法,但必须正确地进行
此规则标记控制对资源和操作的访问的代码。目标是指导安全代码检查
更具体地说,它将引发有关以下Spring代码的问题:
实现接口的任何类的定义
org.springframework.security.access.AccessDecisionVoter
org.springframework.security.access.AccessDecisionManager
org.springframework.security.access.AfterInvocationProvider
org.springframework.security.access.PermissionEvaluator
org.springframework.security.access.expression.SecurityExpressionOperations
org.springframework.security.access.expression.method.MethodSecurityExpressionHandler
org.springframework.security.core.GrantedAuthority
org.springframework.security.acls.model.PermissionGrantingStrategy
任何扩展类的类的定义
org.springframework.security.config.annotation.method.configuration.globalMethodSecurity配置
任何带注释的方法
发布前批注:@PreAuthorize、@PreFilter、@PostAuthorize或@PostFilter来自org.springframework.security.access.prepost包
@org.springframework.security.access.annotation.securied
调用以下任何方法
org.springframework.security.acls.model.MutableAclService:createAcl、deleteAcl、updateAcl
org.springframework.security.config.annotation.web.builders.HttpSecurity:authorizeRequests
实现org.springframework.security.core.GrantedAuthority的匿名类或直接实现此接口的任何类的实例化。
它还将对javax.annotation.security包中的JSR-250 annotation@RolesAllowed、@PermitAll和@DenyAll提出问题
问问自己
至少有一个访问的操作或资源是安全敏感的。
没有适当的访问控制,或者它没有涵盖所有敏感操作和资源。
用户拥有他们不需要的权限。
访问控制基于用户输入或某些其他不安全数据。
权限很难删除或需要很长时间才能更新。
如果您对第一个问题和以下任何一个问题的回答是肯定的,您将面临风险
推荐的安全编码实践
第一步是将所有敏感操作限制为经过身份验证的用户
每个用户应具有尽可能最低的权限。访问控制粒度应与每个资源或操作的敏感度相匹配。敏感度越高,访问权限越小
不要将访问控制基于用户输入或可能被篡改的值。例如,开发人员不应该从HTTP cookie读取用户权限,因为它可以在客户端进行修改
检查对每个操作和资源的访问是否受到适当限制
使管理员能够在必要时快速删除权限。这使他们能够减少攻击者在发生漏洞时可以访问您的系统的时间
记录并监视被拒绝的访问请求,因为它们可能暴露攻击
看
OWASP 2017年前10名A5类-博肯访问控制
无国界医生组织前25名-多孔防御”
作为修复,我做了几件事,但问题仍然存在
修正:
有人能帮忙吗
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/api/**").access("hasAnyAuthority('CLIENT', 'ADMIN','OPERATION')").anyRequest()
.authenticated().and().oauth2ResourceServer().jwt();
// Send a 401 message to the browser (w/o this, you'll see a blank page)
Okta.configureResourceServer401ResponseBody(http);
}