Custom script log functions do not escape HTML entities #2917

Closed
opened 2025-12-29 18:23:24 +01:00 by adam · 1 comment
Owner

Originally created by @fchiron-qualys on GitHub (Sep 30, 2019).

Environment

  • Python version: 3.6.8
  • NetBox version: 2.6.5

Steps to Reproduce

  1. Create a custom with logs containing HTML tag-looking data like output of python type()
  2. Run the script
from extras.scripts import Script

class LogBugScript(Script):
    description = "HTML entities not escaped"

    def run(self, data):
        self.log_debug("int type: {}".format(type(2)))
        self.log_success("int type [fixed]: {}".format(type(2)).replace("<", "&lt;"))
        self.log_info("<pre>Can be nice</pre>")
        self.log_warning("<pre>Or not</pre>")
        self.log_failure("JS injection...<script lang='javascript'>alert('XSS')</script>")

output

log_* functions should escape HTML entities

log_* just output passed string as-is avoiding output of some texts and opening possibility of code injection.

Originally created by @fchiron-qualys on GitHub (Sep 30, 2019). <!-- NOTE: This form is only for reproducible bugs. If you need assistance with NetBox installation, or if you have a general question, DO NOT open an issue. Instead, post to our mailing list: https://groups.google.com/forum/#!forum/netbox-discuss Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.8 * NetBox version: 2.6.5 ### Steps to Reproduce 1. Create a custom with logs containing HTML tag-looking data like output of python type() 2. Run the script ``` from extras.scripts import Script class LogBugScript(Script): description = "HTML entities not escaped" def run(self, data): self.log_debug("int type: {}".format(type(2))) self.log_success("int type [fixed]: {}".format(type(2)).replace("<", "&lt;")) self.log_info("<pre>Can be nice</pre>") self.log_warning("<pre>Or not</pre>") self.log_failure("JS injection...<script lang='javascript'>alert('XSS')</script>") ``` ![output](https://user-images.githubusercontent.com/55992072/65899904-04c33b00-e3b5-11e9-8bc0-9363718308c9.jpg) <!-- What did you expect to happen? --> log_* functions should escape HTML entities <!-- What happened instead? --> log_* just output passed string as-is avoiding output of some texts and opening possibility of code injection.
adam closed this issue 2025-12-29 18:23:25 +01:00
Author
Owner

@jeremystretch commented on GitHub (Oct 7, 2019):

Folding this into #3471

@jeremystretch commented on GitHub (Oct 7, 2019): Folding this into #3471
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2917