---
title: "CORS and Security Attributes · Nuxt Scripts"
description: "Configure cross-origin credentials, referrer policy, and integrity checks for scripts."
canonical_url: "https://scripts.nuxt.com/docs/guides/cors"
meta:
  "og:description": "Configure cross-origin credentials, referrer policy, and integrity checks for scripts."
  "og:image": "https://scripts.nuxt.com/_og/s/o_96588d1fa7cf925c.png"
  "og:image:height": "600"
  "og:image:type": image/png
  "og:image:width": "1200"
  "og:title": "CORS and Security Attributes · Nuxt Scripts"
  "twitter:image": "https://scripts.nuxt.com/_og/s/o_96588d1fa7cf925c.png"
---

> Index of every page on this site: [llms.txt](https://scripts.nuxt.com/llms.txt)

**Guides**

# **CORS and Security Attributes**

[Copy for LLMs](https://scripts.nuxt.com/docs/guides/cors.md)

## Background

When loading scripts from external domains, the script element's [`**crossorigin**`** setting**](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Attributes/crossorigin) determines whether the browser uses Cross-Origin Resource Sharing (CORS). For third-party scripts, this affects:

- Whether the browser sends cookies with requests
- Access to error details for debugging
- Subresource Integrity (SRI) validation

## Default Behavior

Nuxt Scripts applies privacy-focused defaults to cross-origin scripts:

```html
<script
  src="https://example.com/script.js"
  crossorigin="anonymous"
  referrerpolicy="no-referrer"
></script>
```

The attributes have separate effects:

- **`**crossorigin="anonymous"**`**: Prevents the script request from sending cross-origin credentials, including cookies
- **[`**referrerpolicy="no-referrer"**`](https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Referrer-Policy)**: Prevents sharing the page URL with third-party servers

Some vendor scripts require cookies or referrer information, so these defaults are not compatible with every endpoint.

## Common CORS Errors

### Script Fails to Load

```text
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource
```

This occurs when a server doesn't return an appropriate `**Access-Control-Allow-Origin**` header but `**crossorigin="anonymous"**` is set. Some third-party scripts don't support CORS.

### Script Loads but Functions Fail

The script loads but functionality is broken because it expected cookies or session data.

### Error Details Hidden

```js
window.onerror = msg => console.log(msg)
// Shows: "Script error." instead of actual error
```

Without `**crossorigin**`, browsers hide error details from external scripts for security.

## Configuring CORS Attributes

### Per-Script Configuration

Disable CORS attributes for scripts that don't support them:

```ts
useScript({
  src: 'https://example.com/script.js',
  crossorigin: false, // Remove crossorigin attribute
  referrerpolicy: false, // Remove referrerpolicy attribute
})
```

Or use a different `**crossorigin**` value:

```ts
useScript({
  src: 'https://example.com/script.js',
  crossorigin: 'use-credentials', // Send cookies with request
})
```

The `**crossorigin**` and `**referrerpolicy**` fields are script input attributes, so configure them per script. They are not part of `**defaultScriptOptions**`.

## Crossorigin Values

| **Value** | **Cross-origin credentials** | **Error details** | **Use case** |
| --- | --- | --- | --- |
| `**anonymous**` | Not sent | Available if the server allows the origin | Privacy-focused default |
| `**use-credentials**` | The browser sends them if its policy allows | Available if the server allows credentials and the requesting origin | Scripts requiring authentication |
| `**false**` | Browser cookie policy determines whether to send them | Hidden | Scripts without CORS support |

## Registry Scripts

Some registry definitions disable `**crossorigin**` for compatibility with their vendors:

```ts
const config = {
  scriptInput: {
    src: 'https://js.stripe.com/basil/stripe.js',
    crossorigin: false,
    referrerpolicy: false,
  }
}
```

Scripts with `**crossorigin: false**` include:

- Stripe
- YouTube Player
- Usercentrics
- Ahrefs Web Analytics
- Google Sign-In
- Google reCAPTCHA
- Meta Pixel
- TikTok Pixel
- X (Twitter) Pixel
- Snapchat Pixel
- LinkedIn Insight Tag
- Cloudflare Web Analytics
- Lemon Squeezy
- Calendly
- Matomo Analytics
- Bing UET

If a registry script fails at the network layer, inspect these attributes alongside the response's CORS headers.

## Subresource Integrity

For cross-origin resources, [**Subresource Integrity requires a CORS check**](https://developer.mozilla.org/en-US/docs/Web/Security/Defenses/Subresource_Integrity). When using [**bundled scripts with SRI**](https://scripts.nuxt.com/docs/api/nuxt-config#assetsintegrity), Nuxt adds `**crossorigin="anonymous"**` automatically:

nuxt.config.ts

```ts
export default defineNuxtConfig({
  scripts: {
    assets: {
      integrity: true, // Automatically sets crossorigin="anonymous"
    }
  }
})
```

## Troubleshooting

### Script Won't Load

1. Check the browser console for CORS errors
2. Set `**crossorigin: false**` to disable CORS mode
3. Verify the third-party server supports CORS headers

### Script Loads but Broken

1. The script may require cookies; try `**crossorigin: 'use-credentials'**`
2. The script may need the referrer; set `**referrerpolicy: false**`
3. Check if the script expects you to load it without CORS attributes

### Debugging External Script Errors

To see full error messages from external scripts:

1. Ensure the script has `**crossorigin="anonymous"**`
2. Verify that the server returns an appropriate `**Access-Control-Allow-Origin**` header
3. If the server doesn't support CORS, you won't get detailed errors

### Bundling as an alternative

[**Bundling the script**](https://scripts.nuxt.com/docs/guides/first-party) moves the initial request to your own domain, where it no longer needs cross-origin script handling.

[Edit this page](https://github.com/nuxt/scripts/edit/main/docs/content/1.guides/6.cors.md)

[Markdown For LLMs](https://scripts.nuxt.com/docs/guides/cors.md)

[**Facade Components** Facade components are placeholder UI elements that get replaced once a third-party script loads.](https://scripts.nuxt.com/docs/guides/facade-components) [**useScript()** Load and control third-party scripts with Nuxt-specific options.](https://scripts.nuxt.com/docs/api/use-script)

**On this page **

- [Background](#background)
- [Default Behavior](#default-behavior)
- [Common CORS Errors](#common-cors-errors)
- [Configuring CORS Attributes](#configuring-cors-attributes)
- [Crossorigin Values](#crossorigin-values)
- [Registry Scripts](#registry-scripts)
- [Subresource Integrity](#subresource-integrity)
- [Troubleshooting](#troubleshooting)

```json
{"@context":"https://schema.org","@graph":[{"@id":"https://scripts.nuxt.com/#website","@type":"WebSite","description":"Nuxt Scripts lets you load third-party scripts with better performance, privacy, security and DX. It includes many popular third-parties out of the box.","name":"Nuxt Scripts","url":"https://scripts.nuxt.com/","publisher":{"@id":"https://scripts.nuxt.com/#identity"}},{"@id":"https://scripts.nuxt.com/docs/guides/cors#webpage","@type":"WebPage","description":"Configure cross-origin credentials, referrer policy, and integrity checks for scripts.","name":"CORS and Security Attributes","url":"https://scripts.nuxt.com/docs/guides/cors","breadcrumb":{"@id":"https://scripts.nuxt.com/docs/guides/cors#breadcrumb"},"isPartOf":{"@id":"https://scripts.nuxt.com/#website"},"potentialAction":[{"@type":"ReadAction","target":["https://scripts.nuxt.com/docs/guides/cors"]}],"primaryImageOfPage":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/#identity","@type":"Organization","name":"Nuxt Scripts","url":"https://scripts.nuxt.com","logo":{"@id":"https://scripts.nuxt.com/#logo"}},{"@id":"https://scripts.nuxt.com/docs/guides/cors#breadcrumb","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","name":"Nuxt Scripts","item":"https://scripts.nuxt.com/","position":1},{"@type":"ListItem","name":"Documentation","item":"https://scripts.nuxt.com/docs","position":2},{"@type":"ListItem","name":"Guides","item":"https://scripts.nuxt.com/docs/guides","position":3},{"@type":"ListItem","name":"CORS and Security Attributes","item":"https://scripts.nuxt.com/docs/guides/cors","position":4}]},{"@id":"https://scripts.nuxt.com/#logo","@type":"ImageObject","caption":"Nuxt Scripts","contentUrl":"https://scripts.nuxt.com/logo.svg","inLanguage":"en","url":"https://scripts.nuxt.com/logo.svg"}]}
```

## Sitemap

See the full [sitemap](https://scripts.nuxt.com/sitemap.md) for all pages.
