Recently, a colleague of mine introduced a vulnerability to a page in development. This vulnerability allows a user to input 30 characters of unescaped code that will be executed with the |safe
filter. This means that HTML unsafe characters (<
, >
, '
, "
, or &
) can be freely added to the page template.
The vulnerability is present in an error message on a form, meaning that a hacker cannot alter what other users see, only themselves. I would like to demonstrate to my coworker the potential danger of this vulnerability with a shocking example. Additionally, I am curious on a professional level about the worst-case scenario with such a vulnerability. In PHP (possibly older versions), this type of vulnerability could allow a user to display the contents of server files. Would it be possible to do something similar with the settings file using this vulnerability? Fortunately, the Django Devs have made the wise decision to not escape {
even with the |safe
filter, preventing users from displaying context variables.
So far, the most severe scenario I have thought of is the insertion (and execution) of any JavaScript file from the web, which could be catastrophic if it impacted other users. However, if the JavaScript file only affects the hacker themselves, it may not be as concerning.