# XSS(cross site scripting)
크로스 사이트 스크립트 변조(cross site scripting, xss)는 공격자가 상대방의 브라우저에 스크립트가 실행되도록 해 사용자의 세션을 가로채거나, 웹사이트를 변조하거나, 악의적 콘텐츠를 삽입하거나, 피싱 공격을 진행하는 것
예를 들어 검색어 에 스크립트 코드를 넣어서 악성 코드를 뿌린다던가..등등
nest 는 xss설정을 하는 방법 크게 2가지로 나눈다
1. 파이프
2. helmet 라이브러리 사용
파이프의 경우 필터, 인터셉트와 같은 기능 같지만 우선순위가 낮다.
helmet 라이브러리를 이용한 간단한 xss보안 필터 설정을 해보겠다
😎import
npm install helmet
모듈을 설치하고 나서 적용
* 파일이름 : main.ts
import { NestFactory } from '@nestjs/core'; import { NestExpressApplication } from '@nestjs/platform-express'; import { AppModule } from './app.module'; //import * as helmet from "helmet"; import helmet from "helmet"; async function bootstrap() { const app = await NestFactory.create<NestExpressApplication>(AppModule); app.use(helmet()); await app.listen(8080); } bootstrap();
app.use(helmet());
한줄로 간단하게 적용가능
헬멧은 아주 간단하면서도 사용이 쉬운(?) 보안프레임워크
좀더 세부적으로 사용하기 위해서는 아래처럼 사용하기도 한다.
* 파일이름 : main.ts
import { NestFactory } from '@nestjs/core'; import { NestExpressApplication } from '@nestjs/platform-express'; import { AppModule } from './app.module'; import * as helmet from "helmet"; async function bootstrap() { const app = await NestFactory.create<NestExpressApplication>(AppModule); app.use(helmet.contentSecurityPolicy()); app.use(helmet.crossOriginEmbedderPolicy()); app.use(helmet.crossOriginOpenerPolicy()); app.use(helmet.crossOriginResourcePolicy()); app.use(helmet.dnsPrefetchControl()); app.use(helmet.expectCt()); app.use(helmet.frameguard()); app.use(helmet.hidePoweredBy()); app.use(helmet.hsts()); app.use(helmet.ieNoOpen()); app.use(helmet.noSniff()); app.use(helmet.originAgentCluster()); app.use(helmet.permittedCrossDomainPolicies()); app.use(helmet.referrerPolicy()); app.use(helmet.xssFilter()); await app.listen(8080); } bootstrap();
728x90
반응형
'Back-end > Node-NestJS' 카테고리의 다른 글
ejs 문법 <%= 와 <%- 차이 (0) | 2022.12.09 |
---|---|
helmet 보안 xss 필터 추가 (0) | 2022.11.23 |
[Node/Nest] shell 글자 꾸미기 사용하여 큰 글씨 주석 달기 figlet (0) | 2022.09.14 |
[NestJS] 상황에 따른 logger level 분기 나누기 (0) | 2022.09.14 |
[NestJS] LOG에 요청 transation-id 추가하기 (0) | 2022.09.13 |
댓글