Create custom headers for Cloudflare Access-protected origins with Workers
Last updated Jan 28, 2026 This tutorial covers how to use a Cloudflare Worker to add custom HTTP headers to traffic, and how to send those custom headers to your origin services protected by Cloudflare Access.
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 required by Access.
Before you begin
- Secure your origin server with Cloudflare Access
Before you begin
- In the Cloudflare dashboard ↗︎, go to the Workers & Pages page. Go to Workers & Pages ↗
- If this is your first Worker, select Create Worker. Otherwise, select Create application, then select Create Worker.
- Enter an identifiable name for the Worker, then select Deploy.
- Select Edit code.
- Input the following Worker:
export default {
async fetch(request, env, ctx) {
const { headers } = request;
const cfaccessemail = headers.get("cf-access-authenticated-user-email");
const requestWithID = new Request(request);
requestWithID.headers.set("company-user-id", cfaccessemail);
return fetch(requestWithID);
},
};
Worker with custom HTTP headersts
export default {
async fetch(request, env, ctx): Promise<Response> {
const { headers } = request;
const cfaccessemail = headers.get("cf-access-authenticated-user-email");
const requestWithID = new Request(request);
requestWithID.headers.set("company-user-id", cfaccessemail);
return fetch(requestWithID);
},
} satisfies ExportedHandler<Env>;
- Select Save and deploy.
Your Worker is now ready to send custom headers to your Access-protected origin services.
Apply the Worker to your hostname
- Select the Worker you created, then go to Triggers.
- In Routes, select Add route.
- Enter the hostname and zone for your origin, then select Add route.
The Worker will now insert a custom header into requests that match the defined route. For example:
Example custom headerhttp
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7",
"Accept-Encoding": "gzip",
"Accept-Language": "en-US,en;q=0.9",
"Cf-Access-Authenticated-User-Email": "user@example.com",
"Company-User-Id": "user@example.com",
"Connection": "keep-alive"
Was this helpful?
YesNo
On this page
{"@context":"https://schema.org","@type":"TechArticle","@id":"https://developers.cloudflare.com/cloudflare-one/tutorials/access-workers/#page","headline":"Create custom headers for Cloudflare Access-protected origins with Workers","description":"This tutorial covers how to use a Cloudflare Worker to add custom headers to traffic. The headers will be sent to origin services protected by Cloudflare Access.","url":"https://developers.cloudflare.com/cloudflare-one/tutorials/access-workers/","inLanguage":"en","image":"https://developers.cloudflare.com/cloudflare-one/tutorials/access-workers/og.png?v=fa530a0104b696ff","dateModified":"2026-01-28","publisher":{"@type":"Organization","name":"Cloudflare","description":"One platform for your apps, agents, and workforce. Build, secure, and scale without managing infrastructure","url":"https://www.cloudflare.com/","sameAs":["https://github.com/cloudflare","https://www.linkedin.com/company/cloudflare","https://x.com/cloudflare"],"logo":{"@type":"ImageObject","url":"https://developers.cloudflare.com/logo.svg"},"address":{"@type":"PostalAddress","streetAddress":"101 Townsend St","addressLocality":"San Francisco","addressRegion":"CA","postalCode":"94107","addressCountry":"US"},"contactPoint":[{"@type":"ContactPoint","contactType":"Customer Support","url":"https://support.cloudflare.com/","availableLanguage":["English"]},{"@type":"ContactPoint","contactType":"Sales","url":"https://www.cloudflare.com/contact/","availableLanguage":["English"]}]},"isPartOf":{"@type":"WebSite","@id":"https://developers.cloudflare.com/#website","name":"Cloudflare Docs","url":"https://developers.cloudflare.com/"},"keywords":["JavaScript"]}
description: This tutorial explains how to deploy the Cloudflare One Client on headless Linux devices using a service token and an installation script. title: Deploy the Cloudflare One Client on headless Linux machines image: https://developers.cloudflare.com/cloudflare-one/tutorials/deploy-client-headless-linux/og.png?v=d28d8095b38b7468
Documentation Index
Fetch the complete documentation index at: https://developers.cloudflare.com/cloudflare-one/llms.txt
Use this file to discover all available pages before exploring further.
Docs