Source: Bug Bounty Bootcamp by Vickie Li
The Same-Origin Policy (SOP) restricts scripts on one origin from reading data from another origin. Two URLs share an origin only if they have the same protocol, hostname, and port. Because browsers automatically attach session cookies to every request for a matching domain, the SOP prevents cross-origin scripts from using those cookies to read private data.
Many sites intentionally relax the SOP to allow cross-origin communication. Misconfigurations in these mechanisms create exploitable bypasses.
CORS lets servers explicitly allow cross-origin requests via response headers:
Access-Control-Allow-Origin: https://b.example.com Access-Control-Allow-Origin: * (wildcard -- no credentials permitted, so not exploitable)
Exploitable misconfigurations:
Access-Control-Allow-Origin: null – any origin can set a null Origin (e.g., data: URL scheme)Test by submitting:
Origin: attacker.com (reflected without validation?) Origin: www.example.com.attacker.com (regex bypass?) Origin: null
If the response returns Access-Control-Allow-Origin: attacker.com (or similar), it's exploitable – attackers can read cross-origin responses with credentials.
postMessage() allows cross-window messaging between frames/popups:
<code javascript>
RECIPIENT_WINDOW.postMessage(MESSAGE, TARGET_ORIGIN)
window.addEventListener(“message”, handler_function)
```
Sender bug: using a wildcard target origin * lets any origin intercept the message:
<code javascript>
recipient_window.postMessage(sensitive_data, “*”);
```
An attacker page can listen for messages from the sender: <code javascript> var sender_window = window.open(“https://TARGET_URL”, target_domain) window.addEventListener(“message”, function(event) {
// capture event.data
}); ```
Receiver bug: if the receiver doesn't validate the sender's origin, any page can send arbitrary messages and trigger state changes.
JSONP lets cross-origin script tags retrieve JSON by wrapping it in a callback function. If a sensitive endpoint supports JSONP and the callback parameter isn't validated: <code html> <script src=“https://TARGET_URL?callback=parseinfo”></script> ```
This executes parseinfo(sensitive_data) in the attacker's context.
window.addEventListener(“message”…), script tags with callback params)attacker.com, null, www.example.com.attacker.com); check the Access-Control-Allow-Origin response header