---
url: "https://almanac.httparchive.org/en/2024/security"
titulek: "Security | 2024 | The Web Almanac by HTTP Archive"
h1: "Security"
popis: "Security chapter of the 2024 Web Almanac covering Transport Layer Security, content inclusion (CSP, Feature Policy, SRI), web defense mechanisms (tackling XSS, XS-Leaks), and drivers of security mechanism adoptions."
jazyk: "en"
kanonicka: "https://almanac.httparchive.org/en/2024/security"
drobecky: ["en", "2024"]
zdroj: "live"
wayback_snapshot: ""
stazeno: "2026-09-13 20:14:07"
znaku: 85309
slov: 13151
kodovani: "utf-8"
sha256: "e79015eb38d8f1691dea32512d4e94015482cf9b9229f6dd206018243fd18f31"
---
Part II Chapter 11
# Security
Date published: 2024/11/11
Last updated: 2026/01/21
Written by
[Gertjan Franken](/en/2024/contributors#GJFR)
and
[Vik Vanderlinden](/en/2024/contributors#vikvanderlinden)
Reviewed by
[Matteo Große-Kampmann](/en/2024/contributors#lord-r3) ,
[Alberto Fernandez-de-Retana](/en/2024/contributors#AlbertoFDR) ,
and
[Brian Clark](/en/2024/contributors#clarkio)
Analyzed by
[Jannis Rautenstrauch](/en/2024/contributors#JannisBush)
Edited by
[Caleb Queern](/en/2024/contributors#cqueern)
## Introduction
With how much of our lives happen online these days - whether it’s staying in touch, following the news, buying, or even selling products online - web security has never been more important. Unfortunately, the more we rely on these online services, the more appealing they become to malicious actors. As we’ve seen time and time again, even a single weak spot in the systems we depend on can lead to disrupted services, stolen personal data, or worse. The past two years have been no exception, with a rise in [Denial-of-Service (DoS) attacks](https://blog.cloudflare.com/ddos-threat-report-for-2024-q2/), [bad bots](https://www.imperva.com/resources/resource-library/reports/2024-bad-bot-report/), and [supply-chain attacks targeting the Web](https://www.darkreading.com/vulnerabilities-threats/rising-tide-of-software-supply-chain-attacks) like never before.
In this chapter, we take a closer look at the current state of web security by analyzing the protections and security practices used by websites today. We explore key areas like Transport Layer Security (TLS), cookie protection mechanisms, and safeguards against third-party content inclusion. We’ll discuss how security measures like these help prevent attacks, as well as highlight misconfigurations that can undermine them. Additionally, we examine the prevalence of harmful cryptominers and the usage of `security.txt`.
We also investigate the factors driving security practices, analyzing whether elements like country, website category, or technology stack influence the security measures in place. By comparing this year’s findings with those from the [2022 Web Almanac](../2022/security), we highlight key changes and assess long-term trends. This allows us to provide a broader perspective on the evolution of web security practices and the progress made over the years.
## Transport security
[HTTPS](https://developer.mozilla.org/docs/Glossary/https) uses Transport Layer Security ([TLS](https://www.cloudflare.com/en-gb/learning/ssl/transport-layer-security-tls/)) to secure the connection between client and server. Over the past years, the number of sites using TLS has increased tremendously. As in previous years, adoption of TLS continued to increase, but that increase is slowing down as it closes in to 100%.
98%
Figure 11.1. The percentage of requests that use HTTPS.
The number of requests served using TLS climbed another 4% to 98% on mobile since the last Almanac in 2022.
Stacked bar chart showing 96% of desktop sites are using HTTPS, with the remaining 4% using HTTP, while 96% of mobile sites are using HTTPS and the remaining 4% using HTTP.
Figure 11.2. The percentage of hosts that use HTTPS.
The number of home pages served over HTTPS on mobile increased from 89% to 95.6%. This percentage is lower than the number of requests served over HTTPS due to the high number of third-party resources websites load, which are more likely to be served over HTTPS.
### Protocol versions
Over the years, multiple new versions of TLS have been created. In order to remain secure, it is important to use an up to date version of TLS. The latest version is [TLS1.3](https://www.cloudflare.com/en-in/learning/ssl/why-use-tls-1.3/), which has been the preferred version for a while. Compared to TLS1.2, version 1.3 deprecates some cryptographic protocols still included in 1.2 that were found to have certain flaws and it enforces perfect forward secrecy. Support for older versions of TLS have long been removed by major browser vendors. QUIC (Quick UDP Internet Connections), the protocol underlying HTTP/3 also uses TLS, providing similar security guarantees as TLS1.3.
Stacked bar chart showing that on desktop 73% of sites use `TLSv1.3` , while 19% use `TLSv1.2` and 8% use `QUIC` . On mobile the figures are 72%, 18% and 10% respectively.
Figure 11.3. The distribution of TLS versions in use.
We find that TLS1.3 is supported and used by 73% of web pages. The use of TLS1.3 overall has grown, even though QUIC has gained significant use compared to 2022, moving from 0% to almost 10% of mobile pages. The use of TLS1.2 continues to decrease as expected. Compared to the last Almanac it decreased by more than 12% for mobile pages, while TLS1.3 has increased by a bit over 2%. It is expected that the adoption of QUIC will continue to rise, as the use of TLS1.2 will continue to decrease.
We assume most websites don’t move from TLS1.2 directly to QUIC, but rather that most sites using QUIC migrated from TLS1.3 and others moved from TLS1.2 to TLS1.3, thereby giving the appearance of limited growth of TLS1.3.
### Cipher suites
Before client and server can communicate, they have to agree upon the cryptographic algorithms, known as [cipher suites](https://learn.microsoft.com/en-au/windows/win32/secauthn/cipher-suites-in-schannel), to use. Like last time, over 98% of requests are served using a Galois/Counter Mode ([GCM](https://wikipedia.org/wiki/Galois/Counter_Mode)) cipher, which is considered the most secure option, due to them not being vulnerable to [padding attacks](https://blog.qualys.com/product-tech/2019/04/22/zombie-poodle-and-goldendoodle-vulnerabilities). Also unchanged is the almost 79% of requests using a 128-bit key, which is still considered a secure key-length for AES in GCM mode. There are only a handful of suites used on the visited pages. TLS1.3 [only supports GCM and other modern block cipher modes](https://datatracker.ietf.org/doc/html/rfc8446#page-133), which also simplifies its [cipher suite ordering](https://go.dev/blog/tls-cipher-suites).
Stacked bar chart showing the cipher suites used by device, with `AES_128_GCM` being the most common and used by 79% of desktop and 79% of mobile sites, `AES_256_GCM` is used by 20% of desktop and 20% of mobile sites, `AES_256_CBC` is used by 1% of desktop sites and 1% of mobile sites, `CHACHA20_POLY1305` is used by 0% and 0% of sites respectively, `AES_128_CBC` is used by 0% and 0% respectively.
Figure 11.4. The distribution of cipher suites in use.
TLS1.3 makes [forward secrecy](https://wikipedia.org/wiki/Forward_secrecy) required, which means it is highly supported on the web. Forward Secrecy is a feature that assures that in case a key in use is leaked, it cannot be used to decrypt future or past messages sent over a connection. This is important to ensure that adversaries storing long-term traffic cannot decrypt the entire conversation as soon as they are able to leak a key. Interestingly, the use of forward secrecy dropped by almost 2% this year, to 95%.
Stacked bar chart showing forward secrecy being used by 95% requests in both mobile and desktop.
Figure 11.5. The percentage of requests supporting forward secrecy.
### Certificate Authorities
In order to use TLS, servers must first get a certificate they can host, which is created by a [Certificate Authority](https://www.ssl.com/faqs/what-is-a-certificate-authority/) (CA). By retrieving a certificate from one of the trusted CAs, the certificate will be recognized by the browser, thus allowing the user to use the certificate and therefore TLS for their secure communication.
| Issuer | Desktop | Mobile |
| --- | --- | --- |
| R3 | 44.3% | 45.1% |
| GTS CA 1P5 | 6.1% | 6.6% |
| E1 | 4.2% | 4.3% |
| Sectigo RSA Domain Validation Secure Server CA | 3.3% | 3.1% |
| R10 | 2.6% | 2.8% |
| R11 | 2.6% | 2.8% |
| Go Daddy Secure Certificate Authority - G2 | 2.0% | 1.7% |
| cPanel, Inc. Certification Authority | 1.7% | 1.8% |
| Cloudflare Inc ECC CA-3 | 1.5% | 1.3% |
| Amazon RSA 2048 M02 | 1.4% | 1.3% |
Figure 11.6. The percentage of sites using a certificate issued by a specific issuer.
R3 (an intermediate certificate from [Let’s Encrypt](https://letsencrypt.org/)) still leads the charts, although usage dropped compared to last year. Also from Let’s Encrypt are the E1, R10 and R11 intermediary certificates that are rising in percentage of websites using them.
[R3 and E1 were issued in 2020 and are only valid for 5 years](https://letsencrypt.org/2024/03/19/new-intermediate-certificates.html), which means it will [expire in September 2025](https://crt.sh/?id=3334561879). Around a year before the expiry of intermediate certificates, Let’s Encrypt issues new intermediates that will gradually take over from the older ones. [This March, Let’s Encrypt issued their new intermediates](https://letsencrypt.org/2024/03/19/new-intermediate-certificates.html), which include R10 and R11 that are only valid for 3 years. These latter two certificates will take over from R3 directly, which should be reflected in next year’s Almanac.
Along with the rise in the number of Let’s Encrypt issued certificates, other current top 10 providers have seen a decrease in their share of certificates issued, except for GTS CA 1P5 that rose from close to 0% to over 6.5% on mobile. Of course it is possible that at the time of our analysis a CA was in the process of switching intermediate certificates, which could mean they serve a larger percentage of sites than reflected.
56%
Figure 11.7. The percentage of pages that use a Let’s Encrypt issued certificate on mobile.
When we sum together the use of all certificates of Let’s Encrypt, we find that they issue over 56% of the certificates currently in use.
### HTTP Strict Transport Security
[HTTP Strict Transport Security (HSTS)](https://developer.mozilla.org/docs/Web/HTTP/Headers/Strict-Transport-Security) is a response header that a server can use to communicate to the browser that only HTTPS should be used to reach pages hosted on this domain, instead of first reaching out over HTTP and following a redirect.
30%
Figure 11.8. The percentage of requests that have a HSTS header on mobile.
Currently, 30% of responses on mobile have a HSTS header, which is a 5% increase compared to 2022. Users of the header can communicate directives to the browser by adding them to the header value. The `max-age` directive is obligated. It indicates to the browser the time it should continue to only visit the page over HTTPS in seconds.
Column chart of relative usage of different HSTS directives. `Zero max-age` is used in 5% of websites in both desktop and mobile. `Valid max-age` is used in 95% of websites in both desktop and mobile. `includeSubdomains` is used in 37% of websites in desktop and 35% of websites in mobile. `preload` is used in 18% of websites in both mobile and desktop.
Figure 11.9. The usage of specified HSTS directives.
The share of requests with a valid `max-age` has remained unchanged at 95%. The other , optional, directives (`includeSubdomains` and `preload`) both see a slight increase of 1% compared to 2022 to 35% and 18% on mobile respectively. The `preload` directive, which [is not part of the HSTS specification](https://developer.mozilla.org/docs/Web/HTTP/Headers/Strict-Transport-Security#preloading_strict_transport_security), requires the `includeSubdomains` to be set and also requires a `max-age` larger than 1 year (or 31,536,000 seconds).
Column chart of percentiles of values in the max-age attribute, converted to days. In the 10th percentile for both desktop and mobile are 30 days, in the 25th percentile for desktop are 183 days and for mobile 182 days, in the 50th percentile both are 365 days, int the 75th percentile both are 365 as well, and in the 90th percentile both are 730 days.
Figure 11.10. The distribution of HSTS max-age values by percentile.
The distribution of valid `max-age` values has remained almost the same as in 2022, with the exception that the 10th percentile on mobile has decreased from 72 to 30 days. The median value of `max-age` remains at 1 year.
## Cookies
Websites can store small pieces of data in a user’s browser by setting an HTTP cookie. Depending on the cookie’s attributes, it will be sent with every subsequent request to that website. As such, cookies can be used for purposes of implicit authentication, tracking or storing user preferences.
When cookies are used for authenticating users, it is paramount to protect them from abuse. For instance, if an adversary gets ahold of a user’s session cookie, they could potentially log into the victim’s account.
To protect their user’s from attacks like [Cross-Site Request Forgery (CSRF)](https://owasp.org/www-community/attacks/csrf),[session hi-jacking](https://owasp.org/www-community/attacks/Session_hijacking_attack), [Cross-Site Script Inclusion (XSSI)](https://owasp.org/www-project-web-security-testing-guide/v41/4-Web_Application_Security_Testing/11-Client_Side_Testing/13-Testing_for_Cross_Site_Script_Inclusion) and [Cross-Site Leaks](https://xsleaks.dev/), websites are expected to securely configure authentication cookies.
The three cookie attributes outlined below enhance the security of authentication cookies against the attacks mentioned earlier. Ideally, developers should consider using all attributes, as they provide complementary layers of protection.
Bar chart of cookie attributes used on desktop sites divided by first and third-party cookies. For first-party `HttpOnly` is used by 42%, `Secure` by 44%, and `SameSite` by 59%, while for third-party `HttpOnly` is used by 20%, `Secure` by 96%, and `SameSite` by 94%.
Figure 11.11. Cookie attributes (desktop).
#### `HttpOnly`
By setting this attribute, the cookie is not allowed to be accessed or manipulated through the JavaScript `document.cookie` API. This prevents a [Cross-Site Scripting (XSS)](https://owasp.org/www-community/attacks/xss/) attack from gaining access to cookies containing secret session tokens.
With 42% of cookies having the `HttpOnly` attribute in a first-party context on desktop, the usage has risen by 6% compared to 2022. As for third-party requests, the usage has decreased by 1%.
#### `Secure`
Browsers only transmit cookies with the `Secure` attribute over secure, encrypted channels, such as HTTPS, and not over HTTP. This ensures that man-in-the-middle attackers cannot intercept and read sensitive values stored in cookies.
The use of the `Secure` attribute has been steadily increasing over the years. Since 2022, an additional 7% of cookies in first-party contexts and 6% in third-party contexts have been configured with this attribute. As discussed in previous editions of the Security chapter, the significant difference in adoption between the two contexts is largely due to the requirement that third-party cookies with `SameSite=None` must also be marked as `Secure`. This highlights that additional security prerequisites for enabling desired non-default functionality are an effective driver for the adoption of security features.
#### `SameSite`
The most recently introduced cookie attribute, `SameSite`, allows developers to control whether a cookie is allowed to be included in third-party requests. It is intended as an additional layer of defense against attacks like CSRF.
The attribute can be set to one of three values: `Strict`, `Lax`, or `None`. Cookies with the `Strict` value are completely excluded from cross-site requests. When set to `Lax`, cookies are only included in third-party requests under specific conditions, such as navigational GET requests, but not POST requests. By setting `SameSite=none`, the cookie bypasses the same-site policy and is included in all requests, making it accessible in cross-site contexts.
Bar chart of SameSite cookie attributes divided by first and third-party. For first-party `SameSite=lax` is used by 34%, `SameSite=strict` by 2%, `SameSite=none` by 23% and 41% had no SameSite attribute, while for third-party `SameSite=lax` is used by 0.4%, `SameSite=none` by 94% and 6% had no SameSite attribute.
Figure 11.12. SameSite cookie attributes (desktop).
While the relative number of cookies with a `SameSite` attribute has increased compared to 2022, this rise is largely attributable to cookies being explicitly excluded from the same-site policy by setting `SameSite=None`.
It’s important to note that all cookies without a `SameSite` attribute are treated as `SameSite=Lax` by default. Consequently, a total of 75% of cookies set in a first-party context are effectively treated as if they were set to `Lax`.
### Prefixes
[Session fixation](https://owasp.org/www-community/attacks/Session_fixation) attacks can be mitigated by using cookie prefixes like `__Secure-` and `__Host-`. When a cookie name starts with `__Secure-`, the browser requires the cookie to have the `Secure` attribute and to be transmitted over an encrypted connection. For cookies with the `__Host-` prefix, the browser additionally mandates that the cookie includes the `Path` attribute set to `/` and excludes the `Domain` attribute. These requirements help protect cookies from man-in-the-middle attacks and threats from compromised subdomains.
| Type of cookie | `__Secure` | `__Host` |
| --- | --- | --- |
| First-party | 0.05% | 0.17% |
| Third-party | 0.00% | 0.04% |
Figure 11.13. `__Secure-` and `__Host-` prefixes (desktop).
The adoption of cookie prefixes remains low, with less than 1% of cookies using these prefixes on both desktop and mobile platforms. This is particularly surprising given the high adoption rate of cookies with the `Secure` attribute, the only prerequisite for cookies prefixed with `__Secure-`. However, changing a cookie’s name can require significant refactoring, which is presumably a reason why developers tend to avoid this.
Websites can control how long browsers store a cookie by setting its lifespan. Browsers will discard cookies when they reach the age specified by the `Max-Age` attribute or when the timestamp defined in the `Expires` attribute is reached. If neither attribute is set, the cookie is considered a session cookie and will be removed when the session ends.
Column chart showing the use of cookie ages in days at various percentiles. At the 10th percentile, a `Max-Age` , `Expires` and real age of 1 day. At the 25th percentile a value of 90 days and 60 days for `Max-Age` and `Expires` respectively, the real age is 60 days. At the 50th percentile a value of 365 days for `Max-Age` , `Expires` and 364 for the real age. At the 75th percentile a value of 365 days for `Max-Age` , `Expires` and the real age. At the 90th percentile a value of 730 days for `Max-Age` , `Expires` and the real age.
Figure 11.14. Cookie age in days (desktop).
The distribution of cookie ages has remained largely unchanged compared to [lat year](../2022/security#cookie-age). However, since then, the [cookie standard working draft](https://httpwg.org/http-extensions/draft-ietf-httpbis-rfc6265bis.html#name-cookie-lifetime-limits) has been updated, capping the maximum cookie age to 400 days. This change has already been implemented in [Chrome](https://developer.chrome.com/blog/cookie-max-age-expires) and Safari. Based on the percentiles shown above, in these browsers, more than 10% of all observed cookies have their age capped to this 400-day limit.
## Content inclusion
Content inclusion is a foundational aspect of the Web, allowing resources like CSS, JavaScript, fonts, and images to be shared via CDNs or reused across multiple websites. However, fetching content from external or third-party sources introduces significant risks. By referencing resources outside your control, you are placing trust in those third parties, which could either turn malicious or be compromised. This can lead to so-called supply-chain attacks, like the recent [polyfill incident where compromised resources affected hundreds of thousands of websites](https://www.darkreading.com/remote-workforce/polyfillio-supply-chain-attack-smacks-down-100k-websites). Therefore, security policies that govern content inclusion are essential for protecting web applications.
### Content Security Policy
Websites can exert greater control over their embedded content by deploying a [Content Security Policy (CSP)](https://developer.mozilla.org/docs/Web/HTTP/CSP) through either the `Content-Security-Policy` response header or by defining the policy in a `` tag. The wide range of directives available in CSP allows websites to specify, in a fine-grained manner, which resources can be fetched and from which origins.
In addition to vetting included content, CSP can serve other purposes as well, such as enforcing the use of encrypted channels with the `upgrade-insecure-requests` directive and controlling where the site can be embedded to protect against clickjacking attacks using the `frame-ancestors` directive.
+27%
Figure 11.15. Relative increase in adoption for Content-Security-Policy header from 2022.
The adoption rate of CSP headers increased from 15% of all hosts in 2022 to 19% this year. This amounts to a relative increase of 27%. Over these two years, the relative increase was 12% between 2022 and 2023, and 14% between 2023 and 2024.
Looking back, overall CSP adoption was only at 12% of hosts in 2021, so it’s encouraging to see that growth has remained steady. If this trend continues, projections suggest that CSP adoption will surpass the 20% mark in next year’s Web Almanac.
#### Directives
Most websites utilize CSP for purposes beyond controlling embedded resources, with the `upgrade-insecure-requests` and `frame-ancestors` directives being the most popular.
Bar chart showing usage of most common CSP directives. `frame-ancestors` is the most common with 56% in desktop and 55% in mobile, followed by `upgrade-insecure-requests` which is 54% in desktop and 56% in mobile. `block-all-mixed-content` is 24% in desktop and 24% in mobile, `default-src` is 17% in desktop and 15% in mobile, `script-src` is 17% in desktop and 15% in mobile, `style-src` is 13% in desktop and 12% in mobile, `img-src` is 13% in desktop and 12% in mobile, `font-src` is 11% in desktop and 10% in mobile, `connect-src` is 10% in desktop and 9% in mobile, `frame-src` is 10% in desktop and 9% in mobile.
Figure 11.16. Most common directives used in CSP.
The `block-all-mixed-content` directive, which has been deprecated in favor of `upgrade-insecure-requests`, is the third most used directive. Although we observed a relative decrease of 12.5% for desktop and 13.8% for mobile in its usage between 2020 and 2021, the decline has since slowed to an average yearly decrease of 4.4% for desktop and 6.4% for mobile since 2022.
| Policy | Desktop | Mobile |
| --- | --- | --- |
| `upgrade-insecure-requests;` | 27% | 30% |
| `block-all-mixed-content; frame-ancestors 'none'; upgrade-insecure-requests;` | 22% | 22% |
| `frame-ancestors 'self';` | 11% | 10% |
Figure 11.17. Most prevalent CSP headers.
The top three directives also make up the building blocks of the most prevalent CSP definitions. The second most commonly used CSP definition includes both `block-all-mixed-content` and `upgrade-insecure-requests`. This suggests that many websites use `block-all-mixed-content` for backward compatibility, as newer browsers will ignore this directive if `upgrade-insecure-requests` is present.
| Directive | Desktop | Mobile |
| --- | --- | --- |
| `upgrade-insecure-requests` | -1% | 0% |
| `frame-ancestors` | 5% | 3% |
| `block-all-mixed-content` | -9% | -13% |
| `default-src` | -9% | -6% |
| `script-src` | -3% | -2% |
| `style-src` | -8% | -2% |
| `img-src` | -3% | 9% |
| `font-src` | -4% | 8% |
| `connect-src` | 3% | 17% |
| `frame-src` | 4% | 16% |
| `object-src` | 16% | 17% |
Figure 11.18. Relative usage change of CSP directives.
All other directives shown in the table above are used for content inclusion control. Overall, usage has remained relatively stable. However, a notable change is the increased use of the `object-src` directive, which has surpassed `connect-src` and `frame-src`. Since 2022, the usage of `object-src` has risen by 15.9% for desktop and 16.8% for mobile.
Among the most notable decreases in usage is `default-src`, the catch-all directive. This decline could be explained by the increasing use of CSP for purposes beyond content inclusion, such as enforcing HTTP upgrades to HTTPS or controlling the embedding of the current page – situations where `default-src` is not applicable, as these directives don’t fallback to it. This change in CSP purpose is confirmed by the most prevalent CSP headers listed in Figure 17, which all have seen an increase in usage since 2022. However, directives like `upgrade-insecure-requests` and `block-all-mixed-content`, while part of these most common CSP headers, are being used less overall, as seen in Figure 18.
#### Keywords for `script-src`
One of the most important directives of CSP is `script-src`, as curbing scripts loaded by the website hinders potential adversaries greatly. This directive can be used with several attribute keywords.
Column chart showing usage of `nonce-` , `strict-dynamic` , `unsafe-inline` and `unsafe-eval` in the CSP `script-src` directive. `nonce-` is used by 20% of websites with a CSP for desktop and mobile. `strict-dynamic` is used by 10% of websites with a CSP for desktop and 9% for mobile. `unsafe-inline` is used by 91% of websites with a CSP for desktop and 92% for mobile. `unsafe-eval` is used by 78% of websites with a CSP for desktop and mobile.
Figure 11.19. Prevalence of CSP `script-src` keywords.
The `unsafe-inline` and `unsafe-eval` directives can significantly reduce the security benefits provided by CSP. The `unsafe-inline` directive permits the execution of inline scripts, while `unsafe-eval` allows the use of the eval JavaScript function. Unfortunately, the use of these insecure practices remains widespread, demonstrating the challenges of avoiding use of inline scripts and use of the `eval` function.
| Keyword | Desktop | Mobile |
| --- | --- | --- |
| `nonce-` | 62% | 39% |
| `strict-dynamic` | 61% | 88% |
| `unsafe-inline` | -3% | -3% |
| `unsafe-eval` | -3% | 0% |
Figure 11.20. Relative usage change of CSP `script-src` keywords.
However, the increasing adoption of the `nonce-` and `strict-dynamic` keywords is a positive development. By using the `nonce-` keyword, a secret nonce can be defined, allowing only inline scripts with the correct nonce to execute. This approach is a secure alternative to the `unsafe-inline` directive for permitting inline scripts. When used in combination with the `strict-dynamic` keyword, nonced scripts are permitted to import additional scripts from any origin. This approach simplifies secure script loading for developers, as it allows them to trust a single nonced script, which can then securely load other necessary resources.
#### Allowed hosts
CSP is often regarded as one of the more complex security policies, partly due to the detailed policy language, providing fine-grained control over resource inclusion.
Column chart showing percentiles of the length of the CSP header in bytes. At 10th percentile desktop is 22 bytes and mobile is 23 bytes, at 25th percentile both are 25 bytes, at 50th percentile desktop is 55 bytes and mobile is 48 bytes, at 75th percentile both are 75 bytes and at 90th percentile desktop is 504 bytes and mobile is 368 bytes.
Figure 11.21. CSP header length.
Reviewing the observed CSP header lengths, we find that 75% of all headers are 75 bytes or shorter. For context, the longest policy shown in Figure 17 is also 75 bytes. At the 90th percentile, desktop policies reach 504 bytes and mobile policies 368 bytes, indicating that many websites find it necessary to implement relatively lengthy Content Security Policies. However, when analyzing the distribution of unique allowed hosts across all policies, the 90th percentile shows just 2 unique hosts.
The highest number of unique allowed hosts in a policy was 1,020, while the longest Content Security Policy header reached 65,535 bytes. However, this latter header is inflated by a large number of repeated `,` characters for unknown reasons. The second longest CSP header, which is valid, spans 33,123 bytes. This unusually large size is due to hundreds of occurrences of the `adservice.google` domain, each with variations in the top-level domain. Excerpt:
```
adservice.google.com adservice.google.ad adservice.google.ae …
```
This suggests that the long tail of excessively large CSP headers is likely caused by computer-generated exhaustive lists of origins. Although this may seem like a specific edge case, it highlights a limitation of CSP: the lack of regex functionality, which could otherwise provide a more efficient and elegant solution to handle such cases. However, depending on the websites implementation, this issue could also be solved by employing the `strict-dynamic` and `nonce-` keyword in the `script-src` directive, which enables the allowed script with nonce to load additional scripts.
The most common HTTPS origins included in CSP headers are used for loading fonts, ads and other media fetched from CDNs:
| Host | Desktop | Mobile |
| --- | --- | --- |
| `https://www.googletagmanager.com` | 0.41% | 0.32% |
| `https://fonts.gstatic.com` | 0.34% | 0.27% |
| `https://fonts.googleapis.com` | 0.33% | 0.27% |
| `https://www.google-analytics.com` | 0.33% | 0.26% |
| `https://www.google.com` | 0.30% | 0.26% |
| `https://www.youtube.com` | 0.26% | 0.23% |
| `https://*.google-analytics.com` | 0.25% | 0.23% |
| `https://connect.facebook.net` | 0.20% | 0.19% |
| `https://*.google.com` | 0.19% | 0.19% |
| `https://*.googleapis.com` | 0.19% | 0.19% |
Figure 11.22. Most frequently allowed HTTP(S) hosts in CSP policies.
As for WSS origins, used for allowing WebSocket connections to certain origins, the following were found the most common:
| Host | Desktop | Mobile |
| --- | --- | --- |
| `wss://*.intercom.io` | 0.08% | 0.08% |
| `wss://*.hotjar.com` | 0.08% | 0.07% |
| `wss://www.livejournal.com` | 0.05% | 0.06% |
| `wss://*.quora.com` | 0.04% | 0.06% |
| `wss://*.zopim.com` | 0.03% | 0.02% |
Figure 11.23. Most frequently allowed WS(S) hosts in CSP policies.
Two of these origins are related to customer service and ticketing (`intercom.io`, `zopim.com`), one is used for website analytics (`hotjar.com`), and two are associated with social media (`www.livejournal.com`, `quora.com`). For four out of these five websites, we found specific instructions on how to add the origin to the website’s content security policy. This is considered good practice, as it discourages website administrators from using wildcards to allow third-party resources, which would reduce security by allowing broader access than necessary.
### Subresource Integrity
While CSP is a powerful tool for ensuring that resources are only loaded from trusted origins, there remains a risk that those resources could be tampered with. For instance, a script might be loaded from a trusted CDN, but if that CDN suffers a security breach and its scripts are compromised, any website using one of those scripts could become vulnerable as well.
[Subresource Integrity (SRI)](https://developer.mozilla.org/docs/Web/Security/Subresource_Integrity) provides a safeguard against this risk. By using the `integrity` attribute in `