-
Notifications
You must be signed in to change notification settings - Fork 688
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
SONARJAVA-4871 S5122: Support detection of Permissive CORS policies f…
…or Spring (#4747) * SONARJAVA-4871 S5122: Support detection of Permissive CORS policies for Spring * Fix autoscan * Fix malformed spring-webmvc dependency * Worked on review comments
- Loading branch information
Showing
7 changed files
with
100 additions
and
13 deletions.
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S1874.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S1874", | ||
"hasTruePositives": true, | ||
"falseNegatives": 150, | ||
"falseNegatives": 151, | ||
"falsePositives": 0 | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
its/autoscan/src/test/resources/autoscan/diffs/diff_S5122.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"ruleKey": "S5122", | ||
"hasTruePositives": true, | ||
"falseNegatives": 18, | ||
"falseNegatives": 26, | ||
"falsePositives": 0 | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -198,5 +198,4 @@ public void addCorsMappings(CorsRegistry registry) { | |
.allowedOrigins("safe.com"); // Compliant | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
java-checks-test-sources/spring-3.2/src/main/java/checks/CORSCheckSample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package checks; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import org.springframework.web.cors.CorsConfiguration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistration; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
|
||
public class CORSCheckSample { | ||
|
||
private void additional_Spring_5_3_methods() { | ||
CorsConfiguration configuration = new CorsConfiguration(); | ||
configuration.setAllowedOrigins(Arrays.asList("*")); // Noncompliant | ||
configuration.setAllowedOrigins(List.of("*")); // Noncompliant | ||
configuration.setAllowedOrigins(List.of("com.mycompany")); // Compliant | ||
configuration.setAllowedOriginPatterns(List.of("*")); // Noncompliant | ||
|
||
CorsRegistration registration = new CorsRegistration(""); | ||
registration.allowedOrigins("*"); // Noncompliant | ||
registration.allowedOriginPatterns("*"); // Noncompliant | ||
registration.allowedOriginPatterns("com.mycompany/*"); // Complaint | ||
|
||
CorsRegistry registry = new CorsRegistry(); | ||
registry.addMapping("*"); // Noncompliant | ||
registry.addMapping("com.mycompany"); // Compliant | ||
registry.addMapping("com.mycompany/*"); // Complaint | ||
} | ||
|
||
private void coverage() { | ||
CorsConfiguration configuration = new CorsConfiguration(); | ||
configuration.setAllowedOrigins(List.of("com.mycompany", "*", "com.yourcompany")); // Noncompliant | ||
configuration.setAllowedOrigins(List.of("com.mycompany", "com.yourcompany")); // Compliant | ||
configuration.setAllowedOrigins(List.of()); // Compliant | ||
configuration.setAllowedOrigins(getList()); // Compliant | ||
var list = List.of("com.mycompany", "*", "com.yourcompany"); | ||
configuration.setAllowedOrigins(list); // Compliant | ||
|
||
CorsRegistration registration = new CorsRegistration(""); | ||
registration.allowedOrigins("com.mycompany", "*", "com.yourcompany"); // Noncompliant | ||
registration.allowedOrigins("com.mycompany", "com.yourcompany"); // Compliant | ||
registration.allowedOrigins(); // Compliant | ||
} | ||
|
||
private static List<String> getList() { | ||
return List.of("com.mycompany", "*", "com.yourcompany"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters