Skip to content

Commit d71b820

Browse files
Add CORS misconfiguration Bambda. (#139)
* Add CORS misconfiguration Bambda. * Use a random string for the domain extension.
1 parent 30f0d28 commit d71b820

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
id: 46cae4a9-45ff-406a-80bc-c9a0fe630535
2+
name: CORS misconfiguration
3+
function: SCAN_CHECK_ACTIVE_PER_REQUEST
4+
location: SCANNER
5+
source: |
6+
/**
7+
* Identifies CORS misconfiguration.
8+
* @author PortSwigger
9+
**/
10+
11+
if (!requestResponse.hasResponse())
12+
{
13+
return null;
14+
}
15+
16+
var evilHttps = "https://" + api().utilities().randomUtils().randomString(6) + "." + api().utilities().randomUtils().randomString(3);
17+
var evilHttp = "http://" + api().utilities().randomUtils().randomString(6) + "." + api().utilities().randomUtils().randomString(3);
18+
19+
for (var origin : new String[]{evilHttps, evilHttp})
20+
{
21+
var rr = http.sendRequest(requestResponse.request().withAddedHeader("Origin", origin));
22+
if (!rr.hasResponse())
23+
{
24+
continue;
25+
}
26+
27+
var headers = rr.response().headers().toString().toLowerCase();
28+
var creds = headers.contains("access-control-allow-credentials: true");
29+
var reflect = headers.contains("access-control-allow-origin: " + origin.toLowerCase());
30+
var vary = headers.contains("vary: origin");
31+
32+
if (reflect)
33+
{
34+
var severity = creds ? AuditIssueSeverity.HIGH : AuditIssueSeverity.MEDIUM;
35+
var note = vary ? "" : " (missing Vary: Origin)";
36+
return AuditResult.auditResult(
37+
AuditIssue.auditIssue(
38+
"CORS: arbitrary origin reflection" + note,
39+
"Reflected Origin: " + origin + "; credentials=" + creds,
40+
"Use strict allowlist; include Vary: Origin.",
41+
rr.request().url(),
42+
severity,
43+
AuditIssueConfidence.FIRM,
44+
"",
45+
"",
46+
severity,
47+
rr
48+
)
49+
);
50+
}
51+
}
52+
53+
return AuditResult.auditResult();

0 commit comments

Comments
 (0)