Skip to content

Commit 347a8ea

Browse files
committed
add find-js-file.js to passive rules
1 parent 287b0ef commit 347a8ea

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

passive/find-js-file.js

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Author: https://nmwafa.github.io - with GPT
2+
3+
var ScanRuleMetadata = Java.type(
4+
"org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata"
5+
);
6+
7+
function getMetadata() {
8+
return ScanRuleMetadata.fromYaml(`
9+
id: 100021
10+
name: JavaScript File Reference Detector
11+
description: >
12+
Detects references to JavaScript (.js) files in HTML responses.
13+
JavaScript files may expose sensitive information or be vulnerable
14+
to client-side attacks if not reviewed.
15+
solution: >
16+
Review all referenced JavaScript files. Ensure they do not contain
17+
sensitive data (e.g., API keys, credentials) and follow secure coding practices.
18+
risk: info
19+
confidence: medium
20+
cweId: 200 # CWE-200: Information Exposure
21+
wascId: 13 # WASC-13: Information Leakage
22+
status: alpha
23+
helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/
24+
`);
25+
}
26+
27+
function scan(helper, msg, src) {
28+
var contentType = msg.getResponseHeader().getHeader("Content-Type");
29+
if (!contentType || contentType.toLowerCase().indexOf("text/html") == -1) {
30+
return;
31+
}
32+
33+
var body = msg.getResponseBody().toString();
34+
35+
var regex = /["'(]([^"'()]+?\.js)(\?.*?)?["')]/gi;
36+
var matches = [];
37+
var found;
38+
39+
while ((found = regex.exec(body)) !== null) {
40+
matches.push(found[1]);
41+
}
42+
43+
if (matches.length > 0) {
44+
var mainEvidence = matches[0];
45+
var extraInfo =
46+
matches.length > 1
47+
? "Additional JS files:\n" + matches.slice(1).join("\n")
48+
: "";
49+
50+
helper
51+
.newAlert()
52+
.setName("JavaScript file detected")
53+
.setRisk(0)
54+
.setConfidence(1)
55+
.setEvidence(mainEvidence)
56+
.setOtherInfo(extraInfo)
57+
.setMessage(msg)
58+
.raise();
59+
}
60+
}

0 commit comments

Comments
 (0)