?test= にリライト。
index.php の script タグ内に filter_input(INPUT_GET, 'test') を記述し、ブラウザで確認した。
結論
PHP の GET 変数を Javascript の変数に代入する場合、ダブルクオートで囲み、クォートエンコードしても安全とは限らない。
.htaccess
RewriteEngine on
RewriteRule ^([^/]*)/$ ?test=$1 [L]
ダブルクオートなし + エンコードなし
index.php <script>let a=<?=filter_input(INPUT_GET, 'test')?>;</script>
URL
http://localhost/test/alert()/
結果
アラートあり
ダブルクオートなし + クォートエンコードあり
index.php <script>let a=<?=filter_input(INPUT_GET, 'test', FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>;</script>
URL
http://localhost/test/alert()/
結果
アラートあり
ダブルクオートあり + エンコードなし
index.php <script>let a="<?=filter_input(INPUT_GET, 'test')?>";</script>
URL
http://localhost/test/alert()/
結果
アラートなし
ダブルクオートあり + エンコードなし
index.php <script>let a="<?=filter_input(INPUT_GET, 'test')?>";</script>
URL
http://localhost/test/";alert();z="/
結果
アラートあり
ダブルクオートあり + クォートエンコードあり
index.php <script>let a="<?=filter_input(INPUT_GET, 'test', FILTER_SANITIZE_FULL_SPECIAL_CHARS)?>";</script>
URL
http://localhost/test/";alert();z="/
結果
アラートなし
ダブルクオートなし + JSON エンコードあり
index.php <script>let a=<?=json_encode(filter_input(INPUT_GET, 'test'))?>;</script>
URL
http://localhost/test/alert()/
結果
アラートなし
ダブルクオートあり + JSON エンコードあり
index.php <script>let a="<?=json_encode(filter_input(INPUT_GET, 'test'))?>";</script>
URL
http://localhost/test/alert()/
結果
アラートなし
ダブルクオートなし + JSON エンコードあり
index.php <script>let a=<?=json_encode(filter_input(INPUT_GET, 'test'))?>;</script>
URL
http://localhost/test/";alert();z="/
結果
アラートなし
ダブルクオートあり + JSON エンコードあり
index.php <script>let a="<?=json_encode(filter_input(INPUT_GET, 'test'))?>";</script>
URL
http://localhost/test/;alert();z=/
結果
アラートあり
ダブルクオートあり + JSON エンコードあり + クォートエンコードあり
index.php <script>let a="<?=json_encode(filter_input(INPUT_GET, 'test', FILTER_SANITIZE_FULL_SPECIAL_CHARS))?>";</script>
URL
http://localhost/test/;alert();z=/
結果
アラートあり