Skip to content
AnswerWell geo Documentation

Research · 7 min read · Answerwell

Worker Access Policy, Sign-In Protection and Runtime Identity

How to protect Workers with Access: worker-level policies, preview URLs, ctx.access identity, JWT checks, and local wrangler testing.

This page summarises Cloudflare Access for Workers and related changelog updates from Cloudflare. It explains how to require sign-in before traffic reaches a Worker, how policies attach to the Worker instead of every hostname, how preview and workers.dev URLs behave by default, and how your script reads the signed-in user through ctx.access or JWT validation.

Cloudflare Access on Workers: what it protects

Section titled “Cloudflare Access on Workers: what it protects”

Cloudflare Access on Workers limits who can open a Worker’s URLs before the request reaches your code. You can protect preview deployments only, or both preview and production traffic, and define who may sign in (account members, specific emails, or email domains). Advanced rules are edited in the Zero Trust dashboard.

Two protection models matter in current documentation:

Goal Dashboard area API destination type
Preview deployments for all Workers Protect all Workers all_preview_workers
Production and preview for all Workers Protect all Workers all_workers
Preview for one Worker Protect one Worker preview_worker
Production and preview for one Worker Protect one Worker worker
A specific hostname (route, Custom Domain, or path) Self-hosted application Self-hosted application domain

Worker-level Access applies the policy to the Worker resource, so routes, Custom Domains, workers.dev hostnames, and preview URLs stay covered when routing changes. That replaces the older pattern of listing every hostname on a separate Access application.

Now, Access attaches the policy to the Worker itself, so every associated domain and preview URL stays protected even when its routes or domains change.

— Cloudflare, You can now enable Access on a Worker or all Workers at once

For workers.dev and Preview URLs you can also use one-click protection under Settings → Domains & Routes, as described in One-click Cloudflare Access for Workers.

Worker-level Access vs hostname-based Access

Section titled “Worker-level Access vs hostname-based Access”

Require sign-in on a single Worker from Workers & Pages → select Worker → Access → Protect this Worker behind Access. Choose Previews only or All traffic, set the authentication policy, then Apply Access. The same flow is documented in Cloudflare Access configuration.

Worker-level Access policies do not support WebSocket connections. Upgrade requests fail with 403. If the Worker uses WebSockets (including Durable Objects or real-time apps), use a hostname-based Access application instead.

Worker-level Access policies do not currently support WebSocket connections. WebSocket upgrade requests to a Worker protected by a worker-level Access policy will fail with a 403 error.

— Cloudflare, Cloudflare Access

You can make every existing and new Worker private by default (account-wide setting). Each Worker then requires sign-in unless you add a Worker-level bypass to make that Worker public. A bypass only matters when account-level Access already protects that Worker.

Make all Workers private by default, so every existing and newly created Worker requires sign-in before anyone can reach it.

— Cloudflare, Access changelog

Bypass policies use decision: "bypass" with an everyone include rule on a worker destination; see Make a Worker public when all Workers are protected.

One-click protection now creates reusable policies instead of one unique policy per application.

Surface Default policy behaviour
Preview URLs (all Workers) Single shared policy Cloudflare Workers Preview URLs; created the first time you enable Access on any preview URL
Production workers.dev Per-Worker policy named <worker-name> - Production; removed when Access is disabled if unused elsewhere

Preview URLs: All Workers preview URLs share a single “Cloudflare Workers Preview URLs” policy across your account.

— Cloudflare, One-click Access protection for Workers now creates reusable Cloudflare Access policies

Customise rules in the Zero Trust dashboard or via Manage Cloudflare Access on Settings → Domains & Routes.

Preview URL defaults and locking down public endpoints

Section titled “Preview URL defaults and locking down public endpoints”

Preview URLs let you hit a deployment before production. If you only disable the workers.dev route, a preview URL could still be public—a common misconfiguration.

From Wrangler v4.44.0 onward, when preview URL mode is not set explicitly on deploy, it matches the workers.dev route setting (earlier Wrangler versions used different defaults; see Workers Preview URL default behavior now matches your workers.dev setting).

Situation Default
Neither setting configured Both workers.dev and preview URL enabled
workers.dev enabled, preview not explicitly set Preview URL enabled
workers.dev disabled, preview not explicitly set Preview URL disabled

Override preview URL enable/disable in the dashboard, API, or Wrangler. To limit who can open those URLs, enable Access from the Worker’s settings as in workers.dev routing.

When Access is enabled on the Worker, authenticated requests expose ctx.access. Call ctx.access.getIdentity() for email, name, and groups without parsing JWTs in application code.

When Access is enabled on your Worker, every authenticated request includes ctx.access. Call ctx.access.getIdentity() to get the user’s email, name, and groups — no manual JWT validation required.

— Cloudflare, Workers Access changelog

Example pattern from the same source:

export default {
async fetch(request, env, ctx) {
if (!ctx.access) {
return new Response("Access did not run", { status: 401 });
}
const identity = await ctx.access.getIdentity();
return Response.json({ aud: ctx.access.aud, email: identity?.email });
},
};

Manage policies from the Access tab under Workers & Pages (account-wide list) or per-Worker Access tab.

If the Worker serves Static Assets, the internal assets router does not pass ctx.access to your user Worker. Access still gates the site, but your script cannot read ctx.access on those requests.

When a Worker has Static Assets, the internal assets router does not pass ctx.access to the user Worker.

— Cloudflare, Worker script

Use hostname-based Access and JWT validation, or routes that always hit your fetch handler, when identity in code is required.

JWT validation with Cf-Access-Jwt-Assertion

Section titled “JWT validation with Cf-Access-Jwt-Assertion”

Access still performs the browser gate. For application-level security you should verify the JWT Cloudflare adds on allowed requests.

To fully secure your application, it is important that you validate the JWT that Cloudflare Access adds to the Cf-Access-Jwt-Assertion header on the incoming request.

— Cloudflare, One-click Cloudflare Access for Workers

Read cf-access-jwt-assertion, verify against your team JWKS (${TEAM_DOMAIN}/cdn-cgi/access/certs), and check audience against POLICY_AUD. The changelog shows verification with the jose package. You can also use identity from a validated JWT or the /cdn-cgi/access/get-identity endpoint as noted in workers.dev access.

wrangler dev can inject a fake Access context via wrangler.jsonc:

{
"access": {
"dev": {
"aud": "my-app",
"identity": { "email": "admin@example.com" }
}
}
}

Your Worker receives the same ctx.access and getIdentity() behaviour as in production. Remove the dev block to simulate unauthenticated requests. Documented in Workers Access changelog.

Create or update Access applications with the Workers API (preview_worker or worker destinations and worker_id) instead of the dashboard. Example requests appear under Protect one Worker in the Access apps API section.

Policies can also be set through the Workers API per You can now enable Access on a Worker or all Workers at once.

Who can change Workers vs who can open URLs

Section titled “Who can change Workers vs who can open URLs”

Cloudflare Access answers “who may visit this URL.” Workers roles answer “who may edit or deploy this Worker” (Metadata Read-Only, Content Read-Only, Editor, Admin at product or per-Worker scope). Dashboard invites from a Worker overview require Super Administrator; see Give teammates access to specific Workers and Workers roles and permissions. Durable Objects inherit the implementing Worker’s roles (Durable Objects roles and permissions).

Do not confuse account Workers Platform Admin with Access sign-in policies (Grant account members read-only access to the Workers Platform).

  • Listing every hostname on a self-hosted Access app while routes change, instead of worker-scoped Access.
  • Using worker-level Access on a WebSocket Worker (403 on upgrade).
  • Disabling workers.dev but assuming preview URLs are off without checking Wrangler version and explicit preview settings.
  • Relying on ctx.access with Static Assets routing.
  • Enabling Access at the edge but skipping JWT checks for sensitive APIs.
  1. In Workers & Pages, open the Worker → Access (or Settings → Domains & Routes for one-click workers.dev / Preview Access) and confirm scope: previews only vs all traffic.
  2. Open the Worker URL in a private window: unauthenticated users should see the Access login, not your Worker response.
  3. After sign-in, deploy a diagnostic route that logs await ctx.access.getIdentity() per Workers Access changelog.
  4. If the app is sensitive, confirm your code rejects requests missing or failing verification of cf-access-jwt-assertion as in One-click Cloudflare Access for Workers.
  5. You can check automatically in Answerwell (our tool): https://answerwell.org/workspace

If something on this page is wrong or unclear, email yimasynthetic@gmail.com with the page URL and the exact wording you are asking about.