---
title: "Workers - Reject redirects in Workers fetch requests — Cloud Changelog"
description: "Cloudflare Workers now supports redirect: \"error\" in fetch() and Request, completing support for all three redirect modes defined by the WHATWG Fetch Stan…"
url: "https://cloudchangelog.com/cloudflare/2026-11-28-fetch-redirect-error"
updated: "2026-11-29"
---

[Back to feed](https://cloudchangelog.com/feed/2026-W48)

November 28, 2026 · Cloudflare

# Workers - Reject redirects in Workers fetch requests

- [Workers](https://cloudchangelog.com/products/cloudflare/workers)
- [Serverless](https://cloudchangelog.com/search?q=serverless)

## What changed

**Workers fetch redirect: error:** fetch() and Request support redirect: "error", rejecting with a TypeError on 301, 302, 303, 307 or 308.

Cloudflare Workers now supports `redirect: "error"` in [`fetch()`](https://developers.cloudflare.com/workers/runtime-apis/fetch/) and [`Request`](https://developers.cloudflare.com/workers/runtime-apis/request/), completing support for all three redirect modes defined by the [WHATWG Fetch Standard ↗︎](https://fetch.spec.whatwg.org/#requestredirect): `follow`, `manual`, and `error`.

When the server responds with a redirect status (`301`, `302`, `303`, `307`, or `308`), `fetch()` with `redirect: "error"` rejects with a `TypeError` without contacting the redirect destination. It rejects even if the response has no `Location` header. Non-redirect `3xx` responses, such as `304 Not Modified`, resolve normally.

Use `redirect: "error"` to:

- **Protect credentials and secrets**: Fail closed on OAuth token exchanges, signed webhooks, and API calls carrying sensitive headers (such as `Cookie`, `X-API-Key`, or `Authorization`) so redirects cannot forward headers to another destination.
- **Prevent server-side request forgery (SSRF) redirect hops**: After you validate a user-supplied URL, block redirects to unvalidated hosts. This applies to webhook targets, link previews, and feed fetchers.
- **Enforce strict API contracts**: Catch unexpected redirects (such as an upstream API redirecting to an HTML sign-in page) immediately instead of following them, consuming extra subrequests, and failing later during response parsing.
- **Share code across runtimes**: Use the same `redirect: "error"` option in Workers and browsers when your code needs to reject redirects.

src/index.jsjs

```
export default {
	async fetch(request, env) {
		try {
			const response = await fetch("https://api.example.com/v1/token", {
				method: "POST",
				headers: {
					"X-API-Key": env.API_KEY,
				},
				redirect: "error",
			});

			return response;
		} catch {
			return new Response(
				"Upstream request failed or returned an unexpected redirect",
				{
					status: 502,
				},
			);
		}
	},
};
```

src/index.tsts

```
export default {
	async fetch(request, env): Promise<Response> {
		try {
			const response = await fetch("https://api.example.com/v1/token", {
				method: "POST",
				headers: {
					"X-API-Key": env.API_KEY,
				},
				redirect: "error",
			});

			return response;
		} catch {
			return new Response(
				"Upstream request failed or returned an unexpected redirect",
				{
					status: 502,
				},
			);
		}
	},
} satisfies ExportedHandler<{ API_KEY: string }>;
```

This mode is enabled by default for Workers with a [compatibility date](https://developers.cloudflare.com/workers/configuration/compatibility-dates/) of `2026-12-22` or later. To opt in on an earlier compatibility date, add the [`fetch_redirect_error`](https://developers.cloudflare.com/workers/configuration/compatibility-flags/#reject-redirects-in-fetch) compatibility flag:

```
{
  "$schema": "./node_modules/wrangler/config-schema.json",
  "compatibility_flags": [
    "fetch_redirect_error"
  ]
}
```

```
compatibility_flags = ["fetch_redirect_error"]
```

For compatibility dates on or after `2026-12-22`, add `no_fetch_redirect_error` to opt out. If you pass a URL to `fetch()` or `new Request()`, the default is `follow`. If you pass an existing `Request`, both use its redirect mode unless you override it. Incoming requests use `manual`.

For more information, refer to [Redirect handling](https://developers.cloudflare.com/workers/runtime-apis/request/#redirect-handling) and the [`fetch_redirect_error` compatibility flag](https://developers.cloudflare.com/workers/configuration/compatibility-flags/#reject-redirects-in-fetch).

Get the week’s Cloudflare changes in one email

Your email address

Free, every Monday: only what changed in Cloudflare that week. We email you a link to confirm.

[See last week’s digest](https://cloudchangelog.com/digests/weekly-2026-W47#provider-cloudflare)

Free. Unsubscribe any time.

[Read on developers.cloudflare.com](https://developers.cloudflare.com/changelog/post/2026-11-28-fetch-redirect-error/)

[All Workers changes](https://cloudchangelog.com/products/cloudflare/workers)

## Contact

- [YouTube](https://www.youtube.com/@cloudchangelog)
