先看CSS:
直接上代碼:
<!DOCTYPE html>
<html>
<head>
<title></title>
<style type="text/css">
test{
background: url('http://www.baidu.com/</style><h1>aaaa</h1>');
}
</style>
</head>
<body>
bbb
</body>
</html>
注意代碼中第一個</style>的位置,測試結果:
chrome
FF
IE
chrome最終解析成的代碼:
同理,script標籤也會出現同樣的問題:
<!DOCTYPE html>
<html>
<head>
<title></title>
<script type="text/javascript">
var a="aaa</script><h1>bbb</h1>";
</script>
</head>
<body>
bbb
</body>
</html>
測試結果:
解析後的代碼:
總結:
在頁面中嵌入CSS或script時,</style>和</script>標籤會有較高的優先級,造成對引號的突破,包括單引號和雙引號,在防禦此類問題時,需要特別注意對這兩個標籤的檢查。