Enable HttpOnly flag for the CSRF cookie #11554

Closed
opened 2025-12-29 21:46:41 +01:00 by adam · 1 comment
Owner

Originally created by @jetomit on GitHub (Sep 2, 2025).

Originally assigned to: @jetomit on GitHub.

NetBox version

v4.2.9

Feature type

Other

Proposed functionality

Enable the Django setting CSRF_COOKIE_HTTPONLY.

If there are any plugins that access the CSRF cookie from JS code instead of using the window.CSRF_TOKEN property (see https://github.com/netbox-community/netbox/pull/10205), they might break. So alternatively make the setting configurable by adding to settings.py:

CSRF_COOKIE_HTTPONLY = getattr(configuration, 'CSRF_COOKIE_HTTPONLY', False)

I have tested CSRF_COOKIE_HTTPONLY = True in our environment according to steps described in https://github.com/netbox-community/netbox/issues/9963 and found no issues. I’ll be happy to submit a pull request if this proposal is accepted. Thanks!

Use case

Mainly to appease our auditors. The security benefit is marginal, but there should be no downside (except as described above if the setting is enabled unconditionally).

Database changes

None.

External dependencies

None.

Originally created by @jetomit on GitHub (Sep 2, 2025). Originally assigned to: @jetomit on GitHub. ### NetBox version v4.2.9 ### Feature type Other ### Proposed functionality Enable the Django setting [`CSRF_COOKIE_HTTPONLY`](https://docs.djangoproject.com/en/stable/ref/settings/#csrf-cookie-httponly). If there are any plugins that access the CSRF cookie from JS code instead of using the `window.CSRF_TOKEN` property (see https://github.com/netbox-community/netbox/pull/10205), they might break. So alternatively make the setting configurable by adding to `settings.py`: CSRF_COOKIE_HTTPONLY = getattr(configuration, 'CSRF_COOKIE_HTTPONLY', False) I have tested `CSRF_COOKIE_HTTPONLY = True` in our environment according to steps described in https://github.com/netbox-community/netbox/issues/9963 and found no issues. I’ll be happy to submit a pull request if this proposal is accepted. Thanks! ### Use case Mainly to appease our auditors. The security benefit is marginal, but there should be no downside (except as described above if the setting is enabled unconditionally). ### Database changes None. ### External dependencies None.
adam added the status: acceptedtype: featurecomplexity: low labels 2025-12-29 21:46:42 +01:00
adam closed this issue 2025-12-29 21:46:42 +01:00
Author
Owner

@bctiemann commented on GitHub (Sep 4, 2025):

Seems reasonable to do this by just setting it to True rather than introducing a new configurable setting. No downsides I can see.

@bctiemann commented on GitHub (Sep 4, 2025): Seems reasonable to do this by just setting it to True rather than introducing a new configurable setting. No downsides I can see.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#11554