Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit ffbc6d8

Browse files
authored
feat: Enable configuration of a lower resultsPerPage on NVD API (#6843)
1 parent ed0e8cb commit ffbc6d8

File tree

13 files changed

+66
-1
lines changed

13 files changed

+66
-1
lines changed

ant/src/main/java/org/owasp/dependencycheck/taskdefs/Update.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,11 @@ public class Update extends Purge {
7070
*/
7171
private int nvdApiDelay = 0;
7272

73+
/**
74+
* The number of records per page of NVD API data.
75+
*/
76+
private Integer nvdApiResultsPerPage;
77+
7378
/**
7479
* The Proxy Server.
7580
*/
@@ -287,6 +292,24 @@ public void setNvdApiDelay(int nvdApiDelay) {
287292
this.nvdApiDelay = nvdApiDelay;
288293
}
289294

295+
/**
296+
* Get the value of nvdApiResultsPerPage.
297+
*
298+
* @return the value of nvdApiResultsPerPage
299+
*/
300+
public int getNvdApiResultsPerPage() {
301+
return nvdApiResultsPerPage;
302+
}
303+
304+
/**
305+
* Set the value of nvdApiResultsPerPage.
306+
*
307+
* @param nvdApiResultsPerPage new value of nvdApiResultsPerPage
308+
*/
309+
public void setApiResultsPerPage(int nvdApiResultsPerPage) {
310+
this.nvdApiResultsPerPage = nvdApiResultsPerPage;
311+
}
312+
290313
/**
291314
* Get the value of proxyServer.
292315
*
@@ -620,6 +643,7 @@ protected void populateSettings() throws BuildException {
620643
getSettings().setStringIfNotEmpty(Settings.KEYS.NVD_API_KEY, nvdApiKey);
621644
getSettings().setStringIfNotEmpty(Settings.KEYS.NVD_API_ENDPOINT, nvdApiEndpoint);
622645
getSettings().setIntIfNotNull(Settings.KEYS.NVD_API_DELAY, nvdApiDelay);
646+
getSettings().setIntIfNotNull(Settings.KEYS.NVD_API_RESULTS_PER_PAGE, nvdApiResultsPerPage);
623647
getSettings().setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_URL, nvdDatafeedUrl);
624648
getSettings().setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_USER, nvdUser);
625649
getSettings().setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_PASSWORD, nvdPassword);

ant/src/site/markdown/config-update.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ nvdApiKey | The API Key to access the NVD API; obtained from https://
3838
nvdApiEndpoint | The NVD API endpoint URL; setting this is uncommon. | https://services.nvd.nist.gov/rest/json/cves/2.0
3939
nvdMaxRetryCount | The maximum number of retry requests for a single call to the NVD API. | 10
4040
nvdApiDelay | The number of milliseconds to wait between calls to the NVD API. | 3500 with an NVD API Key or 8000 without an API Key
41+
nvdApiResultsPerPage | The number records for a single page from NVD API (must be <=2000). | 2000
4142
nvdDatafeedUrl | The URL for the NVD API Data feed that can be generated using https://github.com/jeremylong/Open-Vulnerability-Project/tree/main/vulnz#caching-the-nvd-cve-data - example value `https://internal.server/cache/nvdcve-{0}.json.gz` | &nbsp;
4243
nvdUser | Credentials used for basic authentication for the NVD API Data feed. | &nbsp;
4344
nvdPassword | Credentials used for basic authentication for the NVD API Data feed. | &nbsp;

ant/src/site/markdown/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ nvdApiKey | The API Key to access the NVD API; obtained from https://
148148
nvdApiEndpoint | The NVD API endpoint URL; setting this is uncommon. | https://services.nvd.nist.gov/rest/json/cves/2.0
149149
nvdMaxRetryCount | The maximum number of retry requests for a single call to the NVD API. | 10
150150
nvdApiDelay | The number of milliseconds to wait between calls to the NVD API. | 3500 with an NVD API Key or 8000 without an API Key
151+
nvdApiResultsPerPage | The number records for a single page from NVD API (must be <=2000). | 2000
151152
nvdDatafeedUrl | The URL for the NVD API Data feed that can be generated using https://github.com/jeremylong/Open-Vulnerability-Project/tree/main/vulnz#caching-the-nvd-cve-data - example value `https://internal.server/cache/nvdcve-{0}.json.gz` | &nbsp;
152153
nvdUser | Credentials used for basic authentication for the NVD API Data feed. | &nbsp;
153154
nvdPassword | Credentials used for basic authentication for the NVD API Data feed. | &nbsp;

cli/src/main/java/org/owasp/dependencycheck/App.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,7 @@ protected void populateSettings(CliParser cli) throws InvalidSettingException {
661661
settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_ENDPOINT,
662662
cli.getStringArgument(CliParser.ARGUMENT.NVD_API_ENDPOINT));
663663
settings.setIntIfNotNull(Settings.KEYS.NVD_API_DELAY, cli.getIntegerValue(CliParser.ARGUMENT.NVD_API_DELAY));
664+
settings.setIntIfNotNull(Settings.KEYS.NVD_API_RESULTS_PER_PAGE, cli.getIntegerValue(CliParser.ARGUMENT.NVD_API_RESULTS_PER_PAGE));
664665
settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_URL, cli.getStringArgument(CliParser.ARGUMENT.NVD_API_DATAFEED_URL));
665666
settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_USER, cli.getStringArgument(CliParser.ARGUMENT.NVD_API_DATAFEED_USER));
666667
settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_PASSWORD, cli.getStringArgument(CliParser.ARGUMENT.NVD_API_DATAFEED_PASSWORD));

cli/src/main/java/org/owasp/dependencycheck/CliParser.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,17 @@ private void validateArgs() throws FileNotFoundException, ParseException {
148148
throw new ParseException("Invalid Setting: nvdApiDelay must be a number greater than or equal to 0.");
149149
}
150150
}
151+
value = line.getOptionValue(ARGUMENT.NVD_API_RESULTS_PER_PAGE);
152+
if (value != null) {
153+
try {
154+
final int i = Integer.parseInt(value);
155+
if (i <= 0 || i > 2000) {
156+
throw new ParseException("Invalid Setting: nvdApiResultsPerPage must be a number in the range [1, 2000].");
157+
}
158+
} catch (NumberFormatException ex) {
159+
throw new ParseException("Invalid Setting: nvdApiResultsPerPage must be a number in the range [1, 2000].");
160+
}
161+
}
151162
}
152163
if (isRunScan()) {
153164
validatePathExists(getScanFiles(), ARGUMENT.SCAN);
@@ -353,6 +364,8 @@ private void addAdvancedOptions(final Options options) {
353364
"Only update the local NVD data cache; no scan will be executed."))
354365
.addOption(newOptionWithArg(ARGUMENT.NVD_API_DELAY, "milliseconds",
355366
"Time in milliseconds to wait between downloading from the NVD."))
367+
.addOption(newOptionWithArg(ARGUMENT.NVD_API_RESULTS_PER_PAGE, "count",
368+
"The number records for a single page from NVD API (must be <=2000)."))
356369
.addOption(newOptionWithArg(ARGUMENT.NVD_API_ENDPOINT, "endpoint",
357370
"The NVD API Endpoint - setting this is rare."))
358371
.addOption(newOptionWithArg(ARGUMENT.NVD_API_DATAFEED_URL, "url",
@@ -1163,6 +1176,10 @@ public static class ARGUMENT {
11631176
* The time in milliseconds to wait between downloading NVD API data.
11641177
*/
11651178
public static final String NVD_API_DELAY = "nvdApiDelay";
1179+
/**
1180+
* The number records for a single page from NVD API.
1181+
*/
1182+
public static final String NVD_API_RESULTS_PER_PAGE = "nvdApiResultsPerPage";
11661183
/**
11671184
* The short CLI argument name for setting the location of the data
11681185
* directory.

cli/src/site/markdown/arguments.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ Advanced Options
3131
| | \-\-nvdApiEndpoint | \<endpoint\> | The NVD API endpoint URL; setting this is uncommon. | https://services.nvd.nist.gov/rest/json/cves/2.0 |
3232
| | \-\-nvdMaxRetryCount | \<count\> | The maximum number of retry requests for a single call to the NVD API. | 10 |
3333
| | \-\-nvdApiDelay | \<milliseconds\>| The number of milliseconds to wait between calls to the NVD API. | 3500 with an NVD API Key or 8000 without an API Key |
34+
| | \-\-nvdApiResultsPerPage | \<number\> | The number records for a single page from NVD API (must be <=2000). | 2000 |
3435
| | \-\-nvdDatafeed | \<url\> | The URL for the NVD API Data feed that can be generated using https://github.com/jeremylong/Open-Vulnerability-Project/tree/main/vulnz#caching-the-nvd-cve-data - example value `https://internal.server/cache/nvdcve-{0}.json.gz` | &nbsp; |
3536
| | \-\-nvdUser | \<username\> | Credentials used for basic authentication for the NVD API Data feed. | &nbsp; |
3637
| | \-\-nvdPassword | \<password\> | Credentials used for basic authentication for the NVD API Data feed. | &nbsp; |

core/src/main/java/org/owasp/dependencycheck/data/update/NvdApiDataSource.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,10 @@ private boolean processApi() throws UpdateException {
319319
+ "an NVD API key as the update can take a VERY long time without an API Key");
320320
builder.withDelay(10000);
321321
}
322-
builder.withResultsPerPage(RESULTS_PER_PAGE);
322+
323+
final int resultsPerPage = Math.min(settings.getInt(Settings.KEYS.NVD_API_RESULTS_PER_PAGE, RESULTS_PER_PAGE), RESULTS_PER_PAGE);
324+
325+
builder.withResultsPerPage(resultsPerPage);
323326
//removed due to the virtualMatch filter causing overhead with the NVD API
324327
//final String virtualMatch = settings.getString(Settings.KEYS.CVE_CPE_STARTS_WITH_FILTER);
325328
//if (virtualMatch != null) {

maven/src/main/java/org/owasp/dependencycheck/maven/BaseDependencyCheckMojo.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -992,6 +992,13 @@ public abstract class BaseDependencyCheckMojo extends AbstractMojo implements Ma
992992
@Parameter(property = "nvdApiDelay")
993993
private Integer nvdApiDelay;
994994

995+
/**
996+
* The number records for a single page from NVD API (must be <=2000).
997+
*/
998+
@SuppressWarnings("CanBeFinal")
999+
@Parameter(property = "nvdApiResultsPerPage")
1000+
private Integer nvdApiResultsPerPage;
1001+
9951002
/**
9961003
* The path to dotnet core.
9971004
*/
@@ -2354,6 +2361,7 @@ protected void populateSettings() {
23542361
settings.setStringIfNotEmpty(Settings.KEYS.DB_FILE_NAME, dbFilename);
23552362
settings.setStringIfNotNull(Settings.KEYS.NVD_API_ENDPOINT, nvdApiEndpoint);
23562363
settings.setIntIfNotNull(Settings.KEYS.NVD_API_DELAY, nvdApiDelay);
2364+
settings.setIntIfNotNull(Settings.KEYS.NVD_API_RESULTS_PER_PAGE, nvdApiResultsPerPage);
23572365
settings.setStringIfNotEmpty(Settings.KEYS.NVD_API_DATAFEED_URL, nvdDatafeedUrl);
23582366
settings.setIntIfNotNull(Settings.KEYS.NVD_API_VALID_FOR_HOURS, nvdValidForHours);
23592367
settings.setIntIfNotNull(Settings.KEYS.NVD_API_MAX_RETRY_COUNT, nvdMaxRetryCount);

maven/src/site/markdown/configuration.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ nvdApiEndpoint | The NVD API endpoint URL; setting this is uncommon.
150150
nvdApiServerId | The id of a server defined in the settings.xml that configures the credentials (password is used as ApiKey) for accessing the NVD API. | &nbsp; |
151151
nvdMaxRetryCount | The maximum number of retry requests for a single call to the NVD API. | 10 |
152152
nvdApiDelay | The number of milliseconds to wait between calls to the NVD API. | 3500 with an NVD API Key or 8000 without an API Key . |
153+
nvdApiResultsPerPage | The number records for a single page from NVD API (must be <=2000). | 2000 |
153154
nvdDatafeedUrl | The URL for the NVD API Data feed that can be generated using https://github.com/jeremylong/Open-Vulnerability-Project/tree/main/vulnz#caching-the-nvd-cve-data - example value `https://internal.server/cache/nvdcve-{0}.json.gz` | &nbsp; |
154155
nvdDatafeedServerId | The id of a server defined in the settings.xml that configures the credentials (username and password) for accessing the NVD API Data feed.| &nbsp; |
155156
nvdUser | Credentials used for basic authentication for the NVD API Data feed. | &nbsp; |

src/site/markdown/dependency-check-gradle/configuration-aggregate.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ nvd | apiKey | The API Key to access the NVD API; obtained f
8888
nvd | endpoint | The NVD API endpoint URL; setting this is uncommon. | https://services.nvd.nist.gov/rest/json/cves/2.0 |
8989
nvd | maxRetryCount | The maximum number of retry requests for a single call to the NVD API. | 10 |
9090
nvd | delay | The number of milliseconds to wait between calls to the NVD API. | 3500 with an NVD API Key or 8000 without an API Key |
91+
nvd | resultsPerPage | The number records for a single page from NVD API (must be <=2000). | 2000 |
9192
nvd | datafeedUrl | The URL for the NVD API Data feed that can be generated using https://github.com/jeremylong/Open-Vulnerability-Project/tree/main/vulnz#caching-the-nvd-cve-data | &nbsp; |
9293
nvd | datafeedUser | Credentials used for basic authentication for the NVD API Data feed. | &nbsp; |
9394
nvd | datafeedPassword | Credentials used for basic authentication for the NVD API Data feed. | &nbsp; |

0 commit comments

Comments
 (0)