Skip to content

Commit 6992ece

Browse files
committed
scan rules: Clean code tweaks
- Add static modifier where applicable - Remove boiler plate or useless comments/JavaDoc attributes. - CHANGELOG > Add maintenance note (if there wasn't already one present). - pscanrules > Made resource message methods private again where example alerts have been implemented. Signed-off-by: kingthorin <[email protected]>
1 parent 9ab7743 commit 6992ece

File tree

151 files changed

+355
-691
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

151 files changed

+355
-691
lines changed

addOns/ascanrules/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
99
- The following rules now includes example alert functionality for documentation generation purposes (Issue 6119), as well as now including Alert Tags (OWASP Top 10, WSTG, and updated CWE):
1010
- Server Side Template Injection
1111
- Server Side Template Injection (Blind)
12+
- Maintenance changes.
1213

1314
### Fixed
1415
- False positives in the Path Traversal rule.

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/BufferOverflowScanRule.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public String getOther() {
101101
public void scan(HttpMessage msg, String param, String value) {
102102

103103
if (this.isStop()) { // Check if the user stopped things
104-
LOGGER.debug("Scanner {} Stopping.", this.getName());
104+
LOGGER.debug("Stopping scan rule \"{}\".", this.getName());
105105
return; // Stop!
106106
}
107107
if (isPage500(getBaseMsg())) // Check to see if the page closed initially
@@ -159,17 +159,15 @@ public Map<String, String> getAlertTags() {
159159

160160
@Override
161161
public int getCweId() {
162-
// The CWE id
163162
return 120;
164163
}
165164

166165
@Override
167166
public int getWascId() {
168-
// The WASC ID
169167
return 7;
170168
}
171169

172-
private String randomCharacterString(int length) {
170+
private static String randomCharacterString(int length) {
173171
StringBuilder sb1 = new StringBuilder(length + 1);
174172
int counter = 0;
175173
int character = 0;

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/CodeInjectionScanRule.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,6 @@ public void init() {
155155
@Override
156156
public void scan(HttpMessage msg, String paramName, String value) {
157157

158-
// Begin scan rule execution
159158
LOGGER.debug(
160159
"Checking [{}][{}], parameter [{}] for Dynamic Code Injection Vulnerabilities",
161160
msg.getRequestHeader().getMethod(),

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/CommandInjectionScanRule.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,6 @@ public class CommandInjectionScanRule extends AbstractAppParamPlugin
282282
NIX_BLIND_OS_PAYLOADS.add("|" + insertedCMD + "#");
283283
}
284284

285-
// Logger instance
286285
private static final Logger LOGGER = LogManager.getLogger(CommandInjectionScanRule.class);
287286

288287
// Get WASC Vulnerability description
@@ -366,7 +365,7 @@ public int getRisk() {
366365
return Alert.RISK_HIGH;
367366
}
368367

369-
private String getOtherInfo(TestType testType, String testValue) {
368+
private static String getOtherInfo(TestType testType, String testValue) {
370369
return Constant.messages.getString(
371370
MESSAGE_PREFIX + "otherinfo." + testType.getNameKey(), testValue);
372371
}
@@ -405,7 +404,6 @@ int getTimeSleep() {
405404
@Override
406405
public void scan(HttpMessage msg, String paramName, String value) {
407406

408-
// Begin scan rule execution
409407
LOGGER.debug(
410408
"Checking [{}][{}], parameter [{}] for OS Command Injection Vulnerabilities",
411409
msg.getRequestHeader().getMethod(),

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/DirectoryBrowsingScanRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ public String getReference() {
9595
return Constant.messages.getString(MESSAGE_PREFIX + "refs");
9696
}
9797

98-
private void checkIfDirectory(HttpMessage msg) throws URIException {
98+
private static void checkIfDirectory(HttpMessage msg) throws URIException {
9999

100100
URI uri = msg.getRequestHeader().getURI();
101101
uri.setQuery(null);

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/ExternalRedirectScanRule.java

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -147,13 +147,6 @@ public String getReference() {
147147
return VULN.getReferencesAsString();
148148
}
149149

150-
/**
151-
* Scan for External Redirect vulnerabilities
152-
*
153-
* @param msg a request only copy of the original message (the response isn't copied)
154-
* @param param the parameter name that need to be exploited
155-
* @param value the original parameter value
156-
*/
157150
@Override
158151
public void scan(HttpMessage msg, String param, String value) {
159152

@@ -342,7 +335,7 @@ private static boolean isRedirectHost(String value, boolean escaped) throws URIE
342335
* @param msg the current message where reflected redirection should be check into
343336
* @return get back the redirection type if exists
344337
*/
345-
private int isRedirected(String payload, HttpMessage msg) {
338+
private static int isRedirected(String payload, HttpMessage msg) {
346339

347340
// (1) Check if redirection by "Location" header
348341
// http://en.wikipedia.org/wiki/HTTP_location
@@ -471,7 +464,7 @@ private static boolean isRedirectPresent(Pattern pattern, String value) {
471464
* @param type the redirection type
472465
* @return a string representing the reason of this redirection
473466
*/
474-
private String getRedirectionReason(int type) {
467+
private static String getRedirectionReason(int type) {
475468
switch (type) {
476469
case REDIRECT_LOCATION_HEADER:
477470
return Constant.messages.getString(MESSAGE_PREFIX + "reason.location.header");
@@ -493,11 +486,6 @@ private String getRedirectionReason(int type) {
493486
}
494487
}
495488

496-
/**
497-
* Give back the risk associated to this vulnerability (high)
498-
*
499-
* @return the risk according to the Alert enum
500-
*/
501489
@Override
502490
public int getRisk() {
503491
return Alert.RISK_HIGH;
@@ -508,24 +496,14 @@ public Map<String, String> getAlertTags() {
508496
return ALERT_TAGS;
509497
}
510498

511-
/**
512-
* http://cwe.mitre.org/data/definitions/601.html
513-
*
514-
* @return the official CWE id
515-
*/
516499
@Override
517500
public int getCweId() {
518-
return 601;
501+
return 601; // CWE-601: URL Redirection to Untrusted Site ('Open Redirect')
519502
}
520503

521-
/**
522-
* http://projects.webappsec.org/w/page/13246981/URL%20Redirector%20Abuse
523-
*
524-
* @return the official WASC id
525-
*/
526504
@Override
527505
public int getWascId() {
528-
return 38;
506+
return 38; // URL Redirector Abuse
529507
}
530508

531509
@Override

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/FormatStringScanRule.java

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -105,19 +105,15 @@ public String getReference() {
105105
return Constant.messages.getString(MESSAGE_PREFIX + "refs");
106106
}
107107

108-
private String getError(char c) {
108+
private static String getError(char c) {
109109
return Constant.messages.getString(MESSAGE_PREFIX + "error" + c);
110110
}
111111

112-
/*
113-
* This method is called by the active scanner for each GET and POST parameter for every page
114-
* @see org.parosproxy.paros.core.scanner.AbstractAppParamPlugin#scan(org.parosproxy.paros.network.HttpMessage, java.lang.String, java.lang.String)
115-
*/
116112
@Override
117113
public void scan(HttpMessage msg, String param, String value) {
118114

119115
if (this.isStop()) { // Check if the user stopped things
120-
LOGGER.debug("Scanner {} Stopping.", getName());
116+
LOGGER.debug("Stopping scan rule \"{}\".", getName());
121117
return; // Stop!
122118
}
123119

@@ -223,7 +219,7 @@ && isPage200(verificationMsg)) {
223219
// errors. It is only
224220
// used if the GNU and generic C compiler check fails to find a vulnerability.
225221
if (this.isStop()) { // Check if the user stopped things
226-
LOGGER.debug("Scanner {} Stopping.", getName());
222+
LOGGER.debug("Stopping scan rule \"{}\".", getName());
227223
return; // Stop!
228224
}
229225
StringBuilder sb2 = new StringBuilder();
@@ -276,14 +272,12 @@ public Map<String, String> getAlertTags() {
276272

277273
@Override
278274
public int getCweId() {
279-
// The CWE id
280-
return 134;
275+
return 134; // CWE-134: Use of Externally-Controlled Format String
281276
}
282277

283278
@Override
284279
public int getWascId() {
285-
// The WASC ID
286-
return 6;
280+
return 6; // Format String
287281
}
288282

289283
private AlertBuilder createBaseAlert(

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/GetForPostScanRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void scan() {
8888
// Check if the user stopped things. One request per URL so check before
8989
// sending the request
9090
if (isStop()) {
91-
LOGGER.debug("Scan rule {} Stopping.", getName());
91+
LOGGER.debug("Stopping scan rule \"{}\".", getName());
9292
return;
9393
}
9494

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/HeartBleedActiveScanRule.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ public class HeartBleedActiveScanRule extends AbstractHostPlugin
5151
/** the timeout, which is controlled by the Attack Strength */
5252
private int timeoutMs = 0;
5353

54-
/** the logger object */
5554
private static final Logger LOGGER = LogManager.getLogger(HeartBleedActiveScanRule.class);
5655

5756
/** Prefix for internationalized messages used by this rule */
@@ -868,7 +867,6 @@ public class HeartBleedActiveScanRule extends AbstractHostPlugin
868867
0x40,
869868
0x00 // payload length to be sent back by the server. 0x40 0x00 = 16384 in decimal
870869
// Note: No actual payload sent!
871-
// Note: No actual padding sent!
872870
};
873871

874872
@Override

addOns/ascanrules/src/main/java/org/zaproxy/zap/extension/ascanrules/HiddenFilesScanRule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ public void scan() {
113113
for (HiddenFile file : hfList) {
114114

115115
if (isStop()) {
116-
LOGGER.debug("Scan rule {} stopping.", getName());
116+
LOGGER.debug("Stopping scan rule \"{}\".", getName());
117117
return;
118118
}
119119

0 commit comments

Comments
 (0)