Skip to content

Commit c566904

Browse files
authored
fix: disable central analyzer after failures (#7993)
1 parent 46042fd commit c566904

File tree

4 files changed

+15
-5
lines changed

4 files changed

+15
-5
lines changed

core/src/main/java/org/owasp/dependencycheck/analyzer/CentralAnalyzer.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ public void analyzeDependency(Dependency dependency, Engine engine) throws Analy
247247
long sleepingTimeBetweenRetriesInMillis = BASE_RETRY_WAIT;
248248
boolean success = false;
249249
Model model = null;
250+
DownloadFailedException lastException = null;
250251
if (cache != null) {
251252
model = cache.get(ma.getPomUrl());
252253
}
@@ -261,6 +262,7 @@ public void analyzeDependency(Dependency dependency, Engine engine) throws Analy
261262
Downloader.getInstance().fetchFile(new URL(ma.getPomUrl()), pomFile);
262263
success = true;
263264
} catch (DownloadFailedException ex) {
265+
lastException = ex;
264266
try {
265267
Thread.sleep(sleepingTimeBetweenRetriesInMillis);
266268
} catch (InterruptedException ex1) {
@@ -287,6 +289,10 @@ public void analyzeDependency(Dependency dependency, Engine engine) throws Analy
287289
} else {
288290
LOGGER.warn("Unable to download pom.xml for {} from Central; "
289291
+ "this could result in undetected CPE/CVEs.", dependency.getFileName());
292+
setEnabled(false);
293+
LOGGER.warn("Disabling the Central Analyzer due to repeated download failures; Central Search "
294+
+ "may be down see https://status.maven.org/\n Note that this could result in both false "
295+
+ "positives and false negatives", lastException);
290296
}
291297

292298
} catch (AnalysisException ex) {
@@ -303,21 +309,25 @@ public void analyzeDependency(Dependency dependency, Engine engine) throws Analy
303309
}
304310
} catch (TooManyRequestsException tre) {
305311
this.setEnabled(false);
306-
final String message = "Connections to Central search refused. Analysis failed.";
312+
final String message = "Connections to Central search refused. Analysis failed. Disabling Central analyzer - this " +
313+
"could lead to both false positives and false negatives.";
307314
LOGGER.error(message, tre);
308315
throw new AnalysisException(message, tre);
309316
} catch (IllegalArgumentException iae) {
310317
LOGGER.info("invalid sha1-hash on {}", dependency.getFileName());
311318
} catch (FileNotFoundException fnfe) {
312319
LOGGER.debug("Artifact not found in repository: '{}", dependency.getFileName());
313320
} catch (ForbiddenException e) {
321+
this.setEnabled(false);
314322
final String message = "Connection to Central search refused. This is most likely not a problem with " +
315323
"Dependency-Check itself and is related to network connectivity. Please check " +
316324
"https://central.sonatype.org/faq/403-error-central/.";
317325
LOGGER.error(message);
318326
throw new AnalysisException(message, e);
319327
} catch (IOException ioe) {
320-
final String message = "Could not connect to Central search. Analysis failed.";
328+
this.setEnabled(false);
329+
final String message = "Could not connect to Central search. Analysis failed; disabling Central analyzer - this " +
330+
"could lead to both false positives and false negatives.";
321331
LOGGER.error(message, ioe);
322332
throw new AnalysisException(message, ioe);
323333
}

core/src/main/resources/dependencycheck.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ analyzer.central.url=https://search.maven.org/solrsearch/select
7878
# Note - the central query is used in a String.format(query, url, sha1)).analyzer.jar.enabled
7979
# As such, it must have two %s and any other % must be escapped by doubling it
8080
analyzer.central.query=%s?q=1:%s&wt=xml
81-
analyzer.central.retry.count=7
81+
analyzer.central.retry.count=3
8282
analyzer.central.parallel.analysis=false
8383
analyzer.central.use.cache=true
8484
central.content.url=https://search.maven.org/remotecontent?filepath=

core/src/test/resources/dependencycheck.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ central.content.url=https://search.maven.org/remotecontent?filepath=
7878
# Note - the central query is used in a String.format(query, url, sha1)).
7979
# As such, it must have two %s and any other % must be escapped by doubling it
8080
analyzer.central.query=%s?q=1:%s&wt=xml
81-
analyzer.central.retry.count=7
81+
analyzer.central.retry.count=3
8282
analyzer.central.parallel.analysis=false
8383

8484
# the URL for searching NPM Audit API

utils/src/test/resources/dependencycheck.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ central.content.url=https://search.maven.org/remotecontent?filepath=
8080
# Note - the central query is used in a String.format(query, url, sha1)).
8181
# As such, it must have two %s and any other % must be escapped by doubling it
8282
analyzer.central.query=%s?q=1:%s&wt=xml
83-
analyzer.central.retry.count=7
83+
analyzer.central.retry.count=3
8484
analyzer.central.parallel.analysis=false
8585

8686
# the URL for searching NPM Audit API

0 commit comments

Comments
 (0)