# GTM 스크립트가 아닌 경우 서버 측에서 생성된 CSP nonce를 가져올 수 있는 옵션이 있나요?

**URL:** https://meta.discourse.org/t/is-there-an-option-to-get-server-side-generated-csp-nonce-for-non-gtm-scripts/230904
**Category:** Support
**Tags:** pr-welcome
**Created:** [6월 23, 2022, 2:04오후 UTC](https://meta.discourse.org/t/is-there-an-option-to-get-server-side-generated-csp-nonce-for-non-gtm-scripts/230904 "2022-06-23T14:04:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![kuba.bomba](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuba.bomba/32/264646_2.png) [@kuba.bomba](https://meta.discourse.org/u/kuba.bomba)
#### Post date: [6월 23, 2022, 2:04오후 UTC](https://meta.discourse.org/t/is-there-an-option-to-get-server-side-generated-csp-nonce-for-non-gtm-scripts/230904/1 "2022-06-23T14:04:11Z")

</div>

안녕하세요,

[nonce를 gtm에 생성](https://meta.discourse.org/t/using-nonces-in-google-tag-manager-scripts/188296)하는 깔끔한 방법이 있다는 것을 확인했습니다. GTM 컨테이너를 설치하지 않고 nonce를 DOM에 추가할 수 있는 방법이 있을까요? 스크립트에 unsafe-inline을 사용하는 것을 피하고 싶습니다.

---

<div class="post-metadata">

### Author: ![pmusaraj](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/pmusaraj/32/119489_2.png) [@pmusaraj](https://meta.discourse.org/u/pmusaraj)
#### Post date: [6월 23, 2022, 2:19오후 UTC](https://meta.discourse.org/t/is-there-an-option-to-get-server-side-generated-csp-nonce-for-non-gtm-scripts/230904/2 "2022-06-23T14:19:09Z")

</div>

좋은 질문입니다. 기술적으로 GTM이 설치되었든 아니든 상관없이 nonce를 포함해야 할 이유가 없다고 봅니다.

#pr-welcome으로 표시합니다.

---

<div class="post-metadata">

### Author: ![j127](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/j127/32/79093_2.png) [@j127](https://meta.discourse.org/u/j127)
#### Post date: [7월 6, 2022, 12:42오전 UTC](https://meta.discourse.org/t/is-there-an-option-to-get-server-side-generated-csp-nonce-for-non-gtm-scripts/230904/3 "2022-07-06T00:42:28Z")

</div>

CSP nonce를 사용하면 Cloudflare의 문제도 우회하는 데 도움이 될 것입니다.

Cloudflare의 Super Bot Fight Mode는 인라인 스크립트를 주입하며, 문서에서는 nonce 사용을 언급하고 있습니다:

> **[JavaScript Detections](https://developers.cloudflare.com/cloudflare-challenges/challenge-types/javascript-detections/)**
>
> Client-side JavaScript challenges that run on every request to identify automated traffic.

제 사이트에서 발생하는 오류는 다음과 같습니다: “해시, nonce 또는 'unsafe-inline’가 Content Security Policy의 script-src 지시문에 포함되어 있지 않아 스크립트 실행이 거부되었습니다.”

---

<div class="post-metadata">

### Author: ![sam](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/sam/32/102149_2.png) [@sam](https://meta.discourse.org/u/sam)
#### Post date: [7월 7, 2022, 6:00오전 UTC](https://meta.discourse.org/t/is-there-an-option-to-get-server-side-generated-csp-nonce-for-non-gtm-scripts/230904/4 "2022-07-07T06:00:22Z")

</div>

우리의 스플래시 스크린 구현은 이미 CSP nonce를 사용하며, @Johani가 이를 구축했습니다.

GTM이나 superbot에서 비슷한 것을 작동시키는 것은 아마도 꽤 실현 가능할 것입니다.

---

<div class="post-metadata">

### Author: ![kuba.bomba](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/kuba.bomba/32/264646_2.png) [@kuba.bomba](https://meta.discourse.org/u/kuba.bomba)
#### Post date: [7월 27, 2022, 1:31오후 UTC](https://meta.discourse.org/t/is-there-an-option-to-get-server-side-generated-csp-nonce-for-non-gtm-scripts/230904/5 "2022-07-27T13:31:23Z")

</div>

실제로… 제 `unsafe-inline`가 갑자기 작동하지 않게 됐어요. 뭔가 깨지는 변경 사항이 들어간 건가요? 콘솔에 이런 메시지가 뜨네요:

```plaintext
Note that 'unsafe-inline' is ignored if either a hash or nonce value is present in the source list

```

아무것도 변경하지 않았는데, 스플래시 화면의 nonce 때문인 걸까요? 😕

그 일 때문에 웹 분석 데이터 한 달치를 잃어버렸어요…
