---
title: "ContentSecurityPolicy"
source: "https://github.com/remix-run/remix/blob/remix@3.2.0/packages/headers/src/lib/content-security-policy.ts#L61"
---

# ContentSecurityPolicy

## Summary

A single Content Security Policy, independent of routing and nonce generation.
Comma-separated policy lists must be handled as separate policies.

## Signature

```ts
class ContentSecurityPolicy {
  constructor(
    init: string | ContentSecurityPolicyInit | ContentSecurityPolicy,
  ): ContentSecurityPolicy

  // Methods
  delete(name: string): void
  get(name: string): string[] | undefined
  set(name: string, values: readonly string[]): void
  toString(): string
  from(
    value: string | ContentSecurityPolicyInit | ContentSecurityPolicy | null,
  ): ContentSecurityPolicy
}

```

## Methods

### `delete(name: string): void`

Removes a directive by its case-insensitive, hyphenated name.

#### Parameters

##### `name`

Directive to remove.

### `get(name: string): string[] | undefined`

Reads a directive by its case-insensitive, hyphenated name.

#### Parameters

##### `name`

Directive name, such as `script-src`.

### `set(name: string, values: readonly string[]): void`

Sets a directive, including extension directives. Tokens cannot contain whitespace or delimiters.
`report-to` requires exactly one HTTP token naming a reporting endpoint.

#### Parameters

##### `name`

Case-insensitive, hyphenated directive name.

##### `values`

Individual CSP tokens; an empty array emits a valueless directive.

### `toString(): string`

Serializes the policy without changing directive values or merging policies.



### `from(value: string | ContentSecurityPolicyInit | ContentSecurityPolicy | null): ContentSecurityPolicy`

Parses or copies a single policy.

#### Parameters

##### `value`

Serialized policy, directive object, existing policy, or null.