Skip to content

Commit 4768278

Browse files
[API Shield] Add details on securing mTLS rules (#19561)
--------- Co-authored-by: Pedro Sousa <[email protected]>
1 parent 13e8f68 commit 4768278

File tree

1 file changed

+21
-4
lines changed

1 file changed

+21
-4
lines changed

src/content/docs/api-shield/security/mtls/configure.mdx

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ sidebar:
66
head:
77
- tag: title
88
content: Configure mTLS
9-
109
---
1110

12-
import { Render } from "~/components"
11+
import { Render } from "~/components";
1312

1413
When you specify API hosts in [mTLS authentication](/api-shield/security/mtls/), Cloudflare will block all requests that do not have a [client certificate](/ssl/client-certificates/) for mTLS authentication.
1514

@@ -40,7 +39,25 @@ The first expression — `not cf.tls_client_auth.cert_verified` — returns `tru
4039

4140
The second expression uses the `http.request.uri.path` field, combined with the `in` operator, to capture the URI paths your mTLS rule applies to.
4241

43-
Because the [action](/ruleset-engine/rules-language/actions/) for your rule is *Block*, only requests that present a valid client certificate can access the specified hosts.
42+
Because the [action](/ruleset-engine/rules-language/actions/) for your rule is _Block_, only requests that present a valid client certificate can access the specified hosts.
43+
44+
For enhanced security, Cloudflare recommends that you validate the SHA-256 certificate hash alongside the verified certificate field. This ensures that only requests presenting a valid client certificate with a specific fingerprint are allowed.
45+
46+
You can implement this by using an expression similar to the following:
47+
48+
```txt
49+
not (cf.tls_client_auth.cert_verified and cf.tls_client_auth.cert_fingerprint_sha256 eq "253E08C1AB67EB7630C61734D377D75D5DCCDE2F6E69986C221D66E848B64321")
50+
```
51+
52+
To obtain the SHA-256 fingerprint of a client certificate stored in the `mtls.crt` file, you can run the following OpenSSL command:
53+
54+
```sh
55+
openssl x509 -noout -fingerprint -sha256 -inform pem -in mtls.crt | cut -d "=" -f 2 | tr -d ':'
56+
```
57+
58+
```txt output
59+
253E08C1AB67EB7630C61734D377D75D5DCCDE2F6E69986C221D66E848B64321
60+
```
4461

4562
### Check for revoked certificates
4663

@@ -54,5 +71,5 @@ When a request includes a revoked certificate, the `cf.tls_client_auth.cert_revo
5471

5572
:::caution
5673

57-
This check only applies to client certificates issued by the Cloudflare managed CA. Cloudflare currently does not check certificate revocation lists (CRL) for [CAs that have been uploaded](/ssl/client-certificates/byo-ca/).
74+
This check only applies to client certificates issued by the Cloudflare managed CA. Cloudflare currently does not check certificate revocation lists (CRL) for [CAs that have been uploaded](/ssl/client-certificates/byo-ca/).
5875
:::

0 commit comments

Comments
 (0)