class Amber::Configuration::SecurityHeadersConfig

Overview

Holds the response header values that Amber::Pipe::SecurityHeaders sends. The defaults stop MIME sniffing, refuse framing by any site (including the application's own pages), trim the referrer and, on HTTPS, pin the host to HTTPS. Headers that turn off browser features (Permissions-Policy) or popup relationships (Cross-Origin-Opener-Policy) are opt-in, because their strict values break payment, camera, location and popup sign-in flows.

An application changes a value in config/environments/<env>.yml:

security_headers:
  frame_options: "SAMEORIGIN"
  content_security_policy: "frame-ancestors 'self'"

or with an AMBER_SECURITY_HEADERS_<KEY> environment variable, such as AMBER_SECURITY_HEADERS_FRAME_OPTIONS=SAMEORIGIN.

An empty string turns that one header off. #strict_transport_security is sent only on requests that HTTP::Request#https? reports as HTTPS.

Every value is checked when the settings load and whenever it is assigned: a value with a line break or another character HTTP headers do not allow raises Amber::Exceptions::ConfigurationError then, rather than failing each response later.

Included Modules

Defined in:

amber/configuration/security_headers_config.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(ctx : YAML::ParseContext, node : YAML::Nodes::Node) #

[View source]
def self.new #

[View source]

Instance Method Detail

def after_initialize #

Rejects a bad value read from YAML while the settings load.


[View source]
def content_security_policy : String #

Value of Content-Security-Policy. The default carries only frame-ancestors, the modern form of X-Frame-Options, so it changes nothing about which scripts, styles or images a page may load.


[View source]
def content_security_policy=(value : String) : String #

Sets the #content_security_policy value. Raises Amber::Exceptions::ConfigurationError when it contains a character HTTP headers do not allow.


[View source]
def content_type_options : String #

Value of X-Content-Type-Options.


[View source]
def content_type_options=(value : String) : String #

Sets the #content_type_options value. Raises Amber::Exceptions::ConfigurationError when it contains a character HTTP headers do not allow.


[View source]
def cross_origin_opener_policy : String #

Value of Cross-Origin-Opener-Policy. Empty by default, so not sent: same-origin cuts the link between a page and a popup from another site, which popup sign-in (OAuth) and payment windows rely on. Set "same-origin" when the application opens no such popups and is never opened as one.


[View source]
def cross_origin_opener_policy=(value : String) : String #

Sets the #cross_origin_opener_policy value. Raises Amber::Exceptions::ConfigurationError when it contains a character HTTP headers do not allow.


[View source]
def frame_options : String #

Value of X-Frame-Options, for browsers that predate CSP frame-ancestors.


[View source]
def frame_options=(value : String) : String #

Sets the #frame_options value. Raises Amber::Exceptions::ConfigurationError when it contains a character HTTP headers do not allow.


[View source]
def list_of_headers : Array(Tuple(String, String)) #

Returns each always-sent header name paired with its configured value, leaving out the headers whose value is empty.


[View source]
def permissions_policy : String #

Value of Permissions-Policy. Empty by default, so not sent: denying a feature such as payment or camera breaks the pages that use it (an Apple Pay button, a video call). Name the features the application never uses, for example "accelerometer=(), camera=(), geolocation=(), gyroscope=(), magnetometer=(), microphone=(), payment=(), usb=()".


[View source]
def permissions_policy=(value : String) : String #

Sets the #permissions_policy value. Raises Amber::Exceptions::ConfigurationError when it contains a character HTTP headers do not allow.


[View source]
def referrer_policy : String #

Value of Referrer-Policy.


[View source]
def referrer_policy=(value : String) : String #

Sets the #referrer_policy value. Raises Amber::Exceptions::ConfigurationError when it contains a character HTTP headers do not allow.


[View source]
def sends_strict_transport_security? : Bool #

Returns true when Strict-Transport-Security has a value to send.


[View source]
def strict_transport_security : String #

Value of Strict-Transport-Security, sent on HTTPS requests only, because browsers ignore it over plain HTTP (RFC 6797, section 8.1). The default pins this host for two years and leaves sibling subdomains alone; add includeSubDomains once every subdomain of the domain is served over HTTPS (RFC 6797, section 11.4).


[View source]
def strict_transport_security=(value : String) : String #

Sets the #strict_transport_security value. Raises Amber::Exceptions::ConfigurationError when it contains a character HTTP headers do not allow.


[View source]
def validate! : Nil #

Raises Amber::Exceptions::ConfigurationError listing every value that contains a line break or another character HTTP headers do not allow.


[View source]