&<>*‘/()
등을&
<
>
"
'
/
(
)
로 치환<html>
<body>
<script>
const query = "<script>alert('hello world')<"+"/script>";
async function req() {
// 사용자가 에디터와 같은 입력 폼에 입력한 데이터를 서버에 저장
const response = await fetch(`/vuln/search?q=${query}`, { method: 'GET' })
const data = await response.text();
// 외부로부터 받은 데이터(HTML 코드)를 아무런 검증 없이 DOM으로 기록
document.write(data);
}
req();
</script>
</body>
</html>
<html>
<body>
<script>
const query = "<script>alert('hello world')<"+"/script>";
async function req() {
const response = await fetch(`/vuln/search?q=${query}`, { method: 'GET' })
const data = await response.text();
// 외부로부터 받은 데이터를 이스케이프 처리 후 사용
document.write(decodeURI(encodeURIComponent(data)));
}
req();
</script>
</body>
</html>
과학기술정보통신부와 한국인터넷진흥원의 'JavaScript 시큐어코딩 가이드'