Skip to content

Commit 4f1675b

Browse files
authored
Merge pull request #114 from thc202/update-2.14
Update APIs of add-ons and core
2 parents 7546ec7 + b5df1ec commit 4f1675b

File tree

6 files changed

+283
-0
lines changed

6 files changed

+283
-0
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@ 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+
### Added
9+
- Add the APIs of the following add-on:
10+
- Custom Payloads version 0.13.0.
11+
812
### Changed
13+
- Update core APIs for 2.14.
14+
- Update the APIs of the following add-on:
15+
- Selenium version 15.16.0.
916
- Stop sending the API key as query parameter, not needed since ZAP 2.6.0.
1017
- Allow to call the ZAP API with custom HTTP method (e.g. file upload).
1118

subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/gen/Acsrf.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,16 @@ public ApiResponse setOptionPartialMatchingEnabled(boolean bool) throws ClientAp
6969

7070
/** Generate a form for testing lack of anti-CSRF tokens - typically invoked via ZAP */
7171
public byte[] genForm(String hrefid) throws ClientApiException {
72+
return genFormActionUrl(hrefid, null);
73+
}
74+
75+
/** Generate a form for testing lack of anti-CSRF tokens - typically invoked via ZAP */
76+
public byte[] genFormActionUrl(String hrefid, String actionurl) throws ClientApiException {
7277
Map<String, String> map = new HashMap<>();
7378
map.put("hrefId", hrefid);
79+
if (actionurl != null) {
80+
map.put("actionUrl", actionurl);
81+
}
7482
return api.callApiOther("acsrf", "other", "genForm", map);
7583
}
7684
}

subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/gen/Alert.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,16 @@ public ApiResponse alert(String id) throws ClientApiException {
5151
*/
5252
public ApiResponse alerts(String baseurl, String start, String count, String riskid)
5353
throws ClientApiException {
54+
return alerts(baseurl, start, count, riskid, null);
55+
}
56+
57+
/**
58+
* Gets the alerts raised by ZAP, optionally filtering by URL or riskId, and paginating with
59+
* 'start' position and 'count' of alerts
60+
*/
61+
public ApiResponse alerts(
62+
String baseurl, String start, String count, String riskid, String contextname)
63+
throws ClientApiException {
5464
Map<String, String> map = new HashMap<>();
5565
if (baseurl != null) {
5666
map.put("baseurl", baseurl);
@@ -64,6 +74,9 @@ public ApiResponse alerts(String baseurl, String start, String count, String ris
6474
if (riskid != null) {
6575
map.put("riskId", riskid);
6676
}
77+
if (contextname != null) {
78+
map.put("contextName", contextname);
79+
}
6780
return api.callApi("alert", "view", "alerts", map);
6881
}
6982

@@ -121,6 +134,25 @@ public ApiResponse deleteAllAlerts() throws ClientApiException {
121134
return api.callApi("alert", "action", "deleteAllAlerts", null);
122135
}
123136

137+
/**
138+
* Deletes all the alerts optionally filtered by URL which fall within the Context with the
139+
* provided name, risk, or base URL.
140+
*/
141+
public ApiResponse deleteAlerts(String contextname, String baseurl, String riskid)
142+
throws ClientApiException {
143+
Map<String, String> map = new HashMap<>();
144+
if (contextname != null) {
145+
map.put("contextName", contextname);
146+
}
147+
if (baseurl != null) {
148+
map.put("baseurl", baseurl);
149+
}
150+
if (riskid != null) {
151+
map.put("riskId", riskid);
152+
}
153+
return api.callApi("alert", "action", "deleteAlerts", map);
154+
}
155+
124156
/** Deletes the alert with the given ID. */
125157
public ApiResponse deleteAlert(String id) throws ClientApiException {
126158
Map<String, String> map = new HashMap<>();

subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/gen/Core.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,13 @@ public ApiResponse disableClientCertificate() throws ClientApiException {
672672
return api.callApi("core", "action", "disableClientCertificate", null);
673673
}
674674

675+
/** Create a zip file of the ZAP core and add-on SBOMs */
676+
public ApiResponse createSbomZip(String filepath) throws ClientApiException {
677+
Map<String, String> map = new HashMap<>();
678+
map.put("filePath", filepath);
679+
return api.callApi("core", "action", "createSbomZip", map);
680+
}
681+
675682
/**
676683
* Deletes all alerts of the current session.
677684
*
@@ -989,4 +996,22 @@ public byte[] sendHarRequest(String request, String followredirects) throws Clie
989996
}
990997
return api.callApiOther("core", "other", "sendHarRequest", map);
991998
}
999+
1000+
/** Download a file from the transfer directory */
1001+
public byte[] fileDownload(String filename) throws ClientApiException {
1002+
Map<String, String> map = new HashMap<>();
1003+
map.put("fileName", filename);
1004+
return api.callApiOther("core", "other", "fileDownload", map);
1005+
}
1006+
1007+
/**
1008+
* Upload a file to the transfer directory. Only POST requests accepted with encodings of
1009+
* "multipart/form-data" or "application/x-www-form-urlencoded".
1010+
*/
1011+
public byte[] fileUpload(String filename, String filecontents) throws ClientApiException {
1012+
Map<String, String> map = new HashMap<>();
1013+
map.put("fileName", filename);
1014+
map.put("fileContents", filecontents);
1015+
return api.callApiOther("POST", "core", "other", "fileUpload", map);
1016+
}
9921017
}
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
1+
/*
2+
* Zed Attack Proxy (ZAP) and its related class files.
3+
*
4+
* ZAP is an HTTP/HTTPS proxy for assessing web application security.
5+
*
6+
* Copyright 2023 The ZAP Development Team
7+
*
8+
* Licensed under the Apache License, Version 2.0 (the "License");
9+
* you may not use this file except in compliance with the License.
10+
* You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing, software
15+
* distributed under the License is distributed on an "AS IS" BASIS,
16+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17+
* See the License for the specific language governing permissions and
18+
* limitations under the License.
19+
*/
20+
package org.zaproxy.clientapi.gen;
21+
22+
import java.util.HashMap;
23+
import java.util.Map;
24+
import org.zaproxy.clientapi.core.ApiResponse;
25+
import org.zaproxy.clientapi.core.ClientApi;
26+
import org.zaproxy.clientapi.core.ClientApiException;
27+
28+
/** This file was automatically generated. */
29+
@SuppressWarnings("javadoc")
30+
public class Custompayloads {
31+
32+
private final ClientApi api;
33+
34+
public Custompayloads(ClientApi api) {
35+
this.api = api;
36+
}
37+
38+
/**
39+
* Lists all available categories.
40+
*
41+
* <p>This component is optional and therefore the API will only work if it is installed
42+
*/
43+
public ApiResponse customPayloadsCategories() throws ClientApiException {
44+
return api.callApi("custompayloads", "view", "customPayloadsCategories", null);
45+
}
46+
47+
/**
48+
* Lists all the payloads currently loaded (category, payload, enabled state). Optionally
49+
* filtered by category.
50+
*
51+
* <p>This component is optional and therefore the API will only work if it is installed
52+
*/
53+
public ApiResponse customPayloads(String category) throws ClientApiException {
54+
Map<String, String> map = new HashMap<>();
55+
if (category != null) {
56+
map.put("category", category);
57+
}
58+
return api.callApi("custompayloads", "view", "customPayloads", map);
59+
}
60+
61+
/**
62+
* Disables payloads for a given category.
63+
*
64+
* <p>This component is optional and therefore the API will only work if it is installed
65+
*/
66+
public ApiResponse disableCustomPayloads(String category) throws ClientApiException {
67+
Map<String, String> map = new HashMap<>();
68+
if (category != null) {
69+
map.put("category", category);
70+
}
71+
return api.callApi("custompayloads", "action", "disableCustomPayloads", map);
72+
}
73+
74+
/**
75+
* Enables payloads for a given category.
76+
*
77+
* <p>This component is optional and therefore the API will only work if it is installed
78+
*/
79+
public ApiResponse enableCustomPayloads(String category) throws ClientApiException {
80+
Map<String, String> map = new HashMap<>();
81+
if (category != null) {
82+
map.put("category", category);
83+
}
84+
return api.callApi("custompayloads", "action", "enableCustomPayloads", map);
85+
}
86+
87+
/**
88+
* Removes a payload.
89+
*
90+
* <p>This component is optional and therefore the API will only work if it is installed
91+
*/
92+
public ApiResponse removeCustomPayload(String category, String payload)
93+
throws ClientApiException {
94+
Map<String, String> map = new HashMap<>();
95+
map.put("category", category);
96+
if (payload != null) {
97+
map.put("payload", payload);
98+
}
99+
return api.callApi("custompayloads", "action", "removeCustomPayload", map);
100+
}
101+
102+
/**
103+
* Adds a new payload.
104+
*
105+
* <p>This component is optional and therefore the API will only work if it is installed
106+
*/
107+
public ApiResponse addCustomPayload(String category, String payload) throws ClientApiException {
108+
Map<String, String> map = new HashMap<>();
109+
map.put("category", category);
110+
if (payload != null) {
111+
map.put("payload", payload);
112+
}
113+
return api.callApi("custompayloads", "action", "addCustomPayload", map);
114+
}
115+
116+
/**
117+
* Enables a given payload.
118+
*
119+
* <p>This component is optional and therefore the API will only work if it is installed
120+
*/
121+
public ApiResponse enableCustomPayload(String category, String payload)
122+
throws ClientApiException {
123+
Map<String, String> map = new HashMap<>();
124+
map.put("category", category);
125+
if (payload != null) {
126+
map.put("payload", payload);
127+
}
128+
return api.callApi("custompayloads", "action", "enableCustomPayload", map);
129+
}
130+
131+
/**
132+
* Disables a given payload.
133+
*
134+
* <p>This component is optional and therefore the API will only work if it is installed
135+
*/
136+
public ApiResponse disableCustomPayload(String category, String payload)
137+
throws ClientApiException {
138+
Map<String, String> map = new HashMap<>();
139+
map.put("category", category);
140+
if (payload != null) {
141+
map.put("payload", payload);
142+
}
143+
return api.callApi("custompayloads", "action", "disableCustomPayload", map);
144+
}
145+
}

subprojects/zap-clientapi/src/main/java/org/zaproxy/clientapi/gen/Selenium.java

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ public ApiResponse optionFirefoxBinaryPath() throws ClientApiException {
6868
return api.callApi("selenium", "view", "optionFirefoxBinaryPath", null);
6969
}
7070

71+
/** This component is optional and therefore the API will only work if it is installed */
72+
public ApiResponse optionFirefoxDefaultProfile() throws ClientApiException {
73+
return api.callApi("selenium", "view", "optionFirefoxDefaultProfile", null);
74+
}
75+
7176
/**
7277
* Returns the current path to Firefox driver (geckodriver)
7378
*
@@ -94,6 +99,17 @@ public ApiResponse optionPhantomJsBinaryPath() throws ClientApiException {
9499
return api.callApi("selenium", "view", "optionPhantomJsBinaryPath", null);
95100
}
96101

102+
/**
103+
* Gets the browser arguments.
104+
*
105+
* <p>This component is optional and therefore the API will only work if it is installed
106+
*/
107+
public ApiResponse getBrowserArguments(String browser) throws ClientApiException {
108+
Map<String, String> map = new HashMap<>();
109+
map.put("browser", browser);
110+
return api.callApi("selenium", "view", "getBrowserArguments", map);
111+
}
112+
97113
/**
98114
* Sets the current path to Chrome binary
99115
*
@@ -127,6 +143,13 @@ public ApiResponse setOptionFirefoxBinaryPath(String string) throws ClientApiExc
127143
return api.callApi("selenium", "action", "setOptionFirefoxBinaryPath", map);
128144
}
129145

146+
/** This component is optional and therefore the API will only work if it is installed */
147+
public ApiResponse setOptionFirefoxDefaultProfile(String string) throws ClientApiException {
148+
Map<String, String> map = new HashMap<>();
149+
map.put("String", string);
150+
return api.callApi("selenium", "action", "setOptionFirefoxDefaultProfile", map);
151+
}
152+
130153
/**
131154
* Sets the current path to Firefox driver (geckodriver)
132155
*
@@ -160,4 +183,47 @@ public ApiResponse setOptionPhantomJsBinaryPath(String string) throws ClientApiE
160183
map.put("String", string);
161184
return api.callApi("selenium", "action", "setOptionPhantomJsBinaryPath", map);
162185
}
186+
187+
/**
188+
* Adds a browser argument.
189+
*
190+
* <p>This component is optional and therefore the API will only work if it is installed
191+
*/
192+
public ApiResponse addBrowserArgument(String browser, String argument, String enabled)
193+
throws ClientApiException {
194+
Map<String, String> map = new HashMap<>();
195+
map.put("browser", browser);
196+
map.put("argument", argument);
197+
if (enabled != null) {
198+
map.put("enabled", enabled);
199+
}
200+
return api.callApi("selenium", "action", "addBrowserArgument", map);
201+
}
202+
203+
/**
204+
* Removes a browser argument.
205+
*
206+
* <p>This component is optional and therefore the API will only work if it is installed
207+
*/
208+
public ApiResponse removeBrowserArgument(String browser, String argument)
209+
throws ClientApiException {
210+
Map<String, String> map = new HashMap<>();
211+
map.put("browser", browser);
212+
map.put("argument", argument);
213+
return api.callApi("selenium", "action", "removeBrowserArgument", map);
214+
}
215+
216+
/**
217+
* Sets whether or not a browser argument is enabled.
218+
*
219+
* <p>This component is optional and therefore the API will only work if it is installed
220+
*/
221+
public ApiResponse setBrowserArgumentEnabled(String browser, String argument, String enabled)
222+
throws ClientApiException {
223+
Map<String, String> map = new HashMap<>();
224+
map.put("browser", browser);
225+
map.put("argument", argument);
226+
map.put("enabled", enabled);
227+
return api.callApi("selenium", "action", "setBrowserArgumentEnabled", map);
228+
}
163229
}

0 commit comments

Comments
 (0)