helmet.js 모듈

sprinkler dev·2021년 9월 29일
0
post-thumbnail

helmet.js?

HTTP 헤더 설정을 자동으로 바꾸어 몇가지 잘 알려진 취약점으로 부터 앱을 보호할 수 있는 패키지

설치 방법

$ yarn add helmet @types/helmet
또는
$ npm install helmet @types/helmet

사용 예시

import helmet from 'helmet';

// 기본 11개 미들웨어 사용
app.use(helmet());

// helmet.frameguard를 제외한 기본 10개 미들웨어 사용
app.use(
  helmet({
    frameguard: false,
  })
);

기본으로 사용하는 미들웨어

  • crossOriginEmbedderPolicy, crossOriginOpenerPolicy, crossOriginResourcePolicy, originAgentCluster 네가지를 제외한 11개 미들웨어를 기본으로 사용함

사용가능한 미들웨어

helmet.contentSecurityPolicy(options) : XSS(Cross site scripting) 공격 및 기타 교차 사이트 인젝션 예방

helmet.crossOriginEmbedderPolicy() : Cross-Origin-Embedder-Policy 헤더를 require-corp로 설정

helmet.crossOriginOpenerPolicy() : Cross-Origin-Opener-Policy 헤더를 설정

helmet.crossOriginResourcePolicy() : Cross-Origin-Resource-Policy 헤더를 설정

helmet.expectCt(options) : Expect-CT 헤더를 설정하여 SSL 인증서 오발급을 예방

helmet.referrerPolicy(options) : Referrer-Policy 헤더를 설정하여 민감한 정보 유출 예방

helmet.hsts(options) : Strict-Transport-Security 헤더를 설정하여 보안연결(HTTPS) 강제

helmet.noSniff() : X-Content-Type-Options 헤더를 nosniff로 설정하여 MIME 스니핑 예방

helmet.originAgentCluster() : Origin-Agent-Cluster 헤더를 설정하여 오리진간 문서를 별도 에이전트 클러스터로 분리

helmet.dnsPrefetchControl(options) : X-DNS-Prefetch-Control 헤더를 설정하여 DNS 프리패칭을 조절

helmet.ieNoOpen() : X-Download-Options 헤더를 설정하여 ie8 이상에서만 사용할 수 있도록 함

helmet.frameguard(options) : X-Frame-Options 헤더를 설정하여 clickjacking 공격을 예방

helmet.permittedCrossDomainPolicies(options) : X-Permitted-Cross-Domain-Policies 헤더를 설정하여 크로스도메인 컨텐츠 정책을 설정

helmet.hidePoweredBy() : X-Powered-By 헤더를 제거하여 웹앱의 프레임워크를 특정할 수 없도록 함

helmet.xssFilter() : X-XSS-Protection 헤더를 0으로 설정하여 크로스사이트 스크립트를 이용한 공격을 예방

profile
2년차 백엔드 개발자

0개의 댓글