You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Customers with a Bot Management and a [Workers](/workers/) subscription can use the template below to introduce a delay to requests that are likely from bots.
Copy file name to clipboardExpand all lines: src/content/docs/cloudflare-for-platforms/cloudflare-for-saas/domain-support/custom-metadata.mdx
+41-42Lines changed: 41 additions & 42 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,27 +5,26 @@ sidebar:
5
5
order: 5
6
6
head: []
7
7
description: Configure per-hostname settings such as URL rewriting and custom headers.
8
-
9
8
---
10
9
11
-
import { Render } from"~/components"
10
+
import { Render } from"~/components";
12
11
13
12
You may wish to configure per-hostname (customer) settings beyond the scale of Page Rules or Rate Limiting, which have a maximum of 125 rules each.
14
13
15
14
To do this, you will first need to reach out to your account team to enable access to Custom Metadata. After configuring custom metadata, you can use it in the following ways:
16
15
17
-
* Read the metadata JSON from [Cloudflare Workers](/workers/) (requires access to Workers) to define per-hostname behavior.
18
-
* Use custom metadata values in [rule expressions](/ruleset-engine/rules-language/expressions/) of different Cloudflare security products to define the rule scope.
16
+
- Read the metadata JSON from [Cloudflare Workers](/workers/) (requires access to Workers) to define per-hostname behavior.
17
+
- Use custom metadata values in [rule expressions](/ruleset-engine/rules-language/expressions/) of different Cloudflare security products to define the rule scope.
19
18
20
19
<Renderfile="ssl-for-saas-plan-limitation" />
21
20
22
-
***
21
+
---
23
22
24
23
## Examples
25
24
26
-
* Per-customer URL rewriting — for example, customers 1-10,000 fetch assets from server A, 10,001-20,000 from server B, etc.
27
-
* Adding custom headers — for example, `X-Customer-ID: $number` based on the metadata you provided
28
-
* Setting HTTP Strict Transport Security (“HSTS”) headers on a per-customer basis
25
+
- Per-customer URL rewriting — for example, customers 1-10,000 fetch assets from server A, 10,001-20,000 from server B, etc.
26
+
- Adding custom headers — for example, `X-Customer-ID: $number` based on the metadata you provided
27
+
- Setting HTTP Strict Transport Security (“HSTS”) headers on a per-customer basis
29
28
30
29
Please speak with your Solutions Engineer to discuss additional logic and requirements.
31
30
@@ -54,32 +53,32 @@ curl --request PATCH \
54
53
55
54
Changes to metadata will propagate across Cloudflare’s edge within 30 seconds.
56
55
57
-
***
56
+
---
58
57
59
58
## Accessing custom metadata from a Cloudflare Worker
60
59
61
60
The metadata object will be accessible on each request using the `request.cf.hostMetadata` property. You can then read the data, and customize any behavior on it using the Worker.
62
61
63
-
In the example below we will use the user\_id in the Worker that was submitted using the API call above `"custom_metadata":{"customer_id":"12345","redirect_to_https": true,"security_tag":"low"}`, and set a request header to send the `customer_id` to the origin:
62
+
In the example below we will use the user_id in the Worker that was submitted using the API call above `"custom_metadata":{"customer_id":"12345","redirect_to_https": true,"security_tag":"low"}`, and set a request header to send the `customer_id` to the origin:
* Ensure that the JSON schema used is fixed: changes to the schema without corresponding Cloudflare Workers changes will potentially break websites, or fall back to any defined “default” behavior
100
-
* Prefer a flat JSON structure
101
-
* Use string keys in snake\_case (rather than camelCase or PascalCase)
102
-
* Use proper booleans (true/false rather than `true` or `1` or `0`)
103
-
* Use numbers to represent integers instead of strings (`1` or `2` instead of `"1"` or `"2"`)
104
-
* Define fallback behaviour in the non-presence of metadata
105
-
* Define fallback behaviour if a key or value in the metadata are unknown
98
+
- Ensure that the JSON schema used is fixed: changes to the schema without corresponding Cloudflare Workers changes will potentially break websites, or fall back to any defined “default” behavior
99
+
- Prefer a flat JSON structure
100
+
- Use string keys in snake_case (rather than camelCase or PascalCase)
101
+
- Use proper booleans (true/false rather than `true` or `1` or `0`)
102
+
- Use numbers to represent integers instead of strings (`1` or `2` instead of `"1"` or `"2"`)
103
+
- Define fallback behaviour in the non-presence of metadata
104
+
- Define fallback behaviour if a key or value in the metadata are unknown
106
105
107
106
General guidance is to follow [Google’s JSON Style guide](https://google.github.io/styleguide/jsoncstyleguide.xml) where appropriate.
108
107
109
-
***
108
+
---
110
109
111
110
## Limitations
112
111
113
112
There are some limitations to the metadata that can be provided to Cloudflare:
114
113
115
-
* It must be valid JSON.
116
-
* Any origin resolution — for example, directing requests for a given hostname to a specific backend — must be provided as a hostname that exists within Cloudflare’s DNS (even for non-authoritative setups). Providing an IP address directly will cause requests to error.
117
-
* The total payload must not exceed 4 KB.
118
-
* It requires a Cloudflare Worker that knows how to process the schema and trigger logic based on the contents.
119
-
* Custom metadata cannot be set on custom hostnames that contain wildcards.
114
+
- It must be valid JSON.
115
+
- Any origin resolution — for example, directing requests for a given hostname to a specific backend — must be provided as a hostname that exists within Cloudflare’s DNS (even for non-authoritative setups). Providing an IP address directly will cause requests to error.
116
+
- The total payload must not exceed 4 KB.
117
+
- It requires a Cloudflare Worker that knows how to process the schema and trigger logic based on the contents.
118
+
- Custom metadata cannot be set on custom hostnames that contain wildcards.
120
119
121
120
:::note
122
121
123
-
Be careful when modifying the schema. Adding, removing, or changing keys and possible values may cause the Cloudflare Worker to either ignore the data or return an error for requests that trigger it.
122
+
Be careful when modifying the schema. Adding, removing, or changing keys and possible values may cause the Cloudflare Worker to either ignore the data or return an error for requests that trigger it.
Copy file name to clipboardExpand all lines: src/content/docs/cloudflare-one/tutorials/access-workers.mdx
+13-27Lines changed: 13 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,27 +10,20 @@ products:
10
10
- Access
11
11
languages:
12
12
- JavaScript
13
-
14
13
---
15
14
16
-
17
-
18
15
This tutorial covers how to use a [Cloudflare Worker](/workers/) to add custom HTTP headers to traffic, and how to send those custom headers to your origin services protected by [Cloudflare Access](/cloudflare-one/policies/access/).
19
16
20
17
Some applications and networking implementations require specific custom headers to be passed to the origin, which can be difficult to implement for traffic moving through a Zero Trust proxy. You can configure a Worker to send the [user authorization headers](/cloudflare-one/identity/authorization-cookie/) required by Access.
21
18
22
-
***
19
+
---
23
20
24
21
## Before you begin
25
22
26
-
27
-
28
-
* Secure your origin server with Cloudflare Access
29
-
23
+
- Secure your origin server with Cloudflare Access
30
24
31
25
## Before you begin
32
26
33
-
34
27
1. Log in to the [Cloudflare dashboard](https://dash.cloudflare.com/) and select your account. Go to **Workers & Pages**.
35
28
36
29
2. If this is your first Worker, select **Create Worker**. Otherwise, select **Create application**, then select **Create Worker**.
@@ -41,30 +34,26 @@ Some applications and networking implementations require specific custom headers
41
34
42
35
5. Input the following Worker:
43
36
44
-
```javascript title="Worker with custom HTTP headers"
Copy file name to clipboardExpand all lines: src/content/docs/images/manage-images/serve-images/serve-private-images.mdx
+9-10Lines changed: 9 additions & 10 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,6 @@ pcx_content_type: how-to
3
3
title: Serve private images
4
4
sidebar:
5
5
order: 23
6
-
7
6
---
8
7
9
8
You can serve private images by using signed URL tokens. When an image requires a signed URL, the image cannot be accessed without a token unless it is being requested for a variant set to always allow public access.
@@ -14,10 +13,8 @@ You can serve private images by using signed URL tokens. When an image requires
14
13
15
14
:::note
16
15
17
-
18
16
Private images do not currently support custom paths.
19
17
20
-
21
18
:::
22
19
23
20
The example below uses a Worker that takes in a regular URL without a signed token and returns a tokenized URL that expires after one day. You can, however, set this expiration period to whatever you need, by changing the const `EXPIRATION` value.
@@ -62,11 +59,13 @@ async function generateSignedUrl(url) {
0 commit comments