Jump to solution
Details

The Fix

Changed the default redirect code from 302 to 303 in Flask's redirect function, ensuring that all redirects result in a GET request.

Based on closed pallets/flask issue #5895 · PR/commit linked

Production note: Most teams hit this during upgrades or environment changes. Roll out with a canary and smoke critical endpoints (health, OpenAPI/docs) before 100%.

Open PR/Commit
@@ -16,6 +16,11 @@ Unreleased - ``template_filter``, ``template_test``, and ``template_global`` decorators can be used without parentheses. :issue:`5729` +- ``redirect`` returns a ``303`` status code by default instead of ``302``. + This tells the client to always switch to ``GET``, rather than only + switching ``POST`` to ``GET``. This preserves the current behavior of
fix.md
Option A — Apply the official fix\nChanged the default redirect code from 302 to 303 in Flask's redirect function, ensuring that all redirects result in a GET request.\nWhen NOT to use: This fix is not suitable if the application relies on the 302 behavior for specific redirect scenarios.\n\n

Why This Fix Works in Production

  • Trigger: change default redirect code to 303
  • Mechanism: The default redirect code in Flask was set to 302 instead of 303, which can lead to incorrect HTTP method handling
Production impact:
  • If left unfixed, the same config can fail only in production (env differences), causing startup failures or partial feature outages.

Why This Breaks in Prod

  • The default redirect code in Flask was set to 302 instead of 303, which can lead to incorrect HTTP method handling
  • Production symptom (often without a traceback): change default redirect code to 303

Proof / Evidence

Discussion

High-signal excerpts from the issue thread (symptoms, repros, edge-cases).

“Flask and Werkzeug redirect currently defaults to a 302. Routing uses 307 since that preserves method consistently. We didn't change the redirect default to 307, since that would break the common pattern of "GET form, POST form, redirect to”
Issue thread · issue description · source

Failure Signature (Search String)

  • change default redirect code to 303
Copy-friendly signature
signature.txt
Failure Signature ----------------- change default redirect code to 303

Error Message

Signature-only (no traceback captured)
error.txt
Error Message ------------- change default redirect code to 303

What Broke

Users experienced unexpected behavior when redirecting POST requests, potentially leading to incorrect method usage.

Why It Broke

The default redirect code in Flask was set to 302 instead of 303, which can lead to incorrect HTTP method handling

Fix Options (Details)

Option A — Apply the official fix

Changed the default redirect code from 302 to 303 in Flask's redirect function, ensuring that all redirects result in a GET request.

When NOT to use: This fix is not suitable if the application relies on the 302 behavior for specific redirect scenarios.

Option D — Guard side-effects with OnceOnly Guardrail for side-effects

Mitigate duplicate external side-effects under retries/timeouts/agent loops by gating the operation before calling external systems.

  • Place OnceOnly between your code/agent and real side-effects (Stripe, emails, CRM, APIs).
  • Use a stable key per side-effect (e.g., customer_id + action + idempotency_key).
  • Fail-safe: configure fail-open vs fail-closed based on blast radius and spend risk.
Show example snippet (optional)
onceonly.py
from onceonly import OnceOnly import os once = OnceOnly(api_key=os.environ["ONCEONLY_API_KEY"], fail_open=True) # Stable idempotency key per real side-effect. # Use a request id / job id / webhook delivery id / Stripe event id, etc. event_id = "evt_..." # replace key = f"stripe:webhook:{event_id}" res = once.check_lock(key=key, ttl=3600) if res.duplicate: return {"status": "already_processed"} # Safe to execute the side-effect exactly once. handle_event(event_id)

See OnceOnly SDK

When NOT to use: Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

Fix reference: https://github.com/pallets/flask/pull/5898

Last verified: 2026-02-09. Validate in your environment.

Get updates

We publish verified fixes weekly. No spam.

Subscribe

When NOT to Use This Fix

  • This fix is not suitable if the application relies on the 302 behavior for specific redirect scenarios.
  • Do not use this to hide logic bugs or data corruption. Use it to block duplicate external side-effects and enforce tool permissions/spend caps.

Did This Fix Work in Your Case?

Quick signal helps us prioritize which fixes to verify and improve.

Prevention

  • Capture the exact failing error string in logs and tests so you can reproduce via a minimal script.
  • Pin production dependencies and upgrade only with a reproducible test that hits the failing path.

Related Issues

No related fixes found.

Sources

We don’t republish the full GitHub discussion text. Use the links above for context.