Skip to content

Commit e72546c

Browse files
committed
scan rules: Clean code tweaks
- Add static modifier where applicable. - CHANGELOG > Add maintenance note (if there wasn't already one present). - pscanrules > Made resource message methods private again where example alerts have been implemented, or removed them where there was only a single usage (inlining the Contstant resource message usage).
1 parent 839d5c7 commit e72546c

File tree

98 files changed

+244
-519
lines changed

Some content is hidden

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

98 files changed

+244
-519
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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ public int getWascId() {
169169
return 7;
170170
}
171171

172-
private String randomCharacterString(int length) {
172+
private static String randomCharacterString(int length) {
173173
StringBuilder sb1 = new StringBuilder(length + 1);
174174
int counter = 0;
175175
int character = 0;

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,7 @@ public int getRisk() {
366366
return Alert.RISK_HIGH;
367367
}
368368

369-
private String getOtherInfo(TestType testType, String testValue) {
369+
private static String getOtherInfo(TestType testType, String testValue) {
370370
return Constant.messages.getString(
371371
MESSAGE_PREFIX + "otherinfo." + testType.getNameKey(), testValue);
372372
}

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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,7 @@ private static boolean isRedirectHost(String value, boolean escaped) throws URIE
342342
* @param msg the current message where reflected redirection should be check into
343343
* @return get back the redirection type if exists
344344
*/
345-
private int isRedirected(String payload, HttpMessage msg) {
345+
private static int isRedirected(String payload, HttpMessage msg) {
346346

347347
// (1) Check if redirection by "Location" header
348348
// http://en.wikipedia.org/wiki/HTTP_location
@@ -471,7 +471,7 @@ private static boolean isRedirectPresent(Pattern pattern, String value) {
471471
* @param type the redirection type
472472
* @return a string representing the reason of this redirection
473473
*/
474-
private String getRedirectionReason(int type) {
474+
private static String getRedirectionReason(int type) {
475475
switch (type) {
476476
case REDIRECT_LOCATION_HEADER:
477477
return Constant.messages.getString(MESSAGE_PREFIX + "reason.location.header");

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ 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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ private String getEmptyValueResponse(String paramName) throws IOException {
267267
* @param value the value that need to be checked
268268
* @return true if it seems to be encrypted
269269
*/
270-
private boolean isEncrypted(byte[] value) {
270+
private static boolean isEncrypted(byte[] value) {
271271

272272
// Make sure we have a reasonable sized string
273273
// (encrypted strings tend to be long, and short strings tend to break our numbers)

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ private boolean sendAndCheckPayload(
608608
return false;
609609
}
610610

611-
private String getContentsToMatch(HttpMessage message) {
611+
private static String getContentsToMatch(HttpMessage message) {
612612
return message.getResponseHeader().isHtml()
613613
? StringEscapeUtils.unescapeHtml4(message.getResponseBody().toString())
614614
: message.getResponseHeader().toString() + message.getResponseBody().toString();
@@ -700,7 +700,7 @@ public String match(String contents) {
700700
return matchWinDirectories(contents);
701701
}
702702

703-
private String matchNixDirectories(String contents) {
703+
private static String matchNixDirectories(String contents) {
704704
Pattern procPattern =
705705
Pattern.compile("(?:^|\\W)proc(?:\\W|$)", Pattern.CASE_INSENSITIVE);
706706
Pattern etcPattern = Pattern.compile("(?:^|\\W)etc(?:\\W|$)", Pattern.CASE_INSENSITIVE);
@@ -727,7 +727,7 @@ private String matchNixDirectories(String contents) {
727727
return null;
728728
}
729729

730-
private String matchWinDirectories(String contents) {
730+
private static String matchWinDirectories(String contents) {
731731
if (contents.contains("Windows")
732732
&& Pattern.compile("Program\\sFiles").matcher(contents).find()) {
733733
return "Windows";

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ private HttpMessage createHttpMessage(URI uri) throws HttpMalformedHeaderExcepti
277277
* @return
278278
* @throws URIException
279279
*/
280-
private URI getClassURI(URI hostURI, String classname) throws URIException {
280+
private static URI getClassURI(URI hostURI, String classname) throws URIException {
281281
return new URI(
282282
hostURI.getScheme()
283283
+ "://"
@@ -288,7 +288,7 @@ private URI getClassURI(URI hostURI, String classname) throws URIException {
288288
false);
289289
}
290290

291-
private URI getPropsFileURI(URI hostURI, String propsfilename) throws URIException {
291+
private static URI getPropsFileURI(URI hostURI, String propsfilename) throws URIException {
292292
return new URI(
293293
hostURI.getScheme()
294294
+ "://"

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,11 @@ public String getDescription() {
7676
return Constant.messages.getString("ascanrules.spring4shell.desc");
7777
}
7878

79-
private boolean is400Response(HttpMessage msg) {
79+
private static boolean is400Response(HttpMessage msg) {
8080
return !msg.getResponseHeader().isEmpty() && msg.getResponseHeader().getStatusCode() == 400;
8181
}
8282

83-
private void setGetPayload(HttpMessage msg, String payload) throws URIException {
83+
private static void setGetPayload(HttpMessage msg, String payload) throws URIException {
8484
msg.getRequestHeader().setMethod("GET");
8585
URI uri = msg.getRequestHeader().getURI();
8686
String query = uri.getEscapedQuery();
@@ -92,7 +92,7 @@ private void setGetPayload(HttpMessage msg, String payload) throws URIException
9292
uri.setEscapedQuery(query);
9393
}
9494

95-
private void setPostPayload(HttpMessage msg, String payload) {
95+
private static void setPostPayload(HttpMessage msg, String payload) {
9696
msg.getRequestHeader().setMethod("POST");
9797
String body = msg.getRequestBody().toString();
9898
if (body.isEmpty()

0 commit comments

Comments
 (0)