Skip to content

Commit fb89d58

Browse files
authored
Merge pull request #6262 from thc202/spider/max-size-zero
spider: handle zero as unlimited parse size
2 parents 79408e9 + d0c6745 commit fb89d58

File tree

7 files changed

+50
-10
lines changed

7 files changed

+50
-10
lines changed

addOns/spider/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77
## Unreleased
88
### Changed
99
- Maintenance changes.
10+
- Handle zero max parse size as unlimited.
1011

1112
## [0.13.0] - 2025-01-10
1213
### Changed

addOns/spider/src/main/java/org/zaproxy/addon/spider/SpiderParam.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,8 @@ protected void parseImpl() {
355355

356356
this.acceptCookies = getBoolean(SPIDER_ACCEPT_COOKIES, true);
357357

358-
this.maxParseSizeBytes = getInt(SPIDER_MAX_PARSE_SIZE_BYTES, DEFAULT_MAX_PARSE_SIZE_BYTES);
358+
this.maxParseSizeBytes =
359+
Math.max(0, getInt(SPIDER_MAX_PARSE_SIZE_BYTES, DEFAULT_MAX_PARSE_SIZE_BYTES));
359360

360361
loadIrrelevantParameters();
361362
this.confirmRemoveIrrelevantParameter =
@@ -1021,14 +1022,14 @@ public boolean isAcceptCookies() {
10211022
/**
10221023
* Sets the maximum size, in bytes, that a response might have to be parsed.
10231024
*
1024-
* <p>This allows the spider to skip big responses/files.
1025+
* <p>This allows the spider to skip big responses/files. 0 for no limit.
10251026
*
10261027
* @param maxParseSizeBytes the maximum size, in bytes, that a response might have to be parsed.
10271028
* @see #getMaxParseSizeBytes()
10281029
*/
10291030
public void setMaxParseSizeBytes(int maxParseSizeBytes) {
1030-
this.maxParseSizeBytes = maxParseSizeBytes;
1031-
getConfig().setProperty(SPIDER_MAX_PARSE_SIZE_BYTES, maxParseSizeBytes);
1031+
this.maxParseSizeBytes = Math.max(0, maxParseSizeBytes);
1032+
getConfig().setProperty(SPIDER_MAX_PARSE_SIZE_BYTES, this.maxParseSizeBytes);
10321033
}
10331034

10341035
/**

addOns/spider/src/main/java/org/zaproxy/addon/spider/filters/DefaultParseFilter.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,8 @@ public FilterResult filtered(HttpMessage responseMessage) {
117117
}
118118

119119
// Check response body size
120-
if (responseMessage.getResponseBody().length() > params.getMaxParseSizeBytes()) {
120+
if (params.getMaxParseSizeBytes() != 0
121+
&& responseMessage.getResponseBody().length() > params.getMaxParseSizeBytes()) {
121122
getLogger()
122123
.debug("Resource too large: {}", responseMessage.getRequestHeader().getURI());
123124
return filterResultMaxSize;

addOns/spider/src/main/javahelp/org/zaproxy/addon/spider/resources/help/contents/options.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ <h3>Maximum children to crawl</h3>
4343

4444
<h3>Maximum parse size</h3>
4545
Defines the maximum size, in bytes, that a response might have to be parsed. This allows
46-
the Spider to skip big responses/files.
46+
the Spider to skip big responses/files. Zero means unlimited size.
4747

4848
<h3>Domains Always in Scope</h3>
4949
Allows to manage the domains, string literals or regular expressions, that are in the

addOns/spider/src/main/resources/org/zaproxy/addon/spider/resources/Messages.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ spider.api.action.setOptionMaxDepth.param.Integer =
5454
spider.api.action.setOptionMaxDuration =
5555
spider.api.action.setOptionMaxDuration.param.Integer =
5656
spider.api.action.setOptionMaxParseSizeBytes = Sets the maximum size, in bytes, that a response might have to be parsed. This allows the spider to skip big responses/files.
57-
spider.api.action.setOptionMaxParseSizeBytes.param.Integer =
57+
spider.api.action.setOptionMaxParseSizeBytes.param.Integer = The maximum size or 0 for unlimited.
5858
spider.api.action.setOptionMaxScansInUI =
5959
spider.api.action.setOptionMaxScansInUI.param.Integer =
6060
spider.api.action.setOptionParseComments =
@@ -102,7 +102,7 @@ spider.api.view.optionHandleParameters =
102102
spider.api.view.optionMaxChildren = Gets the maximum number of child nodes (per node) that can be crawled, 0 means no limit.
103103
spider.api.view.optionMaxDepth = Gets the maximum depth the spider can crawl, 0 if unlimited.
104104
spider.api.view.optionMaxDuration =
105-
spider.api.view.optionMaxParseSizeBytes = Gets the maximum size, in bytes, that a response might have to be parsed.
105+
spider.api.view.optionMaxParseSizeBytes = Gets the maximum size, in bytes, that a response might have to be parsed, or 0 for unlimited.
106106
spider.api.view.optionMaxScansInUI =
107107
spider.api.view.optionParseComments =
108108
spider.api.view.optionParseGit =
@@ -172,7 +172,7 @@ spider.custom.label.handleOdata = Handle OData Parameters:
172172
spider.custom.label.maxChildren = Maximum Children to Crawl (0 is unlimited):
173173
spider.custom.label.maxDepth = Maximum Depth to Crawl (0 is unlimited):
174174
spider.custom.label.maxDuration = Maximum Duration (minutes; 0 is unlimited):
175-
spider.custom.label.maxParseSizeBytes = Maximum Parse Size (bytes):
175+
spider.custom.label.maxParseSizeBytes = Maximum Parse Size (bytes; 0 is unlimited):
176176
spider.custom.label.parseComments = Parse HTML Comments:
177177
spider.custom.label.parseDsStore = Parse .DS_Store Files:
178178
spider.custom.label.parseGit = Parse Git Metadata:
@@ -245,7 +245,7 @@ spider.options.label.handlehodataparameters = Handle OData-specific parameters
245245
spider.options.label.handleparameters = Query parameters handling for checking visited URIs:
246246
spider.options.label.irrelevantparameters = Irrelevant parameters:
247247
spider.options.label.maxChildren = Maximum Children to Crawl (0 is unlimited):
248-
spider.options.label.maxParseSizeBytes = Maximum Parse Size (bytes):
248+
spider.options.label.maxParseSizeBytes = Maximum Parse Size (bytes; 0 is unlimited):
249249
spider.options.label.post = POST forms (recommended but may generate unwanted requests)
250250
spider.options.label.processform = Process forms (forms are processed and GET queries submitted)
251251
spider.options.label.robotstxt = Parse 'robots.txt' files for new URIs

addOns/spider/src/test/java/org/zaproxy/addon/spider/SpiderParamUnitTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.junit.jupiter.api.BeforeEach;
3232
import org.junit.jupiter.api.Test;
3333
import org.junit.jupiter.params.ParameterizedTest;
34+
import org.junit.jupiter.params.provider.CsvSource;
3435
import org.junit.jupiter.params.provider.ValueSource;
3536
import org.mockito.MockedStatic;
3637
import org.parosproxy.paros.Constant;
@@ -156,4 +157,27 @@ void shouldParseDsStorePerSetting(boolean enabled) {
156157
// Then
157158
assertThat(param.isParseDsStore(), is(equalTo(enabled)));
158159
}
160+
161+
@ParameterizedTest
162+
@CsvSource({"-10, 0", "-1, 0", "0, 0", "1, 1", "10, 10"})
163+
void shouldLoadConfigWithMaxParseSizeBytes(int value, int expected) {
164+
// Given
165+
String configKey = "spider.maxParseSizeBytes";
166+
configuration = new ZapXmlConfiguration();
167+
configuration.setProperty(configKey, value);
168+
// When
169+
param.load(configuration);
170+
// Then
171+
assertThat(param.getMaxParseSizeBytes(), is(equalTo(expected)));
172+
}
173+
174+
@ParameterizedTest
175+
@CsvSource({"-10, 0", "-1, 0", "0, 0", "1, 1", "10, 10"})
176+
void shouldSetAndPersistMaxParseSizeBytes(int value, int expected) {
177+
// Given / When
178+
param.setMaxParseSizeBytes(value);
179+
// Then
180+
assertThat(param.getMaxParseSizeBytes(), is(equalTo(expected)));
181+
assertThat(configuration.getInt("spider.maxParseSizeBytes"), is(equalTo(expected)));
182+
}
159183
}

addOns/spider/src/test/java/org/zaproxy/addon/spider/filters/DefaultParseFilterUnitTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,19 @@ void shouldNotFilterHttpMessageWithResponseUnderMaxParseSize() throws Exception
316316
assertThat(filterResult.isFiltered(), is(equalTo(false)));
317317
}
318318

319+
@Test
320+
void shouldNotFilterHttpMessageWithZeroMaxParseSize() throws Exception {
321+
// Given
322+
int maxParseSizeBytes = 0;
323+
DefaultParseFilter filter =
324+
new DefaultParseFilter(createSpiderParam(maxParseSizeBytes), resourceBundle);
325+
HttpMessage httpMessage = createHttpMessageWithResponseBody("ABC");
326+
// When
327+
FilterResult filterResult = filter.filtered(httpMessage);
328+
// Then
329+
assertThat(filterResult.isFiltered(), is(equalTo(false)));
330+
}
331+
319332
private DefaultParseFilter createDefaultParseFilter() {
320333
return new DefaultParseFilter(createSpiderParam(Integer.MAX_VALUE), resourceBundle);
321334
}

0 commit comments

Comments
 (0)