What's the difference between a 302 FOUND
and a 307 TEMPORARY REDIRECT
HTTP response?
The W3 spec seems to indicate that they're both used for temporary redirects, and neither can be cached unless the response specifically allows it.
What's the difference between a 302 FOUND
and a 307 TEMPORARY REDIRECT
HTTP response?
The W3 spec seems to indicate that they're both used for temporary redirects, and neither can be cached unless the response specifically allows it.
In some use cases, 307 redirects might be abused by an attacker to learn the victim's credentials.
Further information can be found in section 3.1 of A Comprehensive Formal Security Analysis of OAuth 2.0.
The authors of the above paper suggest the following:
The difference concerns redirecting
POST
,PUT
andDELETE
requests and what the expectations of the server are for the user agent behavior (RFC 2616
):Also, read Wikipedia article on the 30x redirection codes.
307 came about because user agents adopted as a de facto behaviour to take POST requests that receive a 302 response and send a GET request to the Location response header.
That is the incorrect behaviour — only a 303 should cause a POST to turn into a GET. User agents should (but don't) stick with the POST method when requesting the new URL if the original POST request returned a 302.
307 was introduced to allow servers to make it clear to the user agent that a method change should not be made by the client when following the Location response header.
Also, for server admins, it may be important to note that browsers may present a prompt to the user if you use 307 redirect.
For example*, Firefox and Opera would ask the user for permission to redirect, whereas Chrome, IE and Safari would do the redirect transparently.
*per Bulletproof SSL and TLS (page 192).
A good example of the
307 Internal Redirect
in action is when Google Chrome encounters a HTTP call to a domain it knows as requiring Strict Transport Security.The browser redirects seamlessly, using the same method as the original call.
EXPECTED for 302: redirect uses same request method POST on NEW_URL
ACTUAL for 302, 303: redirect changes request method from POST to GET on NEW_URL
ACTUAL for 307: redirect uses same request method POST on NEW_URL