Wrong HTTP code when redirecting in response to a POST request #6683

Closed
opened 2025-12-29 19:43:55 +01:00 by adam · 4 comments
Owner

Originally created by @piv3rt on GitHub (Jul 18, 2022).

NetBox version

v3.2.6

Python version

3.9

Steps to Reproduce

  1. The user creates a new "Region" object by submitting the form
  2. A POST request is sent by the browser to dcim/regions/add/
  3. Netbox responds with a 302 Found to redirect the user to dcim/regions/1/
  4. Browser complies with RFC 7231 and sends a new POST request to dcim/regions/1/
  5. Netbox responds with a 405 Method Not Allowed as it expected a GET request, and POST requests aren't supported for dcim/regions/1/

Expected Behavior

In regards to RFC 7231, I think Netbox should respond with a 303 See Other to redirect the user to dcim/regions/1/.

Observed Behavior

Netbox responds to a POST request with a 302 Found, but expects the following request method to bet GET.
This happens because of the use of Django's redirect() shortcut in object_views.py, which is based on HttpResponseRedirect and returns a 302 Found.

Originally created by @piv3rt on GitHub (Jul 18, 2022). ### NetBox version v3.2.6 ### Python version 3.9 ### Steps to Reproduce 1. The user creates a new "Region" object by submitting the form 2. A `POST` request is sent by the browser to `dcim/regions/add/` 3. Netbox responds with a `302 Found` to redirect the user to `dcim/regions/1/` 4. Browser complies with [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.4) and sends a new `POST` request to `dcim/regions/1/` 5. Netbox responds with a `405 Method Not Allowed` as it expected a `GET` request, and `POST` requests aren't supported for `dcim/regions/1/` ### Expected Behavior In regards to [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.4), I think Netbox should respond with a `303 See Other` to redirect the user to `dcim/regions/1/`. ### Observed Behavior Netbox responds to a `POST` request with a `302 Found`, but expects the following request method to bet `GET`. This happens because of the use of Django's `redirect()` shortcut in [object_views.py](https://github.com/netbox-community/netbox/blob/develop/netbox/netbox/views/generic/object_views.py#L404), which is based on `HttpResponseRedirect` and returns a `302 Found`.
adam added the type: bug label 2025-12-29 19:43:55 +01:00
adam closed this issue 2025-12-29 19:43:55 +01:00
Author
Owner

@kkthxbye-code commented on GitHub (Jul 18, 2022):

Browser complies with RFC 7231 and sends a new POST request to dcim/regions/1/

For completeness sake could you specify which browser(s)?

@kkthxbye-code commented on GitHub (Jul 18, 2022): > Browser complies with [RFC 7231](https://datatracker.ietf.org/doc/html/rfc7231#section-6.4.4) and sends a new POST request to dcim/regions/1/ For completeness sake could you specify which browser(s)?
Author
Owner

@piv3rt commented on GitHub (Jul 18, 2022):

In my specific case, it's homemade cloud gateway (reverse proxy), not a desktop web browser. Sorry for this approximation. I understand that this problem might affect few people, as most browsers redirect users with a new GET request.

@piv3rt commented on GitHub (Jul 18, 2022): In my specific case, it's homemade cloud gateway (reverse proxy), not a desktop web browser. Sorry for this approximation. I understand that this problem might affect few people, as most browsers redirect users with a new `GET` request.
Author
Owner

@jeremystretch commented on GitHub (Jul 18, 2022):

While I can appreciate wanting to adhere to the semantics of the RFC, returning a 302 redirect to invoke a GET request following a POST is extremely commonplace, so much so that even Django's canonical form processing example does exactly that. I'm sure the argument has come up before, but ultimately needs to happen much further upstream than in NetBox itself. Additionally, we don't want to invite new problems where none currently exist by altering long-established behavior. For those reasons, I'm going to decline this proposed change.

@jeremystretch commented on GitHub (Jul 18, 2022): While I can appreciate wanting to adhere to the semantics of the RFC, returning a 302 redirect to invoke a GET request following a POST is _extremely_ commonplace, so much so that even [Django's canonical form processing example](https://docs.djangoproject.com/en/4.0/topics/forms/#the-view) does exactly that. I'm sure the argument has come up before, but ultimately needs to happen much further upstream than in NetBox itself. Additionally, we don't want to invite new problems where none currently exist by altering long-established behavior. For those reasons, I'm going to decline this proposed change.
Author
Owner

@piv3rt commented on GitHub (Jul 18, 2022):

Thank you for taking the time to answer, I understand your point of view 🙂

@piv3rt commented on GitHub (Jul 18, 2022): Thank you for taking the time to answer, I understand your point of view 🙂
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6683