Skip to content

Commit 39d4e87

Browse files
committed
Address potential classloader performance issues
Signed-off-by: kingthorin <kingthorin@users.noreply.github.com>
1 parent e7718fb commit 39d4e87

16 files changed

+92
-90
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
1515
- Add cautionary note to help and readme.
1616
- Maintenance and documentation changes.
1717
- Active and passive READMEs to include lastest JS script examples.
18+
- Reduce usage of fully qualified objects in loops or main methods to address potential classloader performance issues.
1819

1920
### Fixed
2021
- The following scripts were not being loaded as scan rules:

httpfuzzerprocessor/addCacheBusting.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
1+
const HtmlParameter = Java.type("org.parosproxy.paros.network.HtmlParameter");
2+
const URL_TYPE = org.parosproxy.paros.network.HtmlParameter.Type.url;
3+
14
function processMessage(utils, message) {
25
var cbValue = "" + Math.floor(Math.random() * 10000);
36
setCacheBusting(message, cbValue);
47
message.getRequestHeader().setHeader("X-Cache-Busting", cbValue);
58
}
69

710
function setCacheBusting(message, cbValue) {
8-
var HtmlParameter = Java.type("org.parosproxy.paros.network.HtmlParameter");
9-
var URL_TYPE = org.parosproxy.paros.network.HtmlParameter.Type.url;
1011
var params = message.getUrlParams();
1112
var newParam = new HtmlParameter(
1213
URL_TYPE,

httpfuzzerprocessor/add_msgs_sites_tree.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
// A Fuzzer HTTP Processor script that allows to populate the Sites tree
22
// with messages sent by the fuzzer (by default the fuzz result/messages
33
// are not shown in the Fuzzer tab).
4+
const HistoryReference = Java.type(
5+
"org.parosproxy.paros.model.HistoryReference"
6+
);
7+
const EventQueue = Java.type("java.awt.EventQueue");
48

59
var session = model.getSession();
610

@@ -11,9 +15,9 @@ function processResult(utils, fuzzResult) {
1115
// The type 15 indicates that the message was sent by the user.
1216
// Refer to the HistoryReference for more details on the available types.
1317
// Persist the message to the session.
14-
var ref = new org.parosproxy.paros.model.HistoryReference(session, 15, msg);
18+
var ref = new HistoryReference(session, 15, msg);
1519
// Add the message to Sites tree.
16-
java.awt.EventQueue.invokeLater(function () {
20+
EventQueue.invokeLater(function () {
1721
session.getSiteTree().addPath(ref, msg);
1822
});
1923

httpfuzzerprocessor/unexpected_responses.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
// This script needs Diff add-on
1616

17-
var DiffTool = Java.type("org.zaproxy.zap.extension.diff.diff_match_patch");
17+
const DiffTool = Java.type("org.zaproxy.zap.extension.diff.diff_match_patch");
1818

1919
/*
2020
* Declare parameters

httpsender/Alert on HTTP Response Code Errors.js

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,21 @@
22
// By default it will raise 'Info' level alerts for Client Errors (4xx) (apart from 404s) and 'Low' Level alerts for Server Errors (5xx)
33
// But it can be easily changed.
44

5-
var Pattern = Java.type("java.util.regex.Pattern");
5+
const Integer = Java.type("java.lang.Integer");
6+
const Pattern = Java.type("java.util.regex.Pattern");
7+
8+
const Alert = Java.type("org.parosproxy.paros.core.scanner.Alert");
9+
const ExtensionAlert = Java.type(
10+
"org.zaproxy.zap.extension.alert.ExtensionAlert"
11+
);
12+
const HistoryReference = Java.type(
13+
"org.parosproxy.paros.model.HistoryReference"
14+
);
15+
16+
const extensionAlert = control
17+
.getExtensionLoader()
18+
.getExtension(ExtensionAlert.NAME);
19+
620
pluginid = 100000; // https://github.com/zaproxy/zaproxy/blob/main/docs/scanners.md
721

822
function sendingRequest(msg, initiator, helper) {
@@ -14,12 +28,10 @@ function responseReceived(msg, initiator, helper) {
1428
// Not of interest.
1529
return;
1630
}
17-
var extensionAlert = control
18-
.getExtensionLoader()
19-
.getExtension(org.zaproxy.zap.extension.alert.ExtensionAlert.NAME);
31+
2032
if (extensionAlert != null) {
2133
var code = msg.getResponseHeader().getStatusCode();
22-
if (code < 400 || code >= 600 || code == 404) {
34+
if (code < 400 || code >= 600) {
2335
// Do nothing
2436
} else {
2537
var risk = 0; // Info
@@ -30,17 +42,12 @@ function responseReceived(msg, initiator, helper) {
3042
title = "A Server Error response code was returned by the server";
3143
}
3244
// CONFIDENCE_HIGH = 3 (we can be pretty sure we're right)
33-
var alert = new org.parosproxy.paros.core.scanner.Alert(
34-
pluginid,
35-
risk,
36-
3,
37-
title
38-
);
45+
var alert = new Alert(pluginid, risk, 3, title);
3946
var ref = msg.getHistoryRef();
4047
if (
4148
ref != null &&
42-
org.parosproxy.paros.model.HistoryReference.getTemporaryTypes().contains(
43-
java.lang.Integer.valueOf(ref.getHistoryType())
49+
HistoryReference.getTemporaryTypes().contains(
50+
Integer.valueOf(ref.getHistoryType())
4451
)
4552
) {
4653
// Dont use temporary types as they will get deleted
@@ -78,11 +85,7 @@ function responseReceived(msg, initiator, helper) {
7885
type = 15; // User - fallback
7986
break;
8087
}
81-
ref = new org.parosproxy.paros.model.HistoryReference(
82-
model.getSession(),
83-
type,
84-
msg
85-
);
88+
ref = new HistoryReference(model.getSession(), type, msg);
8689
}
8790
alert.setMessage(msg);
8891
alert.setUri(msg.getRequestHeader().getURI().toString());
@@ -93,9 +96,7 @@ function responseReceived(msg, initiator, helper) {
9396
"This may indicate that the application is failing to handle unexpected input correctly.\n" +
9497
"Raised by the 'Alert on HTTP Response Code Error' script"
9598
);
96-
// Use a regex to extract the evidence from the response header
97-
var regex = new RegExp("^HTTP.*" + code);
98-
alert.setEvidence(msg.getResponseHeader().toString().match(regex));
99+
alert.setEvidence(code.toString());
99100
alert.setCweId(388); // CWE CATEGORY: Error Handling
100101
alert.setWascId(20); // WASC Improper Input Handling
101102
extensionAlert.alertFound(alert, ref);

httpsender/Alert on Unexpected Content Types.js

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22
// By default it will raise 'Low' level alerts for content types that are not expected to be returned by APIs.
33
// But it can be easily changed.
44

5-
var Pattern = Java.type("java.util.regex.Pattern");
5+
const Integer = Java.type("java.lang.Integer");
6+
const Pattern = Java.type("java.util.regex.Pattern");
67

7-
var pluginid = 100001; // https://github.com/zaproxy/zaproxy/blob/main/docs/scanners.md
8+
const Alert = Java.type("org.parosproxy.paros.core.scanner.Alert");
9+
const ExtensionAlert = Java.type(
10+
"org.zaproxy.zap.extension.alert.ExtensionAlert"
11+
);
12+
const HistoryReference = Java.type(
13+
"org.parosproxy.paros.model.HistoryReference"
14+
);
815

9-
var extensionAlert = control
16+
const extensionAlert = control
1017
.getExtensionLoader()
11-
.getExtension(org.zaproxy.zap.extension.alert.ExtensionAlert.NAME);
18+
.getExtension(ExtensionAlert.NAME);
19+
20+
var pluginid = 100001; // https://github.com/zaproxy/zaproxy/blob/main/docs/scanners.md
1221

1322
var expectedTypes = ["application/octet-stream", "text/plain"];
1423

@@ -23,6 +32,7 @@ function responseReceived(msg, initiator, helper) {
2332
// Not of interest.
2433
return;
2534
}
35+
2636
if (extensionAlert != null) {
2737
var ctype = msg.getResponseHeader().getHeader("Content-Type");
2838
if (ctype != null) {
@@ -38,17 +48,12 @@ function responseReceived(msg, initiator, helper) {
3848
var risk = 1; // Low
3949
var title = "Unexpected Content-Type was returned";
4050
// CONFIDENCE_HIGH = 3 (we can be pretty sure we're right)
41-
var alert = new org.parosproxy.paros.core.scanner.Alert(
42-
pluginid,
43-
risk,
44-
3,
45-
title
46-
);
51+
var alert = new Alert(pluginid, risk, 3, title);
4752
var ref = msg.getHistoryRef();
4853
if (
4954
ref != null &&
50-
org.parosproxy.paros.model.HistoryReference.getTemporaryTypes().contains(
51-
java.lang.Integer.valueOf(ref.getHistoryType())
55+
HistoryReference.getTemporaryTypes().contains(
56+
Integer.valueOf(ref.getHistoryType())
5257
)
5358
) {
5459
// Dont use temporary types as they will get deleted
@@ -86,11 +91,7 @@ function responseReceived(msg, initiator, helper) {
8691
type = 15; // User - fallback
8792
break;
8893
}
89-
ref = new org.parosproxy.paros.model.HistoryReference(
90-
model.getSession(),
91-
type,
92-
msg
93-
);
94+
ref = new HistoryReference(model.getSession(), type, msg);
9495
}
9596
alert.setMessage(msg);
9697
alert.setUri(msg.getRequestHeader().getURI().toString());

passive/Report non static sites.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44
// Note that new passive scripts will initially be disabled
55
// Right click the script in the Scripts tree and select "enable"
66

7+
const PluginPassiveScanner = Java.type(
8+
"org.zaproxy.zap.extension.pscan.PluginPassiveScanner"
9+
);
710
var ScanRuleMetadata = Java.type(
811
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
912
);
@@ -73,7 +76,5 @@ function appliesToHistoryType(historyType) {
7376
// return historyType == org.parosproxy.paros.model.HistoryReference.TYPE_SPIDER;
7477

7578
// Default behaviour scans default types.
76-
return org.zaproxy.zap.extension.pscan.PluginPassiveScanner.getDefaultHistoryTypes().contains(
77-
historyType
78-
);
79+
return PluginPassiveScanner.getDefaultHistoryTypes().contains(historyType);
7980
}

passive/Telerik Using Poor Crypto.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
const ScanRuleMetadata = Java.type(
88
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
99
);
10+
const Base64 = Java.type("org.apache.commons.codec.binary.Base64");
1011

1112
function getMetadata() {
1213
return ScanRuleMetadata.fromYaml(`
@@ -54,11 +55,11 @@ function scan(helper, msg, src) {
5455
return;
5556
}
5657

57-
if (!org.apache.commons.codec.binary.Base64.isBase64(dp)) {
58+
if (!Base64.isBase64(dp)) {
5859
return;
5960
}
6061

61-
var dpBytes = org.apache.commons.codec.binary.Base64.decodeBase64(dp);
62+
var dpBytes = Base64.decodeBase64(dp);
6263

6364
if (dpBytes.length < 48) {
6465
return;

standalone/historySourceTagger.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// if they don't already have a tag that starts with TAG_PREFIX as defined below.
66
// Author: kingthorin
77
// 20160207: Initial release
8+
// 20251212: Maintenance changes
9+
const ScriptVars = Java.type("org.zaproxy.zap.extension.script.ScriptVars");
810

911
extHist = control
1012
.getExtensionLoader()
@@ -13,7 +15,7 @@ extHist = control
1315
TAG_PREFIX = "SRC_";
1416

1517
if (extHist != null) {
16-
i = org.zaproxy.zap.extension.script.ScriptVars.getGlobalVar("tagged_ref"); // Check for global reference
18+
i = ScriptVars.getGlobalVar("tagged_ref"); // Check for global reference
1719
if (i == null) {
1820
i = 1; // Global reference was null so 1
1921
}
@@ -48,8 +50,5 @@ if (extHist != null) {
4850
}
4951
i++;
5052
}
51-
org.zaproxy.zap.extension.script.ScriptVars.setGlobalVar(
52-
"tagged_ref",
53-
lastRef + 1
54-
); // Set global reference
53+
ScriptVars.setGlobalVar("tagged_ref", lastRef + 1); // Set global reference
5554
}

targeted/Remove 302s.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
// the script was invoked with.
33
// The default criteria is leaf nodes with a response code of 302 but you can change that to anything you need
44
// Targeted scripts can only be invoked by you, the user, eg via a right-click option on the Sites or History tabs
5+
const PopupMenuPurgeSites = Java.type(
6+
"org.zaproxy.zap.extension.history.PopupMenuPurgeSites"
7+
);
58

69
function recurseDown(sitestree, node) {
710
//print('recurseDown node: ' + node.getHierarchicNodeName() + " " + node.getChildCount())
@@ -15,10 +18,7 @@ function recurseDown(sitestree, node) {
1518
}
1619
if (deleteThis(node)) {
1720
print("Removing node: " + node.getHierarchicNodeName());
18-
org.zaproxy.zap.extension.history.PopupMenuPurgeSites.purge(
19-
sitestree,
20-
node
21-
);
21+
PopupMenuPurgeSites.purge(sitestree, node);
2222
return true;
2323
}
2424
return false;

0 commit comments

Comments
 (0)