class
Amber::Configuration::SecurityHeadersConfig
- Amber::Configuration::SecurityHeadersConfig
- Reference
- Object
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
- YAML::Serializable
- YAML::Serializable::Strict
Defined in:
amber/configuration/security_headers_config.crConstructors
Instance Method Summary
-
#after_initialize
Rejects a bad value read from YAML while the settings load.
-
#content_security_policy : String
Value of
Content-Security-Policy. -
#content_security_policy=(value : String) : String
Sets the
#content_security_policyvalue. -
#content_type_options : String
Value of
X-Content-Type-Options. -
#content_type_options=(value : String) : String
Sets the
#content_type_optionsvalue. -
#cross_origin_opener_policy : String
Value of
Cross-Origin-Opener-Policy. -
#cross_origin_opener_policy=(value : String) : String
Sets the
#cross_origin_opener_policyvalue. -
#frame_options : String
Value of
X-Frame-Options, for browsers that predate CSPframe-ancestors. -
#frame_options=(value : String) : String
Sets the
#frame_optionsvalue. -
#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.
-
#permissions_policy : String
Value of
Permissions-Policy. -
#permissions_policy=(value : String) : String
Sets the
#permissions_policyvalue. -
#referrer_policy : String
Value of
Referrer-Policy. -
#referrer_policy=(value : String) : String
Sets the
#referrer_policyvalue. -
#sends_strict_transport_security? : Bool
Returns
truewhenStrict-Transport-Securityhas a value to send. -
#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). -
#strict_transport_security=(value : String) : String
Sets the
#strict_transport_securityvalue. -
#validate! : Nil
Raises
Amber::Exceptions::ConfigurationErrorlisting every value that contains a line break or another character HTTP headers do not allow.
Constructor Detail
Instance Method Detail
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.
Sets the #content_security_policy value. Raises
Amber::Exceptions::ConfigurationError when it contains a character
HTTP headers do not allow.
Sets the #content_type_options value. Raises
Amber::Exceptions::ConfigurationError when it contains a character
HTTP headers do not allow.
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.
Sets the #cross_origin_opener_policy value. Raises
Amber::Exceptions::ConfigurationError when it contains a character
HTTP headers do not allow.
Value of X-Frame-Options, for browsers that predate CSP
frame-ancestors.
Sets the #frame_options value. Raises
Amber::Exceptions::ConfigurationError when it contains a character
HTTP headers do not allow.
Returns each always-sent header name paired with its configured value, leaving out the headers whose value is empty.
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=()".
Sets the #permissions_policy value. Raises
Amber::Exceptions::ConfigurationError when it contains a character
HTTP headers do not allow.
Sets the #referrer_policy value. Raises
Amber::Exceptions::ConfigurationError when it contains a character
HTTP headers do not allow.
Returns true when Strict-Transport-Security has a value to send.
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).
Sets the #strict_transport_security value. Raises
Amber::Exceptions::ConfigurationError when it contains a character
HTTP headers do not allow.
Raises Amber::Exceptions::ConfigurationError listing every value that
contains a line break or another character HTTP headers do not allow.