我有一個 Spring Boot 應用程序,在調用 AuthorizeRequests() 的行中,我的配置函數出現以下聲納嚴重缺陷。我應該如何修復它?謝謝。Make sure that Permissions are controlled safely here. Controlling permissions is security-sensitive. It has led in the past to the following vulnerabilities: CVE-2018-12999 CVE-2018-10285 CVE-2017-7455我的配置類:@Configuration@EnableWebSecuritypublic class MyConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception { http .authorizeRequests() // Sonar complain this line here .antMatchers("/v1/").permitAll() .antMatchers("/**").authenticated() .and().httpBasic() .and().cors(); }}
1 回答

眼眸繁星
TA貢獻1873條經驗 獲得超9個贊
我剛剛查找了聲納中的錯誤描述,下面是聲納中的錯誤描述。
控制權限是安全敏感的。它在過去導致了以下漏洞:
CVE-2018-12999
CVE-2018-10285
CVE-2017-7455
攻擊者只能破壞他們有權訪問的內容。因此,限制他們的訪問是防止他們造成嚴重破壞的好方法,但必須采取正確的做法。
此規則標記控制對資源和操作的訪問的代碼。目標是指導安全代碼審查。
以下是導致聲納問題的代碼
.authorizeRequests() // Sonar complain this line here
.antMatchers("/v1/").permitAll()
.antMatchers("/**").authenticated()
正如我在您的問題的評論中提到的,不要盲目授權請求,訪問應該受到限制,如下所示
http.authorizeRequests()
.antMatchers("/", "/home").access("hasRole('USER')")
.antMatchers("/admin/**").hasRole("ADMIN")
.and()
// some more method calls
如果這是您的測試/非生產代碼,只需在抱怨問題的行添加//NOSONAR,聲納將繞過它,但**不要在生產環境中使用//NOSONAR。
添加回答
舉報
0/150
提交
取消