Avoid absolute URIs (with hostname) in SVG renders #9931

Closed
opened 2025-12-29 21:24:37 +01:00 by adam · 3 comments
Owner

Originally created by @uedvt359 on GitHub (Jul 2, 2024).

NetBox version

v4.0.3

Feature type

Change to existing functionality

Proposed functionality

Right now, the RackElevationSVG (and likely others) generate URLs that include schema and hostname. I propose to switch this to relative URLs (a.k.a path-absolute without schema or authority).

a.k.a:

@@ https://netbox.example.com/api/dcim/racks/406/elevation/?face=front&render=svg @@
-<a target="_parent" xlink:href="https://netbox.example.com/dcim/devices/9186/">
+<a target="_parent" xlink:href="/dcim/devices/9186/">

A cursory look suggests that "just" this line needs to be removed (and equivalent patches for other SVGs):

4857a87be5/netbox/dcim/api/views.py (L207)

In order to not break the "Download SVG" button, I propose a URL query parameter (e.g. absoluteURLs=true) to switch them back on when necessary. I also verified that embedding these graphics on external pages still works with relative domains.

I'd gladly submit a PR for these changes.

Use case

We are reverse-proxying Netbox for some external users, and the reverse-proxy automatically rewrites the Host: header from netbox.proxy.example.com back to netbox.example.com (the url used directly internally). So right now, when clicking on a device in the virtual rack, the link redirects the user to the backend-URL (which they can't reach).

Most other links in Netbox are already relative, including the "add device" ones in the RackElevationSVG, so I don't expect any fallout from implementing this.

Database changes

none

External dependencies

none

Originally created by @uedvt359 on GitHub (Jul 2, 2024). ### NetBox version v4.0.3 ### Feature type Change to existing functionality ### Proposed functionality Right now, the RackElevationSVG (and likely others) generate URLs that include schema and hostname. I propose to switch this to relative URLs (a.k.a path-absolute without schema or authority). a.k.a: ```diff @@ https://netbox.example.com/api/dcim/racks/406/elevation/?face=front&render=svg @@ -<a target="_parent" xlink:href="https://netbox.example.com/dcim/devices/9186/"> +<a target="_parent" xlink:href="/dcim/devices/9186/"> ``` A cursory look suggests that "just" this line needs to be removed (and equivalent patches for other SVGs): https://github.com/netbox-community/netbox/blob/4857a87be5bd357b3d583ecb99a7841d75c9da35/netbox/dcim/api/views.py#L207 In order to not break the "Download SVG" button, I propose a URL query parameter (e.g. `absoluteURLs=true`) to switch them back on when necessary. I also verified that embedding these graphics on external pages still works with relative domains. I'd gladly submit a PR for these changes. ### Use case We are reverse-proxying Netbox for some external users, and the reverse-proxy automatically rewrites the `Host:` header from `netbox.proxy.example.com` back to `netbox.example.com` (the url used directly internally). <!--This rewriting functionality is needed, so multiple websites/domains can co-exist on a single httpd server.--> So right now, when clicking on a device in the virtual rack, the link redirects the user to the backend-URL (which they can't reach). Most other links in Netbox are already relative, including the "add device" ones in the RackElevationSVG, so I don't expect any fallout from implementing this. ### Database changes none ### External dependencies none
adam added the type: feature label 2025-12-29 21:24:37 +01:00
adam closed this issue 2025-12-29 21:24:38 +01:00
Author
Owner

@jeremystretch commented on GitHub (Jul 2, 2024):

Absolute URLs must be used as the SVG document may be embedded or saved outside NetBox itself, and relative links would not function.

@jeremystretch commented on GitHub (Jul 2, 2024): Absolute URLs must be used as the SVG document may be embedded or saved outside NetBox itself, and relative links would not function.
Author
Owner

@uedvt359 commented on GitHub (Jul 2, 2024):

embedding them externally will continue to work (i just tested this locally; this config line needs to be removed) with my patch.

for saving the SVGs with the "download" button, I would propose adding a URL query parameter like absoluteURLs=true that toggles this on.

@uedvt359 commented on GitHub (Jul 2, 2024): embedding them externally will continue to work (i just tested this locally; [this config line](https://github.com/netbox-community/netbox/blob/4857a87be5bd357b3d583ecb99a7841d75c9da35/netbox/netbox/settings.py#L386) needs to be removed) with my patch. for saving the SVGs with the "download" button, I would propose adding a URL query parameter like `absoluteURLs=true` that toggles this on.
Author
Owner

@uedvt359 commented on GitHub (Jul 3, 2024):

Apologies for requesting some more of your time, @jeremystretch. But can this please be reconsidered, with the changes to the proposal I suggested in the previous comment? I believe this should address your use-cases as well, then.

@uedvt359 commented on GitHub (Jul 3, 2024): Apologies for requesting some more of your time, @jeremystretch. But can this please be reconsidered, with the changes to the proposal I suggested in the previous comment? I believe this should address your use-cases as well, then.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#9931