Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 42 additions & 40 deletions src/content/docs/ko/reference/experimental-flags/csp.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
---
title: 실험적 콘텐츠 보안 정책
title: 실험적 콘텐츠 보안 정책 (CSP)
sidebar:
label: 콘텐츠 보안 정책
i18nReady: true
Expand All @@ -12,16 +12,16 @@ import Since from '~/components/Since.astro'

<p>

**타입:** `boolean | object`<br />
**기본값:** `false`<br />
<Since v="5.9.0" />
**타입:** `boolean | object`<br />
**기본값:** `false`<br />
<Since v="5.9.0" />
</p>

[콘텐츠 보안 정책 (CSP)](https://developer.mozilla.org/ko/docs/Web/HTTP/Guides/CSP) 지원을 활성화하여 문서가 로드할 수 있는 리소스를 제어함으로써 특정 유형의 보안 위협을 최소화합니다. 이는 [교차 사이트 스크립팅 (XSS)](https://developer.mozilla.org/ko/docs/Glossary/Cross-site_scripting) 공격에 대한 추가적인 보호를 제공합니다.

이 기능을 활성화하면 기본적으로 **Astro에 의해 처리되고 번들링된 스크립트 및 스타일에** 추가 보안이 적용되며, 이러한 콘텐츠 유형과 추가적인 콘텐츠 유형을 더욱 세밀하게 구성할 수 있습니다.

이 실험적인 CSP 기능에는 몇 가지 제한 사항이 있습니다. 인라인 스크립트는 기본적으로 지원되지 않지만, 외부 및 인라인 스크립트에 [자체 해시를 제공](#hashes)할 수 있습니다. 또한 `<ClientRouter />`를 사용하는 [Astro의 뷰 전환](/ko/guides/view-transitions/)은 아직 완전히 지원되지 않습니다. 다른 페이지로 이동할 때 일부 스타일이 적용되지 않거나 일부 스크립트가 실행되지 않을 수 있습니다.
이 실험적인 CSP 기능에는 몇 가지 제한 사항이 있습니다. 인라인 스크립트는 기본적으로 지원되지 않지만, 외부 및 인라인 스크립트에 [자체 해시를 제공](#hashes)할 수 있습니다. `<ClientRouter />`를 사용하는 [Astro의 뷰 전환](/ko/guides/view-transitions/)은 지원되지 않습니다. 하지만 Astro를 사용하여 네이티브 뷰 전환 및 탐색 API를 향상시키지 않는 경우, [브라우저의 네이티브 뷰 전환 API로 마이그레이션하는 것을 고려](https://events-3bg.pages.dev/jotter/astro-view-transitions/)할 수 있습니다.

:::note
Vite 개발 서버의 특성상, `dev` 모드에서 작업하는 동안에는 이 기능이 지원되지 않습니다. 대신 `build` 및 `preview`를 사용하면 Astro 프로젝트에서 이 기능을 테스트할 수 있습니다.
Expand Down Expand Up @@ -86,7 +86,7 @@ export default defineConfig({

<p>

**타입:** `CspDirective[]` <br />
**타입:** `CspDirective[]`<br />
**기본값:** `[]`<br />
<Since v="5.9.0" />
</p>
Expand All @@ -103,7 +103,7 @@ export default defineConfig({
csp: {
directives: [
"default-src 'self'",
"image-src 'self' 'https://images.cdn.example.com'"
"img-src 'self' 'https://images.cdn.example.com'"
]
}
}
Expand All @@ -117,18 +117,18 @@ export default defineConfig({
http-equiv="content-security-policy"
content="
default-src 'self';
image-src 'self' 'https://images.cdn.example.com';
img-src 'self' 'https://images.cdn.example.com';
script-src 'self' 'sha256-somehash';
style-src 'self' 'sha256-somehash';
"
>
```

### `styleDirective` and `scriptDirective`
### `styleDirective` `scriptDirective`

<p>

**타입:** `object` <br />
**타입:** `object`<br />
**기본값:** `{}`<br />
<Since v="5.9.0" />
</p>
Expand All @@ -141,7 +141,7 @@ export default defineConfig({

<p>

**타입:** `string[]` <br />
**타입:** `string[]`<br />
**기본값:** `[]`<br />
<Since v="5.9.0" />
</p>
Expand Down Expand Up @@ -192,7 +192,7 @@ export default defineConfig({

<p>

**타입:** `CspHash[]` <br />
**타입:** `CspHash[]`<br />
**기본값:** `[]`<br />
<Since v="5.9.0" />
</p>
Expand Down Expand Up @@ -234,8 +234,8 @@ export default defineConfig({
<meta
http-equiv="content-security-policy"
content="
script-src 'self' 'sha256-generatedByAstro' 'sha384-scriptHash' 'sha512-scriptHash' 'sha256-scriptHash';
style-src 'self' 'sha256-generatedByAstro' 'sha384-styleHash' 'sha512-styleHash' 'sha256-styleHash';
script-src 'self' 'sha384-scriptHash' 'sha512-scriptHash' 'sha256-scriptHash' 'sha256-generatedByAstro';
style-src 'self' 'sha384-styleHash' 'sha512-styleHash' 'sha256-styleHash' 'sha256-generatedByAstro';
"
>
```
Expand All @@ -244,7 +244,7 @@ export default defineConfig({

<p>

**타입:** `boolean` <br />
**타입:** `boolean`<br />
**기본값:** `false`<br />
<Since v="5.9.0" />
</p>
Expand All @@ -264,34 +264,36 @@ export default defineConfig({
}
});
```

## 런타임 API

`.astro` 컴포넌트의 런타임 API (`Astro` global을 통해 사용 가능) 또는 엔드포인트 및 미들웨어의 `APIContext` 타입을 통해 페이지별 `<meta>` 요소를 사용자 정의할 수 있습니다.

### `addDirective`
### `insertDirective`

<p>
**타입:** `(directive: CspDirective) => void`<br />
<Since v="5.9.0" />

**타입:** `(directive: CspDirective) => void`<br />
<Since v="5.9.0" />
</p>

현재 페이지에 하나의 지시어를 추가합니다. 이 메서드를 여러 번 호출하여 여러 지시어를 추가할 수도 있습니다.

```astro
---
Astro.addDirective("default-src 'self'");
Astro.addDirective("img-src 'self' 'https://images.cdn.example.com'");
Astro.insertDirective("default-src 'self'");
Astro.insertDirective("img-src 'self' 'https://images.cdn.example.com'");
---
```

빌드 후, 이 페이지의 `<meta>` 요소는 포함된 `style-src` 및 `script-src` 지시어에 새로운 지시어를 추가합니다.
빌드 후, 이 페이지의 `<meta>` 요소는 기존 `script-src` 및 `style-src` 지시어와 추가 지시어를 함께 배치합니다.

```html
<meta
http-equiv="content-security-policy"
content="
default-src 'self';
image-src 'self' 'https://images.cdn.example.com';
img-src 'self' 'https://images.cdn.example.com';
script-src 'self' 'sha256-somehash';
style-src 'self' 'sha256-somehash';
"
Expand All @@ -301,15 +303,16 @@ Astro.addDirective("img-src 'self' 'https://images.cdn.example.com'");
### `insertStyleResource`

<p>
**타입:** `(resource: string) => void`<br />
<Since v="5.9.0" />

**타입:** `(resource: string) => void`<br />
<Since v="5.9.0" />
</p>

`style-src` 지시어에 사용할 새 리소스를 삽입합니다.

```astro
---
Astro.insertStyleResource("'https://styles.cdn.example.com'");
Astro.insertStyleResource("https://styles.cdn.example.com");
---
```

Expand All @@ -325,19 +328,19 @@ Astro.insertStyleResource("'https://styles.cdn.example.com'");
>
```


### `addStyleHash`
### `insertStyleHash`

<p>
**타입:** `(hash: CspHash) => void`<br />
<Since v="5.9.0" />

**타입:** `(hash: CspHash) => void`<br />
<Since v="5.9.0" />
</p>

`style-src` 지시어에 새 해시를 추가합니다.

```astro
---
Astro.addStyleHash("sha512-styleHash");
Astro.insertStyleHash("sha512-styleHash");
---
```

Expand All @@ -353,20 +356,19 @@ Astro.addStyleHash("sha512-styleHash");
>
```


### `insertScriptResource`

<p>
**타입:** `(resource: string) => void`<br />
<Since v="5.9.0" />

**타입:** `(resource: string) => void`<br />
<Since v="5.9.0" />
</p>

`script-src` 지시어에 사용할 새 유효한 소스를 삽입합니다.


```astro
---
Astro.insertScriptResource("'https://scripts.cdn.example.com'");
Astro.insertScriptResource("https://scripts.cdn.example.com");
---
```

Expand All @@ -382,19 +384,19 @@ Astro.insertScriptResource("'https://scripts.cdn.example.com'");
>
```

### `addScriptHash`
### `insertScriptHash`

<p>
**타입:** `(hash: CspHash) => void`<br />
<Since v="5.9.0" />

**타입:** `(hash: CspHash) => void`<br />
<Since v="5.9.0" />
</p>

`script-src` 지시어에 새 해시를 추가합니다.


```astro
---
Astro.addScriptHash("sha512-scriptHash");
Astro.insertScriptHash("sha512-scriptHash");
---
```

Expand Down