util.addCSP()

Append Content-Security-Policy values to the response file.

Syntax

util.addCSP() util.addCSP(cspRelPath string) util.addCSP(response File, cspRelPath string)

Parameters

cspRelPath string

Reference the .ContentSecurityPolicy file by a path relative to the current source file. Defaults to ../.ContentSecurityPolicy.

response File

By default, the response file associated with the execution environment is used. You can override it and pass in a file yourself, which is useful when testing.

Description

Append Content-Security-Policy values to the response file.

It is stored in the content-security-policy string attribute.

When no parameters are provided, it will find the Content-Security-Policy rules in the body of a file named .ContentSecurityPolicy next to the currently executed source file.

Examples

Most common usage. This example will fail because the source file in this sandbox is //example.com, so we can’t create a .ContentSecurityPolicy file next to it.

You can use this format your code though.

Reference by path.

Pass in custom response file.