Skip to content

Commit 97215e6

Browse files
author
Aastha Sahni
committed
Update Swagger Secret Detector with improved checks and minor changes suggested
1 parent b00b73b commit 97215e6

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

active/swagger-secret-detector.js

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ var ScanRuleMetadata = Java.type("org.zaproxy.addon.commonlib.scanrules.ScanRule
1010
var CommonAlertTag = Java.type("org.zaproxy.addon.commonlib.CommonAlertTag");
1111
function getMetadata() {
1212
return ScanRuleMetadata.fromYaml(`
13-
id: 100001
13+
id: 100043
1414
name: Swagger UI Secret & Vulnerability Detector
1515
description: >
1616
Detects exposed Swagger UI and OpenAPI endpoints that leak sensitive secrets such as API keys,
@@ -19,14 +19,10 @@ description: >
1919
solution: >
2020
Remove hardcoded secrets from API documentation, restrict access to API documentation endpoints,
2121
and upgrade Swagger UI to a secure version. Ensure proper authentication is required to access documentation.
22-
references:
23-
- https://swagger.io/docs/
24-
- https://owasp.org/www-project-api-security/
2522
category: info_gather
2623
risk: high
2724
confidence: medium
28-
cweId: 200 # CWE-200: Exposure of Sensitive Information to an Unauthorized Actor
29-
wascId: 13 # WASC-13: Information Leakage
25+
cweId: 522 # Insufficiently Protected Credentials
3026
alertTags:
3127
${CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG.getTag()}: ${CommonAlertTag.OWASP_2021_A05_SEC_MISCONFIG.getValue()}
3228
${CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getTag()}: ${CommonAlertTag.OWASP_2017_A06_SEC_MISCONFIG.getValue()}
@@ -232,8 +228,8 @@ function scanPath(as, origMsg, scheme, host, port, pathOnly, fullPath) {
232228
as.newAlert()
233229
.setRisk(3)
234230
.setConfidence(2)
235-
.setName("Vulnerable Swagger UI version detected (v" + semver + ")")
236-
.setAlertRef("100001-1")
231+
.setName("Vulnerable Swagger UI Version Detected (v" + semver + ")")
232+
.setAlertRef("100043-1")
237233
.setDescription("This Swagger UI version is known to contain vulnerabilities. Exploitation may allow unauthorized access, XSS, or token theft.\n\nAffected versions:\n- Swagger UI v2 < 2.2.10\n- Swagger UI v3 < 3.24.3")
238234
.setOtherInfo("Discovered at: " + fullPath)
239235
.setSolution("Upgrade to the latest version of Swagger UI. Regularly review and patch known issues.")
@@ -262,21 +258,22 @@ function detectSecrets(as, requestMsg, fullPath, body) {
262258

263259
var evidenceRaw = Object.keys(matches);
264260
var redactedEvidence = evidenceRaw.map(redactSecret);
261+
// var evidenceString = redactedEvidence.length > 0 ? redactedEvidence[0] : null;
265262
var foundClientId = evidenceRaw.some(e => /clientId/i.test(e));
266263
var foundSecret = evidenceRaw.some(e => /clientSecret|api_key|access_token|authorization/i.test(e));
267264

268265
if (foundClientId && foundSecret) {
269266
as.newAlert()
270267
.setRisk(3)
271268
.setConfidence(2)
272-
.setName("Exposed secrets in Swagger/OpenAPI path")
273-
.setAlertRef("100001-2")
269+
.setName("Exposed Secrets in Swagger/OpenAPI Path")
270+
.setAlertRef("100043-2")
274271
.setDescription("Swagger UI endpoint exposes sensitive secrets such as client secrets, API keys, or OAuth tokens. These secrets may be accessible in the HTML source and should not be exposed publicly, as this can lead to compromise.")
275-
.setEvidence(redactedEvidence.join("\n"))
276-
.setOtherInfo("Discovered at: " + fullPath)
272+
.setEvidence(redactedEvidence[0])
273+
.setOtherInfo("All secrets exposed:\n" + redactedEvidence.join("\n"))
277274
.setSolution("Remove hardcoded secrets from documentation and ensure the endpoint is protected with authentication.")
278275
.setReference("https://swagger.io/docs/open-source-tools/swagger-ui/usage/oauth2/")
279276
.setMessage(requestMsg)
280277
.raise();
281278
}
282-
}
279+
}

0 commit comments

Comments
 (0)