Skip to content

Commit a36d432

Browse files
committed
pscan: add max body size to the API
Allow to configure the option max body size through the API. Fix zaproxy/zaproxy#8974. Signed-off-by: thc202 <[email protected]>
1 parent b573d71 commit a36d432

File tree

5 files changed

+31
-3
lines changed

5 files changed

+31
-3
lines changed

addOns/pscan/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

77
## Unreleased
8-
8+
### Added
9+
- Allow to configure the option max body size through the API (Issue 8974).
910

1011
## [0.3.0] - 2025-06-20
1112
### Changed

addOns/pscan/src/main/java/org/zaproxy/addon/pscan/PassiveScanApi.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ public class PassiveScanApi extends ApiImplementor {
5353
private static final String VIEW_CURRENT_RULE = "currentRule";
5454
private static final String VIEW_CURRENT_TASKS = "currentTasks";
5555
private static final String VIEW_MAX_ALERTS_PER_RULE = "maxAlertsPerRule";
56+
private static final String VIEW_MAX_BODY_SIZE_IN_BYTES = "maxBodySizeInBytes";
5657

5758
private static final String ACTION_SET_ENABLED = "setEnabled";
5859
private static final String ACTION_SET_SCAN_ONLY_IN_SCOPE = "setScanOnlyInScope";
@@ -62,6 +63,7 @@ public class PassiveScanApi extends ApiImplementor {
6263
private static final String ACTION_DISABLE_SCANNERS = "disableScanners";
6364
private static final String ACTION_SET_SCANNER_ALERT_THRESHOLD = "setScannerAlertThreshold";
6465
private static final String ACTION_SET_MAX_ALERTS_PER_RULE = "setMaxAlertsPerRule";
66+
private static final String ACTION_SET_MAX_BODY_SIZE_IN_BYTES = "setMaxBodySizeInBytes";
6567
private static final String ACTION_DISABLE_ALL_TAGS = "disableAllTags";
6668
private static final String ACTION_ENABLE_ALL_TAGS = "enableAllTags";
6769
private static final String ACTION_CLEAR_QUEUE = "clearQueue";
@@ -72,6 +74,7 @@ public class PassiveScanApi extends ApiImplementor {
7274
private static final String PARAM_ID = "id";
7375
private static final String PARAM_ALERT_THRESHOLD = "alertThreshold";
7476
private static final String PARAM_MAX_ALERTS = "maxAlerts";
77+
private static final String PARAM_MAX_SIZE = "maxSize";
7578

7679
private final ExtensionPassiveScan2 extension;
7780
private final PassiveScannersManager scannersManager;
@@ -97,6 +100,8 @@ public PassiveScanApi(ExtensionPassiveScan2 extension, PassiveScannersManager sc
97100
new String[] {PARAM_ID, PARAM_ALERT_THRESHOLD}));
98101
this.addApiAction(
99102
new ApiAction(ACTION_SET_MAX_ALERTS_PER_RULE, new String[] {PARAM_MAX_ALERTS}));
103+
this.addApiAction(
104+
new ApiAction(ACTION_SET_MAX_BODY_SIZE_IN_BYTES, new String[] {PARAM_MAX_SIZE}));
100105
this.addApiAction(new ApiAction(ACTION_DISABLE_ALL_TAGS));
101106
this.addApiAction(new ApiAction(ACTION_ENABLE_ALL_TAGS));
102107
this.addApiAction(new ApiAction(ACTION_CLEAR_QUEUE));
@@ -113,6 +118,7 @@ public PassiveScanApi(ExtensionPassiveScan2 extension, PassiveScannersManager sc
113118
this.addApiView(currentRule);
114119
this.addApiView(new ApiView(VIEW_CURRENT_TASKS));
115120
this.addApiView(new ApiView(VIEW_MAX_ALERTS_PER_RULE));
121+
this.addApiView(new ApiView(VIEW_MAX_BODY_SIZE_IN_BYTES));
116122
}
117123

118124
@Override
@@ -162,6 +168,11 @@ public ApiResponse handleApiAction(String name, JSONObject params) throws ApiExc
162168
case ACTION_SET_MAX_ALERTS_PER_RULE:
163169
getOptions().setMaxAlertsPerRule(ApiUtils.getIntParam(params, PARAM_MAX_ALERTS));
164170
break;
171+
case ACTION_SET_MAX_BODY_SIZE_IN_BYTES:
172+
getOptions()
173+
.setMaxBodySizeInBytesToScan(
174+
Math.max(0, ApiUtils.getIntParam(params, PARAM_MAX_SIZE)));
175+
break;
165176
case ACTION_DISABLE_ALL_TAGS:
166177
getOptions()
167178
.getAutoTagScanners()
@@ -325,6 +336,12 @@ public ApiResponse handleApiView(String name, JSONObject params) throws ApiExcep
325336
VIEW_MAX_ALERTS_PER_RULE,
326337
Integer.toString(getOptions().getMaxAlertsPerRule()));
327338
break;
339+
case VIEW_MAX_BODY_SIZE_IN_BYTES:
340+
result =
341+
new ApiResponseElement(
342+
VIEW_MAX_BODY_SIZE_IN_BYTES,
343+
Integer.toString(getOptions().getMaxBodySizeInBytesToScan()));
344+
break;
328345
default:
329346
throw new ApiException(ApiException.Type.BAD_VIEW);
330347
}

addOns/pscan/src/main/javahelp/org/zaproxy/addon/pscan/help/contents/api.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ <h3>Actions</h3>
4949
<li>maxAlerts: The maximum number of alerts.</li>
5050
</ul>
5151
</li>
52+
<li>
53+
setMaxBodySizeInBytes (maxSize*): Sets the maximum body size in bytes that the passive scanner will scan.
54+
<ul>
55+
<li>maxSize: The maximum size in bytes, 0 to unset.</li>
56+
</ul>
57+
</li>
5258
<li>
5359
setScanOnlyInScope (onlyInScope*): Sets whether or not the passive scan should be performed only on messages that are in scope.
5460
<ul>
@@ -68,6 +74,7 @@ <h3>Views</h3>
6874
<ul>
6975
<li>currentTasks: Shows information about the passive scan tasks currently being run (if any).</li>
7076
<li>maxAlertsPerRule: Gets the maximum number of alerts a passive scan rule should raise.</li>
77+
<li>maxBodySizeInBytes: Gets the maximum body size in bytes that the passive scanner will scan.</li>
7178
<li>recordsToScan: The number of records the passive scanner still has to scan.</li>
7279
<li>scanOnlyInScope: Tells whether or not the passive scan should be performed only on messages that are in scope.</li>
7380
<li>scanners: Lists all passive scan rules with their ID, name, enabled state, and alert threshold.</li>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ pscan.api.action.setEnabled = Sets whether or not the passive scanning is enable
1111
pscan.api.action.setEnabled.param.enabled = The enabled state, true or false.
1212
pscan.api.action.setMaxAlertsPerRule = Sets the maximum number of alerts a passive scan rule can raise.
1313
pscan.api.action.setMaxAlertsPerRule.param.maxAlerts = The maximum number of alerts.
14+
pscan.api.action.setMaxBodySizeInBytes = Sets the maximum body size in bytes that the passive scanner will scan.
15+
pscan.api.action.setMaxBodySizeInBytes.param.maxSize = The maximum size in bytes, 0 to unset.
1416
pscan.api.action.setScanOnlyInScope = Sets whether or not the passive scan should be performed only on messages that are in scope.
1517
pscan.api.action.setScanOnlyInScope.param.onlyInScope = The scan state, true or false.
1618
pscan.api.action.setScannerAlertThreshold = Sets the alert threshold of a passive scan rule.
@@ -21,6 +23,7 @@ pscan.api.view.currentRule = Shows information about the passive scan rule curre
2123
pscan.api.view.currentRule.deprecated = Use the currentTasks view instead.
2224
pscan.api.view.currentTasks = Shows information about the passive scan tasks currently being run (if any).
2325
pscan.api.view.maxAlertsPerRule = Gets the maximum number of alerts a passive scan rule should raise.
26+
pscan.api.view.maxBodySizeInBytes = Gets the maximum body size in bytes that the passive scanner will scan.
2427
pscan.api.view.recordsToScan = The number of records the passive scanner still has to scan.
2528
pscan.api.view.scanOnlyInScope = Tells whether or not the passive scan should be performed only on messages that are in scope.
2629
pscan.api.view.scanners = Lists all passive scan rules with their ID, name, enabled state, and alert threshold.

addOns/pscan/src/test/java/org/zaproxy/addon/pscan/PassiveScanApiUnitTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ void shouldAddApiElements() {
7979
// Given / When
8080
pscanApi = new PassiveScanApi(extension, scannersManager);
8181
// Then
82-
assertThat(pscanApi.getApiActions(), hasSize(11));
83-
assertThat(pscanApi.getApiViews(), hasSize(6));
82+
assertThat(pscanApi.getApiActions(), hasSize(12));
83+
assertThat(pscanApi.getApiViews(), hasSize(7));
8484
assertThat(pscanApi.getApiOthers(), hasSize(0));
8585
}
8686

0 commit comments

Comments
 (0)