LoginSignup
0
0

More than 5 years have passed since last update.

vue.jsでサーバーサイドレンダリングする場合は、vue.jsのエスケープを。

Posted at

vue.jsをサーバーサイドでレンダリングする場合、HTMLのエスケープではなくvue.jsのエスケープが必要です。

index.php
<script src="https://cdn.jsdelivr.net/npm/vue@2.5.16/dist/vue.min.js"></script>
<div id="app">
  <?= htmlspecialchars($_GET["param"], ENT_QUOTES, "utf-8") ?>
</div>
<script>
      new Vue({
        el: '#app'
      })
</script>

上記をphp(サーバーサイド)で実装、URLパラメータに「param={{alert(1)}}」を付けて実行すると
alert()が発火してしまいます。
どうしてもサーバーサイドレンダリングをする場合は、サーバ側でvueを生成する場合は、「{{}}」をサーバでエスケープしなければいけません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0