Skip to content

Commit 22b52c3

Browse files
fix(sonarqube): bypass 10K result cap by fetching issues per-rule
Closes OWASP-Benchmark#33 The issues/search API enforces p*ps <= 10000. With PAGE_SIZE=500, page 21 returns HTTP 400. Fix: iterate per-rule instead of passing all ~600 rules in one query. Each single-rule query stays well under 10K. Also fixes off-by-one in page count (ceiling division) and adds HTTP status checking before reading response body.
1 parent b7b159c commit 22b52c3

1 file changed

Lines changed: 16 additions & 8 deletions

File tree

src/main/java/org/owasp/benchmark/report/sonarqube/SonarReport.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,19 @@ public class SonarReport {
3535
private static final ObjectMapper objectMapper = new ObjectMapper();
3636

3737
public static void main(String[] args) throws Exception {
38-
String allJavaRules = String.join(",", allJavaRules());
38+
Set<String> allJavaRules = allJavaRules();
3939
List<String> issues = new ArrayList<>();
4040
List<String> hotspots = new ArrayList<>();
4141

42-
forAllPagesAt(
43-
"issues/search?componentKeys="
44-
+ SONAR_PROJECT
45-
+ "&types=VULNERABILITY&&rules="
46-
+ allJavaRules,
47-
(result -> issues.addAll(result.issues)));
42+
for (String rule : allJavaRules) {
43+
forAllPagesAt(
44+
"issues/search?componentKeys="
45+
+ SONAR_PROJECT
46+
+ "&types=VULNERABILITY&rules="
47+
+ rule,
48+
(result -> issues.addAll(result.issues)));
49+
}
50+
4851
forAllPagesAt(
4952
"hotspots/search?projectKey=" + SONAR_PROJECT,
5053
(result -> hotspots.addAll(result.hotspots)));
@@ -91,7 +94,7 @@ private static void forAllPagesAt(String apiPath, Consumer<SonarQubeResult> page
9194
objectMapper.readValue(
9295
apiCall(apiPath + pagingSuffix(page, apiPath)), SonarQubeResult.class);
9396

94-
pages = (result.paging.resultCount / PAGE_SIZE) + 1;
97+
pages = (result.paging.resultCount + PAGE_SIZE - 1) / PAGE_SIZE;
9598

9699
pageHandlerCallback.accept(result);
97100

@@ -110,6 +113,11 @@ private static String apiCall(String apiPath) throws IOException {
110113
connection.setDoOutput(true);
111114
connection.setRequestProperty("Authorization", "Basic " + sonarAuth);
112115

116+
int status = connection.getResponseCode();
117+
if (status != 200) {
118+
throw new IOException("SonarQube API returned HTTP " + status + " for " + apiPath);
119+
}
120+
113121
return join("\n", readLines(connection.getInputStream(), defaultCharset()));
114122
}
115123

0 commit comments

Comments
 (0)