# Async Clipboard API and User Activation vs Content Security Policy Nonces and strict-dynamic

- **Canonical URL:** https://frontend.rocks/vs/async-clipboard-activation-vs-csp-nonces-strict-dynamic/
- **Relation:** Contrasts With
- **Last Verified:** 2026-11-15
- **Verdict:** Clipboard sanitization strips executable markup from pasted HTML rather than blocking scripts via CSP.

## Comparison Matrix

| Dimension | Async Clipboard API and User Activation | Content Security Policy Nonces and strict-dynamic |
| :--- | :--- | :--- |
| **Maturity** | Baseline · Widely | Baseline · Widely |
| **Domain** | Web APIs | Security & Accessibility |
| **Mental Model** | Promise-based OS clipboard access gated by HTTPS, document focus, and transient user activation tokens, supporting deferred Blob resolution via ClipboardItem. | HTTP-header script execution allowlist using per-response cryptographic nonces and 'strict-dynamic' trust propagation to block injected scripts without brittle domain allowlists. |
| **Prerequisites** | DOM Event Propagation (Capture, Target, Bubble) (Transient user activation is minted by trusted input events dispatching through the DOM.) | Preload Scanner and fetchpriority Attribute (The browser HTML parser and preload scanner evaluate script nonces before executing fetched scripts.) |
| **When Not to Use** | When not to use navigator.clipboard.readText(): Never poll clipboard contents on focus; it triggers intrusive browser permission prompts and erodes user trust. | When not to use CSP nonces: Static SPAs served from an immutable CDN without edge compute should use SHA-256 script hashes ('sha256-...') instead of nonces. |

## Async Clipboard API and User Activation — Under the Hood
Transient user activation behaves like a stamped museum entry ticket that dissolves after a few seconds: if you call `navigator.clipboard.write()` while holding the ticket, the browser keeps the turnstile open while your `Promise<Blob>` resolves.

1. **Activation Check**: Trusted pointer or keyboard events propagating through [DOM Event Propagation](/concepts/dom-event-propagation) set the frame's `transientActivation` timestamp.
2. **Deferred `ClipboardItem`**: Passing a `Promise<Blob>` inside `new ClipboardItem({ 'text/plain': promise })` lets `write()` claim the gesture synchronously before network I/O completes.
3. **Payload Sanitization**: Engines re-encode `image/png` and strip `<script>` tags from `text/html` on paste to neutralize OS-level parser exploits.

```js
button.addEventListener('click', () => {
  const textBlob = fetch('/api/share-link')
    .then((res) => res.text())
    .then((url) => new Blob([url], { type: 'text/plain' }));

  navigator.clipboard.write([new ClipboardItem({ 'text/plain': textBlob })]);
});
```

## Content Security Policy Nonces and strict-dynamic — Under the Hood
Domain-allowlist CSPs are like checking guest IDs only by hometown ("anyone from `*.googleapis.com` may enter"); `'nonce-...' 'strict-dynamic'` issues a single-use wristband at the door and lets badged guests escort their own sub-bundles inside.

1. **Header vs Parser**: Before the [Preload Scanner](/concepts/preload-scanner-hints) or JS engine runs a `<script>`, it verifies that the element's `nonce` attribute matches the HTTP response header token.
2. **Trust Propagation**: `'strict-dynamic'` lets a nonce-verified root bundle append dynamic `<script>` chunks (such as Vite/Next.js code-split bundles) without stamping every chunk URL, pairing cleanly with [Trusted Types](/concepts/dom-xss-trusted-types).
3. **Allowlist Bypass Closure**: When `'strict-dynamic'` is active, legacy host allowlists and `'unsafe-inline'` are ignored, closing JSONP and Angular-template bypasses on whitelisted CDNs.

```http
Content-Security-Policy:
  default-src 'self';
  script-src 'nonce-8fK2pQ9xL4mN7vR1' 'strict-dynamic';
  object-src 'none';
  base-uri 'none';
```

## Interactive Labs & Dissections
- [Async Clipboard API and User Activation Lab](https://frontend.rocks/concepts/async-clipboard-activation/#lab) ([Markdown](https://frontend.rocks/concepts/async-clipboard-activation.md))
- [Content Security Policy Nonces and strict-dynamic Lab](https://frontend.rocks/concepts/csp-nonces-strict-dynamic/#lab) ([Markdown](https://frontend.rocks/concepts/csp-nonces-strict-dynamic.md))

## Related Architecture Autopsies
- [Autopsy #11: Anatomy of a Supply-Chain DOM XSS & How Trusted Types Stop It](https://frontend.rocks/autopsies/third-party-script-xss-takeover/) ([Markdown](https://frontend.rocks/autopsies/third-party-script-xss-takeover.md)): Compromised third-party widget injects an inline script via an innerHTML sink and exfiltrates session tokens.

## Primary Sources
- https://developer.mozilla.org/en-US/docs/Web/API/Clipboard_API
- https://w3c.github.io/clipboard-apis/
- https://developer.mozilla.org/en-US/docs/Web/HTTP/Guides/CSP
- https://w3c.github.io/webappsec-csp/
