728x90
1.sanitize-html 모듈
HTML 문자열에서 불필요하거나 잠재적으로 위험한 요소를 제거하여 XSS(교차 사이트 스크립팅) 공격을 방지하는 데 사용되는 Node.js 모듈
const sanitizeHtml = require('sanitize-html');
// 사용자가 제공한 HTML 문자열
const dirtyHtml = '<div><script>alert("XSS Attack!")</script><p>Hello, World!</p></div>';
// 기본 설정으로 HTML을 정제 (기본적으로 모든 스크립트와 스타일 태그 제거)
const cleanHtml = sanitizeHtml(dirtyHtml);
console.log(cleanHtml); // <div><p>Hello, World!</p></div>
728x90
'클론코딩 > 생활코딩 Node.js' 카테고리의 다른 글
[Node.js] path 모듈 (0) | 2024.09.04 |
---|---|
[Node.js] fs 모듈 (1) | 2024.09.04 |
[Node.js] querystring 모듈 (0) | 2024.09.04 |