# 콘텐츠 보안 정책(CSP) (content-security-policy)

> 엄격한 CSP 헤더를 점검·적용하고 HTML 정제와 Trusted Types를 함께 써서 XSS와 주입을 막습니다.

- 카테고리: [보안 강화](https://www.myskills.tools/ko/categories/hardening/)
- 출처: 커뮤니티 · David Dias
- 저장소: https://github.com/thedaviddias/Front-End-Checklist/tree/main/skills/content-security-policy (commit 4b0ddb9)
- SKILL.md: https://github.com/thedaviddias/Front-End-Checklist/blob/main/skills/content-security-policy/SKILL.md
- 설치 명령: `npx skills add thedaviddias/Front-End-Checklist --skill content-security-policy`
- 라이선스: MIT
- 호환 도구: Any SKILL.md agent
- 권한: read-repo ✓, write-files ✓, shell ✗, network ✓
- 상태: 스캔 통과
- 규칙 스캔으로 모든 위험을 찾을 수는 없습니다. 설치 전에 이 스킬의 SKILL.md를 읽고 권한을 확인하세요.

## 핵심 규칙

CSP는 피해 범위를 줄일 뿐 출력 인코딩과 HTML 정제를 대신하지 않습니다.

## 실행 단계

1. **현황 확인** — CSP 헤더 유무와 지시어를 확인하고 innerHTML, dangerouslySetInnerHTML 같은 주입 지점을 검토합니다.
2. **먼저 보고 전용** — 먼저 Content-Security-Policy-Report-Only로 시험하고 위반 보고를 모아 사이트가 깨지지 않게 합니다.
3. **정책 강화** — 엄격한 default-src에서 시작해 필요한 출처만 허용하고, 인라인 스크립트는 nonce나 hash를 쓰며 unsafe-inline·unsafe-eval을 피합니다.
4. **운영 유사 환경에서 검증** — 운영에 가까운 환경에서 실제 응답을 확인하고, 큰 앱은 Trusted Types를 심층 방어로 추가합니다.

## 권한 설명 (SKILL.md 기준)

| 기능 | 필요 여부 | 설명 |
|---|---|---|
| 파일 쓰기 | 필요 | CSP 헤더를 설정하도록 서버나 프레임워크 설정을 수정하고 주입 지점에 정제 로직을 추가합니다. |
| 명령 실행 | 필요 없음 | 특정 명령 실행을 요구하지 않습니다. |
| 네트워크 송신 | 일부 필요 | 대상 사이트의 실제 응답 헤더를 확인하기 위해서만 접근합니다. |

## SKILL.md 프런트매터(YAML)

```yaml
---
name: content-security-policy
description: "Use when reviewing headers, forms, cookies, or third-party integrations related to Implement a content security policy. Validate the effective browser and HTTP behavior in a production-like environment."
metadata:
  category: security
  priority: high
  difficulty: advanced
  estimatedTime: "45"
  source: frontendchecklist.io
  url: https://frontendchecklist.io/rules/security/content-security-policy
---
```

홈: https://www.myskills.tools/ko/ · URL: https://www.myskills.tools/ko/skills/content-security-policy/
