Configure a content security policy

You're viewing Apigee Edge documentation.
Go to the Apigee X documentation.

Configure a content security policy (CSP) for all pages in your portal to protect against cross-site scripting (XSS) and other code-injection attacks. The CSP defines trusted sources for content such as scripts, styles, and images. After configuring a policy, content loaded from untrusted sources will be blocked by your browser.

The CSP is added as a Content-Security-Policy HTTP response header to all pages in your portal, as follows:

Content-Security-Policy: policy

You define the policy using directives, as defined in Content Security Policy Directives in the W3C site.

If you enable the CSP header, by default the following CSP directive is defined:

default-src 'unsafe-eval' 'unsafe-inline' * data:

The default-src directive configures the default policy for resource types that do not have a configured directive.

The following table describes the policies defined as part of the default directive.

Policy Access
'unsafe-inline' Inline resources, such as inline <script> elements, javascript: URLs, inline event handlers, and inline <style> elements. Note: You must enclose the policy in single quotes.
'unsafe-eval' Unsafe dynamic code evaluation such as JavaScript eval() and similar methods used to create code from strings. Note: You must enclose the policy in single quotes.
* (wildcard) Any URL except data:, blob:, and filesystem: schemes.
data: Resources loaded via the data scheme (for example, Base64-encoded images).

The following provides examples of configuring the CSP to restrict specific resource types.

Policy Access
default-src 'none' No access for resource types that do not have a configured directive.
img-src * Image URL from any source.
media-src Video or audio URL over HTTPS from the domain.
script-src * Execution of any script from a subdomain of
style-src 'self' Application of any style from the site's origin or the domain.

To configure a content security policy:

  1. Select Publish > Portals and select your portal.
  2. Select Settings in the drop-down menu in the top navigation bar.
  3. Alternatively, click Settings on the portal landing page.
  4. Click the Security tab.
  5. Click Enable content security policy.
  6. Configure the CSP or leave the default.
  7. Click Save.

You can restore the default CSP policy at any time by clicking Restore default.