class

Marten::HTTP::ContentSecurityPolicy

Inherits Reference / Object

Represents a Content-Security-Policy response header.

This class can be leveraged to configure the value of the HTTP Content-Security-Policy response header and enhance protection against cross-site scripting (XSS) and injection attacks.

policy = Marten::HTTP::ContentSecurityPolicy.new do |csp|
  csp.default_src = {:self, "example.com"}
end

policy.build # => "default-src 'self' example.com"

Constructors

new(directives : Hash(String, Array(String) | Bool))
Source

Instance methods

base_uri=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the base-uri directive or remove it (if a nil value is specified).

Source
block_all_mixed_content=(enabled : Bool)
Source
build(nonce : String | Nil = nil, nonce_directives : Array(String) | Nil = nil)
Source
child_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the child-src directive or remove it (if a nil value is specified).

Source
clone
Source
connect_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the connect-src directive or remove it (if a nil value is specified).

Source
default_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the default-src directive or remove it (if a nil value is specified).

Source
directives

Returns the policy directives.

Source
font_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the font-src directive or remove it (if a nil value is specified).

Source
form_action=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the form-action directive or remove it (if a nil value is specified).

Source
frame_ancestors=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the frame-ancestors directive or remove it (if a nil value is specified).

Source
frame_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the frame-src directive or remove it (if a nil value is specified).

Source
img_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the img-src directive or remove it (if a nil value is specified).

Source
manifest_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the manifest-src directive or remove it (if a nil value is specified).

Source
media_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the media-src directive or remove it (if a nil value is specified).

Source
object_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the object-src directive or remove it (if a nil value is specified).

Source
plugin_types=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the plugin-types directive or remove it (if a nil value is specified).

Source
prefetch_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the prefetch-src directive or remove it (if a nil value is specified).

Source
report_to=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the report-to directive or remove it (if a nil value is specified).

Source
report_uri=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the report-uri directive or remove it (if a nil value is specified).

Source
require_sri_for=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the require-sri-for directive or remove it (if a nil value is specified).

Source
sandbox=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the sandbox directive or remove it (if a nil value is specified).

Source
script_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the script-src directive or remove it (if a nil value is specified).

Source
script_src_attr=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the script-src-attr directive or remove it (if a nil value is specified).

Source
script_src_elem=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the script-src-elem directive or remove it (if a nil value is specified).

Source
style_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the style-src directive or remove it (if a nil value is specified).

Source
style_src_attr=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the style-src-attr directive or remove it (if a nil value is specified).

Source
style_src_elem=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the style-src-elem directive or remove it (if a nil value is specified).

Source
upgrade_insecure_requests=(enabled : Bool)
Source
worker_src=(value : Array | Nil | String | Symbol | Tuple)

Allows to set the worker-src directive or remove it (if a nil value is specified).

Source