Skip to content

Commit 8ebeec0

Browse files
committed
fix: disable central analyzer after failures
1 parent eefb8d7 commit 8ebeec0

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

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

Lines changed: 14 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,12 @@ 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+
if (lastException != null) {
293+
setEnabled(false);
294+
LOGGER.warn("Disabling the Central Analyzer due to repeated download failures; Central Search " +
295+
"may be down see https://status.maven.org/\n Note that this could result in both false " +
296+
"positives and false negatives", lastException);
297+
}
290298
}
291299

292300
} catch (AnalysisException ex) {
@@ -303,21 +311,25 @@ public void analyzeDependency(Dependency dependency, Engine engine) throws Analy
303311
}
304312
} catch (TooManyRequestsException tre) {
305313
this.setEnabled(false);
306-
final String message = "Connections to Central search refused. Analysis failed.";
314+
final String message = "Connections to Central search refused. Analysis failed. Disabling Central analyzer - this " +
315+
"could lead to both false positives and false negatives.";
307316
LOGGER.error(message, tre);
308317
throw new AnalysisException(message, tre);
309318
} catch (IllegalArgumentException iae) {
310319
LOGGER.info("invalid sha1-hash on {}", dependency.getFileName());
311320
} catch (FileNotFoundException fnfe) {
312321
LOGGER.debug("Artifact not found in repository: '{}", dependency.getFileName());
313322
} catch (ForbiddenException e) {
323+
this.setEnabled(false);
314324
final String message = "Connection to Central search refused. This is most likely not a problem with " +
315325
"Dependency-Check itself and is related to network connectivity. Please check " +
316326
"https://central.sonatype.org/faq/403-error-central/.";
317327
LOGGER.error(message);
318328
throw new AnalysisException(message, e);
319329
} catch (IOException ioe) {
320-
final String message = "Could not connect to Central search. Analysis failed.";
330+
this.setEnabled(false);
331+
final String message = "Could not connect to Central search. Analysis failed; disabling Central analyzer - this " +
332+
"could lead to both false positives and false negatives.";
321333
LOGGER.error(message, ioe);
322334
throw new AnalysisException(message, ioe);
323335
}

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)