크로스 사이트 스크립팅(cross-site-scripting)의 약자로, 사용자가 웹페이지에 악성 스크립트를 삽입할 수 있는 취약점이다.
예를 들어 게시판에
npm init
먼저 init으로 npm 패키지 설정을 새로 만들어 준다. (or 업데이트)
중간중간 나오는 질문들은 일단 enter 를 눌러 패스!
다 완료되면 package.json이 생성된다. (or 수정된다)
npm install -P sanitize-html
sanitize-html을 설치한다.
"dependencies": { "pm2": "^5.2.0", "sanitize-html": "^2.7.0" }
// In ES modules
import sanitizeHtml from 'sanitize-html';
// Or in CommonJS
const sanitizeHtml = require('sanitize-html');
이제 sanitizeHtml을 사용하고 싶은 부분에 가서 매개변수로 넘겨준다.
sanitizeHtml은 sanitized 된 새 HTML 을 반환해준다.
const dirty = 'some really tacky HTML';
const clean = sanitizeHtml(dirty);
// Allow only a super restricted set of tags and attributes
const clean = sanitizeHtml(dirty, {
allowedTags: [ 'b', 'i', 'em', 'strong', 'a' ],
allowedAttributes: {
'a': [ 'href' ]
},
allowedIframeHostnames: ['www.youtube.com']
});