# Content Security Policy for Sirv

If your app or website has a Content Security Policy (CSP), this article explains how to ensure your Sirv content is served as expected.

Using an AI coding agent?

Install the [`sirv-media-viewer`](https://www.skills.sh/sirv/image-optimization-skill/sirv-media-viewer) skill, and your agent can add the viewer to your site. Ask in plain words, such as “Add a gallery with zoom and a [360 spin](/help/spin/getting-started/how-spin-files-are-created/) to the product page.” [See all 8 skills](/help/rest-api/sirv-skills-for-ai-agents/)

## What is a Content Security Policy?

CSP is a security protocol that controls what resources can be loaded and executed on a website.

The guidance on this page assumes that you are already aware of CSPs and either already have one or are adding one to your website.

If you’d like to learn more about CSP and how it works, here is a helpful [guide to CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP) by Mozilla.

## CSP rules for Sirv content

Certain rules should be added to your CSP, to ensure normal operation of your Sirv images, video streams and other assets.

These rules will allow for interaction with [Sirv Media Viewer](/help/sirv-media-viewer/overview/) galleries, zooms, 360 spins, [video playback](/help/sirv-media-viewer/media-types/video-streaming/) and user interaction stats for those assets.

Below is a set of example rules based on [helmet-csp](https://www.npmjs.com/package/helmet-csp), which is a Content Security Policy middleware for the Express app.

The example assumes that your server has been configured to respond with a Content-Security-Policy header. CSP rules:

```json
const csp = require("helmet-csp");

module.exports = csp({
  directives: {
    // These directives are necessary for Sirv embeds.

    childSrc: ['blob:'],

    connectSrc: [
      'blob:', // Used by Sirv Media Viewer
      'https://video.sirv.com', // Used for Sirv Video Player streams (HLS)
      'https://stats.sirv.com', // Spin stats POST beacons
      'https://your-account.sirv.com', // Your Sirv account domain, or your custom domain
    ],

    defaultSrc: [
      `'self'`,
      'https://scripts.sirv.com', // Sirv Media Viewer
    ],

    fontSrc: [
      'data:', // Used by Sirv Media Viewer
    ],

    frameSrc: [
      'https://your-account.sirv.com', // Your Sirv account domain, or your custom domain
    ],

    imgSrc: [
      `'self'`,
      'data:', // Used by Sirv Media Viewer
      'https://your-account.sirv.com', // Your Sirv account domain, or your custom domain
    ],

    mediaSrc: [
      `'self'`,
      'data:', // Used by Sirv Media Viewer
      'blob:', // Used by Sirv Video Player
      'https://video.sirv.com', // Used by Sirv Video Player
    ],

    scriptSrc: [
      `'self'`,
      `'unsafe-eval'`, // Used by Sirv Media Viewer
      'https://scripts.sirv.com', // Sirv Media Viewer
      'https://video.sirv.com', // Used for Sirv Video Player streams (HLS)
    ],

    styleSrc: [
      `'self'`,
      `'unsafe-inline'`, // Used by Sirv Media Viewer
      'https://scripts.sirv.com', // Sirv Media Viewer
    ],
  }
});
```

Change any references to [https://your-account.sirv.com](https://your-account.sirv.com) to your own sirv.com domain or your [custom domain](/help/getting-started/custom-domain/) if that’s where you’re referencing your video (for example a [full-width background video](/help/sirv-media-viewer/customization/full-width-background-video/)).

## Get help with CSP

Configuring a Content Security Policy is different from one site to the next. The example above is provided to guide you in the right direction.
