Skip to content
Merged
Changes from 2 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
78 changes: 40 additions & 38 deletions src/content/docs/ko/reference/experimental-flags/csp.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ 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) 공격에 대한 추가적인 보호를 제공합니다.
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