Sanitize rendered custom link HTML #7880

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

Originally created by @jeremystretch on GitHub (Apr 7, 2023).

Originally assigned to: @jeremystretch on GitHub.

NetBox version

v3.4.7

Feature type

Change to existing functionality

Proposed functionality

Custom links enable users to craft customized buttons in the UI relevant to particular objects. Both the link URL and text can be rendered from a Jinja2 template.

This FR proposes sanitizing the rendered URL and text to guard against potentially malicious content. We should be able to utilize the clean_html() utility function already in place for this purpose. The sanitization would occur after either piece of content has been fully rendered by the Jinja2 engine.

Use case

Ensures well-formed content and mitigates the risk of users crafting malicious links.

Database changes

No response

External dependencies

No response

Originally created by @jeremystretch on GitHub (Apr 7, 2023). Originally assigned to: @jeremystretch on GitHub. ### NetBox version v3.4.7 ### Feature type Change to existing functionality ### Proposed functionality [Custom links](https://docs.netbox.dev/en/stable/customization/custom-links/) enable users to craft customized buttons in the UI relevant to particular objects. Both the link URL and text can be rendered from a Jinja2 template. This FR proposes sanitizing the rendered URL and text to guard against potentially malicious content. We should be able to utilize the `clean_html()` utility function already in place for this purpose. The sanitization would occur _after_ either piece of content has been fully rendered by the Jinja2 engine. ### Use case Ensures well-formed content and mitigates the risk of users crafting malicious links. ### Database changes _No response_ ### External dependencies _No response_
adam added the status: acceptedtype: feature labels 2025-12-29 20:29:28 +01:00
adam closed this issue 2025-12-29 20:29:28 +01:00
Author
Owner

@jeremystretch commented on GitHub (Apr 21, 2023):

Thanks @x64x6a for implementing this in 89fa546!

@jeremystretch commented on GitHub (Apr 21, 2023): Thanks @x64x6a for implementing this in 89fa546!
Author
Owner

@x64x6a commented on GitHub (Apr 26, 2023):

Sorry, but I just noticed that my commit has a bug that encodes '%' and '=', so links with GET parameters or URL encoded values would be failing.

I believe this line - 89fa546a14 (diff-7cd550a7e9a8bf633ee98ba17fdb140a64186bf257070850a6edc93e09b00004R282)

        link = urllib.parse.quote_plus(link, safe='/:?&')

Would need to add '%=' to safe in order for them to be ignored so they are not encoded:

        link = urllib.parse.quote_plus(link, safe='/:?&%=')
@x64x6a commented on GitHub (Apr 26, 2023): Sorry, but I just noticed that my commit has a bug that encodes '%' and '=', so links with GET parameters or URL encoded values would be failing. I believe this line - https://github.com/netbox-community/netbox/commit/89fa546a1481e56d14cfc4d666a55482b0c85fd1#diff-7cd550a7e9a8bf633ee98ba17fdb140a64186bf257070850a6edc93e09b00004R282 ``` link = urllib.parse.quote_plus(link, safe='/:?&') ``` Would need to add '%=' to `safe` in order for them to be ignored so they are not encoded: ``` link = urllib.parse.quote_plus(link, safe='/:?&%=') ```
Author
Owner

@x64x6a commented on GitHub (Apr 26, 2023):

Should we create a separate issue to resolve that issue or re-open this ticket?
I created a fork of the change - 032d4e1101

@x64x6a commented on GitHub (Apr 26, 2023): Should we create a separate issue to resolve that issue or re-open this ticket? I created a fork of the change - https://github.com/netbox-community/netbox/commit/032d4e1101655e24286371081a9246445cdb6089
Author
Owner

@jeremystretch commented on GitHub (Apr 26, 2023):

@x64x6a thanks for catching that. I've opened #12355 to track this if you'd like to submit a PR from your fork.

@jeremystretch commented on GitHub (Apr 26, 2023): @x64x6a thanks for catching that. I've opened #12355 to track this if you'd like to submit a PR from your fork.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#7880