Guidelines for Setting Security Headers | Veracode (original) (raw)

As part of our Alexa Top 1 Million Security Headers post series, it is not uncommon to have to go back and re-read specifications to determine which header values are valid. While there are numerous sites that detail the various headers and what they do, there isn’t a central place that gives developers the information necessary to identify common mis-configurations and methods of testing if the security headers are set correctly. Setting headers incorrectly can not only cause a false sense of security, they may even be detrimental to its security posture. Veracode feels security headers are an important layer of defense and wishes to enable developers to easily and correctly configure their site. If unsure about a particular header or setting, there is a wonderful resource that tracks browser support.

X-XSS-Protection

Purpose

This response header can be used to configure a user-agent’s built in reflective XSS protection. Currently, only Microsoft’s Internet Explorer, Google Chrome and Safari (WebKit) support this header.

Valid Settings

Common Invalid Settings

How To Test

Internet Explorer will display a dialog box if reflective XSS was detected and sanitized or blocked. Chrome will hide the output of the reflective XSS attack in the response when it is set to 1. When it is set to 1; mode=block, Chrome will redirect the user-agent to an empty data:, URL.

External References

X-Content-Type-Options

Purpose

This header can be set to protect against MIME type confusion attacks in Internet Explorer 9, Chrome and Safari. Firefox is currently debating the implementation. Content sniffing is a method browsers use to attempt to determine the ‘real’ content type of a response by looking at the content itself, instead of the response header’s content-type value. By returning X-Content-Type-Options: nosniff, certain elements will only load external resources if their content-type matches what is expected. As an example, if a stylesheet is being loaded, the MIME type of the resource must match “text/css”. For script resources in Internet Explorer, the following content types are valid:

  1. application/ecmascript
  2. application/javascript
  3. application/x-javascript
  4. text/ecmascript
  5. text/javascript
  6. text/jscript
  7. text/x-javascript
  8. text/vbs
  9. text/vbscript

For Chrome, the following are supported MIME types:

  1. text/javascript
  2. text/ecmascript
  3. application/javascript
  4. application/ecmascript
  5. application/x-javascript
  6. text/javascript1.1
  7. text/javascript1.2
  8. text/javascript1.3
  9. text/jscript
  10. text/livescript

Valid Settings

nosniff – This is the only valid setting, it must match nosniff.

Common Invalid Settings

How To Test

Open the developer panel in Internet Explorer or Chrome and observe the difference between: having nosniff and not having nosniff set in the console output.

External References

X-Frame-Options

Purpose

This header is for configuring which sites are allowed to frame the loaded resource. Its primary purpose is to protect against UI redressing style attacks. Internet Explorer has supported the ALLOW-FROM directive since IE8 and Firefox from 18. Both Chrome and Safari do not support ALLOW-FROM, however WebKit is currently discussing it.

Valid Settings

Common Invalid Settings

How To Test

Visit the test cases and view the various options and how the browser responds to framing the resources.

External References

Strict-Transport-Security

Purpose

The following values must exist over the secure connection (HTTPS) and are ineffective if accessed over HTTP.

Common Invalid Settings

How To Test

Determining if a host is your STS cache is possible by accessing “chrome://net-internals/#hsts” in Google Chrome. First, check if the domain is in the STS cache by using the Query Domain option. Next, visit the site that returns the STS header over HTTPS and attempt to query it again to determine if it was added successfully.

External References

Purpose

This header is still under draft specification but may have clear security impacts so it has been added to this list. The purpose of the Public-Key-Pins (PKP) header is to allow site operators to provide hashed public key information to be stored in the browser’s cache. Much like it Strict-Transport-Security header it will help user’s from active man-in-the-middle attacks. The header may include multiple pin- directives. For example, pin-sha256=base64(sha256(SPKI)). The base64 encoded sha256 hash is the result of hashing the Subject Public Key Info (SPKI) field of an X.509 certificate. While the specification or implementations may change, it was observed that not encapsulating the hashes in quotes is invalid and the hashes will not be added to the PKP cache in Chrome 33. This header acts much like STS by including the max-age and include SubDomains directive. Additionally, PKP supports a Public-Key-Pins-Report-Only header which can be used to report violations but will not enforce the pinning of certificate information, however this does not appear to be implemented in Chrome yet.

Valid Settings

Common Invalid Settings

How To Test

Using the same method as Strict-Transport-Security additional information under the pubkey_hashes field should be visible, if the site successfully had the PKP hashes added.

External References

Access-Control-Allow-Origin

Purpose

Access-Control-Allow-Origin is apart of the Cross Origin Resource Sharing (CORS) specification. This header is used to determine which sites are allowed to access the resource by defining either a single origin or all sites (denoted by a wildcard value). It should be noted that if the resource has the wildcard value set, then the Access-Control-Allow-Credentials option will not be valid and the user-agent’s cookies will not be sent in the request.

Valid Settings

Common Invalid Settings

How To Test

It is easy to determine if the header is configured properly because if it is not, the CORS request will simply fail to return any data.

External References

Content-Security-Policy 1.0

Purpose

Content Security Policy is a collection of directives which can be used to restrict how a page loads various resources. Currently, Internet Explorer only supports a subset of CSP and only with the X-Content-Security-Policy header. Chrome and Firefox currently support 1.0 of CSP, however version 1.1 of the policy is currently being developed. Configured properly it can help protect a site’s resources from various attacks such as XSS and UI redressing related issues. There are 10 possible directives which can each be configured to restrict when and how resources are loaded.

There is also the report-uri directive which can be used to send reports when the policy is violated to a specified URL. This can be helpful for both debugging and being notified of an attack. Additionally, a second header of Content-Security-Policy-Report-Only can be defined to not enforce CSP but to send potential violations to a report URL. It follows the same syntax and rules as the Content-Security-Policy header.

Valid Settings

Common Invalid Settings

How To Test

Open the developer panel and view the console in Chrome or Firefox to view any potential violations while debugging a site.

External References

Click Here to Subscribe to Updates from the Veracode Blog