|
18 | 18 | // NOTE: This script will only find HTML comments in content which passes through ZAP. |
19 | 19 | // Therefore if you browser is caching you may not see something you expect to. |
20 | 20 |
|
21 | | -function scan(ps, msg, src) { |
| 21 | +var ScanRuleMetadata = Java.type( |
| 22 | + "org.zaproxy.addon.commonlib.scanrules.ScanRuleMetadata" |
| 23 | +); |
| 24 | + |
| 25 | +function getMetadata() { |
| 26 | + return ScanRuleMetadata.fromYaml(` |
| 27 | +id: 100011 |
| 28 | +name: Information Disclosure - HTML Comments |
| 29 | +description: > |
| 30 | + While adding general comments is very useful, some programmers tend to leave important data, |
| 31 | + such as: filenames related to the web application, old links or links which were not meant |
| 32 | + to be browsed by users, old code fragments, etc. |
| 33 | +solution: > |
| 34 | + Remove comments which have sensitive information about the design/implementation |
| 35 | + of the application. Some of the comments may be exposed to the user and affect |
| 36 | + the security posture of the application. |
| 37 | +risk: info |
| 38 | +confidence: medium |
| 39 | +cweId: 615 # CWE-615: Inclusion of Sensitive Information in Source Code Comments |
| 40 | +wascId: 13 # WASC-13: Information Leakage |
| 41 | +status: alpha |
| 42 | +codeLink: https://github.com/zaproxy/community-scripts/blob/main/passive/Find%20HTML%20Comments.js |
| 43 | +helpLink: https://www.zaproxy.org/docs/desktop/addons/community-scripts/ |
| 44 | +`); |
| 45 | +} |
| 46 | + |
| 47 | +function scan(helper, msg, src) { |
22 | 48 | // Both can be true, just know that you'll see duplication. |
23 | 49 | var RESULT_PER_FINDING = new Boolean(0); // If you want to see results on a per comment basis (i.e.: A single URL may be listed more than once), set this to true (1) |
24 | 50 | var RESULT_PER_URL = new Boolean(1); // If you want to see results on a per URL basis (i.e.: all comments for a single URL will be grouped together), set this to true (1) |
25 | 51 |
|
26 | | - // lets set up some details we will need for alerts later if we find some comments |
27 | | - var alertRisk = 0; |
28 | | - var alertConfidence = 2; |
29 | | - var alertTitle = "Information Exposure Through HTML Comments (script)"; |
30 | | - var alertDesc = |
31 | | - "While adding general comments is very useful, \ |
32 | | -some programmers tend to leave important data, such as: filenames related to the web application, old links \ |
33 | | -or links which were not meant to be browsed by users, old code fragments, etc."; |
34 | | - var alertSolution = |
35 | | - "Remove comments which have sensitive information about the design/implementation \ |
36 | | -of the application. Some of the comments may be exposed to the user and affect the security posture of the \ |
37 | | -application."; |
38 | | - var cweId = 615; |
39 | | - var wascId = 13; |
40 | | - var url = msg.getRequestHeader().getURI().toString(); |
41 | | - |
42 | 52 | // this is a rough regular expression to find HTML comments |
43 | 53 | // regex needs to be inside /( and )/g to work |
44 | 54 | var re = /(\<![\s]*--[\-!@#$%^&*:;ºª.,"'(){}\w\s\/\\[\]]*--[\s]*\>)/g; |
@@ -66,40 +76,22 @@ application."; |
66 | 76 | if (RESULT_PER_FINDING == true) { |
67 | 77 | counter = counter + 1; |
68 | 78 | //fakeparam+counter gives us parameter differientiation per comment alert (RESULT_PER_FINDING) |
69 | | - ps.raiseAlert( |
70 | | - alertRisk, |
71 | | - alertConfidence, |
72 | | - alertTitle, |
73 | | - alertDesc, |
74 | | - url, |
75 | | - "fakeparam" + counter, |
76 | | - "", |
77 | | - comm[0], |
78 | | - alertSolution, |
79 | | - "", |
80 | | - cweId, |
81 | | - wascId, |
82 | | - msg |
83 | | - ); |
| 79 | + helper |
| 80 | + .newAlert() |
| 81 | + .setParam("fakeparam" + counter) |
| 82 | + .setEvidence(comm[0]) |
| 83 | + .setMessage(msg) |
| 84 | + .raise(); |
84 | 85 | } |
85 | 86 | foundComments.push(comm[0]); |
86 | 87 | } |
87 | 88 | if (RESULT_PER_URL == true) { |
88 | | - ps.raiseAlert( |
89 | | - alertRisk, |
90 | | - alertConfidence, |
91 | | - alertTitle, |
92 | | - alertDesc, |
93 | | - url, |
94 | | - "", |
95 | | - "", |
96 | | - foundComments.toString(), |
97 | | - alertSolution, |
98 | | - "", |
99 | | - cweId, |
100 | | - wascId, |
101 | | - msg |
102 | | - ); |
| 89 | + helper |
| 90 | + .newAlert() |
| 91 | + .setEvidence(foundComments[0]) |
| 92 | + .setOtherInfo(`Other instances: ${foundComments.slice(1).toString()}`) |
| 93 | + .setMessage(msg) |
| 94 | + .raise(); |
103 | 95 | } |
104 | 96 | } |
105 | 97 | } |
|
0 commit comments