Skip to Content
Suffering builds character

7.디렉티브 예시

1-1. script-src 디렉티브

HTTP 응답 헤더에 다음과 같은 옵션을 추가함으로써 특정 도메인(https://trustedscripts.example.com)에서 다운받는 리소스는 신뢰할 수 있는 리소스라고 명시할 수 있음

HTTP Header
Content-Security-Policy: script-src https://trustedscripts.example.com

반대로 script-src 디렉티브에 선언된 것 이외의 다른 소스에서 스크립트를 로드하려는 시도는 사용자 에이전트(주로 브라우저)에 의해 차단됨

1-2. report-url 디렉티브

다음과 같이 report-uri 디렉티브에 특정 도메인을 선언할 경우, 사용자 에이전트는 해당 URL로 위반 내역을 보고함

HTTP Header
Content-Security-Policy: script-src https://trustedscripts.example.com; report-uri /csp-report-endpoint/

이러한 위반 내역 리포트는 표준 JSON 포맷으로, 별도의 지시어로 정책을 설정하지 않는 한, 브라우저는 기본적으로 모든 출처에서 연결된 리소스들을 로드하게 됨

CSP 참고 옵션

Last updated on