netbox.js doesn't reference custom CSRF cookie #6793

Closed
opened 2025-12-29 19:45:27 +01:00 by adam · 2 comments
Owner

Originally created by @tyler-8 on GitHub (Aug 9, 2022).

Originally assigned to: @arthanson on GitHub.

NetBox version

v3.2.8

Python version

3.9

Steps to Reproduce

  1. In configuration.py set the CSRF_COOKIE_NAME value to something other than default (csrftoken)
  2. Login to NetBox
  3. Navigate to Circuits > Circuits.
  4. Click the Filter tab
  5. Open your browser's dev tools console
  6. Click on any filter dropdown (Tenant for example)

Expected Behavior

Dropdown data is populated and selectable.

Observed Behavior

The dropdown is empty and the dev tool's console shows the following error:

netbox.js?v=3.2.8:9 Error: Invalid or missing CSRF token
    at wI (netbox.js?v=3.2.8:8:143492)
    at netbox.js?v=3.2.8:8:143606
    at Generator.next (<anonymous>)
    at netbox.js?v=3.2.8:1:1413
    at new Promise (<anonymous>)
    at Fr (netbox.js?v=3.2.8:1:1202)
    at ny (netbox.js?v=3.2.8:8:143574)
    at netbox.js?v=3.2.8:9:195
    at Generator.next (<anonymous>)
    at netbox.js?v=3.2.8:1:1413
(anonymous) @ netbox.js?v=3.2.8:9
ln @ netbox.js?v=3.2.8:1
Promise.then (async)
cn @ netbox.js?v=3.2.8:1
(anonymous) @ netbox.js?v=3.2.8:1
Fr @ netbox.js?v=3.2.8:1
loadData @ netbox.js?v=3.2.8:9
slim.beforeOpen @ netbox.js?v=3.2.8:9
hn.open @ netbox.js?v=3.2.8:9
gn.onclick @ netbox.js?v=3.2.8:9

Related https://github.com/netbox-community/netbox/issues/9277

I believe this line is at issue b318b79027/netbox/project-static/src/util.ts (L100)

as the compiled netbox.js file shows:

{let{csrftoken:tn}=Zb.default.parse(document.cookie);if(typeof tn=="undefined")throw new Error("Invalid or missing CSRF token")

Somehow this line will have to be dynamically read/updated based on the CSRF_COOKIE_NAME value.

Originally created by @tyler-8 on GitHub (Aug 9, 2022). Originally assigned to: @arthanson on GitHub. ### NetBox version v3.2.8 ### Python version 3.9 ### Steps to Reproduce 1. In `configuration.py` set the `CSRF_COOKIE_NAME` value to something other than default (`csrftoken`) 2. Login to NetBox 3. Navigate to Circuits > Circuits. 4. Click the Filter tab 5. Open your browser's dev tools console 6. Click on any filter dropdown (`Tenant` for example) ### Expected Behavior Dropdown data is populated and selectable. ### Observed Behavior The dropdown is empty and the dev tool's console shows the following error: ``` netbox.js?v=3.2.8:9 Error: Invalid or missing CSRF token at wI (netbox.js?v=3.2.8:8:143492) at netbox.js?v=3.2.8:8:143606 at Generator.next (<anonymous>) at netbox.js?v=3.2.8:1:1413 at new Promise (<anonymous>) at Fr (netbox.js?v=3.2.8:1:1202) at ny (netbox.js?v=3.2.8:8:143574) at netbox.js?v=3.2.8:9:195 at Generator.next (<anonymous>) at netbox.js?v=3.2.8:1:1413 (anonymous) @ netbox.js?v=3.2.8:9 ln @ netbox.js?v=3.2.8:1 Promise.then (async) cn @ netbox.js?v=3.2.8:1 (anonymous) @ netbox.js?v=3.2.8:1 Fr @ netbox.js?v=3.2.8:1 loadData @ netbox.js?v=3.2.8:9 slim.beforeOpen @ netbox.js?v=3.2.8:9 hn.open @ netbox.js?v=3.2.8:9 gn.onclick @ netbox.js?v=3.2.8:9 ``` Related https://github.com/netbox-community/netbox/issues/9277 I believe this line is at issue https://github.com/netbox-community/netbox/blob/b318b7902753c438379c1ec19fa12b765cff5e72/netbox/project-static/src/util.ts#L100 as the compiled `netbox.js` file shows: ``` {let{csrftoken:tn}=Zb.default.parse(document.cookie);if(typeof tn=="undefined")throw new Error("Invalid or missing CSRF token") ``` Somehow this line will have to be dynamically read/updated based on the `CSRF_COOKIE_NAME` value.
adam added the type: bugstatus: accepted labels 2025-12-29 19:45:27 +01:00
adam closed this issue 2025-12-29 19:45:27 +01:00
Author
Owner

@jsenecal commented on GitHub (Aug 18, 2022):

An approach into resolving this would be to have a templated javascript file with the configuration variables in it so that the client side netbox.js could access them. This "file" could then be included as a <script> in netbox base templates.

@jsenecal commented on GitHub (Aug 18, 2022): An approach into resolving this would be to have a templated javascript file with the configuration variables in it so that the client side netbox.js could access them. This "file" could then be included as a <script> in netbox base templates.
Author
Owner

@arthanson commented on GitHub (Aug 29, 2022):

Note: I couldn't repro this with the steps above, but going to any table (Devices) and Configure table and doing the save on the dialog will produce this error.

@arthanson commented on GitHub (Aug 29, 2022): Note: I couldn't repro this with the steps above, but going to any table (Devices) and Configure table and doing the save on the dialog will produce this error.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#6793