Allow access to cookies from netbox scripts feature #7228

Closed
opened 2025-12-29 20:20:40 +01:00 by adam · 0 comments
Owner

Originally created by @uedvt359 on GitHub (Nov 15, 2022).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.3.7

Feature type

Change to existing functionality

Proposed functionality

We need to be able to access cookies from Netbox Scripts, so we can pass the Secret Store Plugin Session Key (that is stored in a cookie). Right now, we modified the utils.py copy_safe_request() function to also expose those.

--- netbox/netbox/utilities/utils.py       2022-11-04 11:52:55.773780916 +0100
+++ netbox/netbox/utilities/utils.py       2022-11-02 08:50:06.691425078 +0100
@@ -342,6 +342,7 @@
     }
     return NetBoxFakeRequest({
         'META': meta,
+        'COOKIES': request.COOKIES,
         'POST': request.POST,
         'GET': request.GET,
         'FILES': request.FILES,

Use case

We need to store a secret from a "Create Device" Script. If the proposed patch is accepted, the following code works:

        session_key = self.request.COOKIES.get('session_key')
        sk = SessionKey.objects.get(userkey__user=self.request.user)
        master_key = sk.get_master_key(base64.b64decode(session_key))

It appears, this feature request was previously submitted as https://github.com/netbox-community/netbox/issues/7672, but got auto-closed due to inactivity.

Database changes

none.

External dependencies

none.

Originally created by @uedvt359 on GitHub (Nov 15, 2022). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.3.7 ### Feature type Change to existing functionality ### Proposed functionality We need to be able to access cookies from Netbox Scripts, so we can pass the Secret Store Plugin Session Key (that is stored in a cookie). Right now, we modified the utils.py `copy_safe_request()` function to also expose those. ```patch --- netbox/netbox/utilities/utils.py 2022-11-04 11:52:55.773780916 +0100 +++ netbox/netbox/utilities/utils.py 2022-11-02 08:50:06.691425078 +0100 @@ -342,6 +342,7 @@ } return NetBoxFakeRequest({ 'META': meta, + 'COOKIES': request.COOKIES, 'POST': request.POST, 'GET': request.GET, 'FILES': request.FILES, ``` ### Use case We need to store a secret from a "Create Device" Script. If the proposed patch is accepted, the following code works: session_key = self.request.COOKIES.get('session_key') sk = SessionKey.objects.get(userkey__user=self.request.user) master_key = sk.get_master_key(base64.b64decode(session_key)) It appears, this feature request was previously submitted as https://github.com/netbox-community/netbox/issues/7672, but got auto-closed due to inactivity. ### Database changes none. ### External dependencies none.
adam added the status: acceptedtype: feature labels 2025-12-29 20:20:40 +01:00
adam closed this issue 2025-12-29 20:20:40 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7228