Pattern: Potential XSS on mark_safe
Issue: -
Using Django templates protects you against the majority of XSS attacks. However, it is important to understand what protections it provides and its limitations.
It is also important to be particularly careful when using is_safe
with custom template tags, the safe
template tag, mark_safe
, and when autoescape is turned off.
XSS attacks allow a user to inject client side scripts into the browsers of other users. This is usually achieved by storing the malicious scripts in the database where it will be retrieved and displayed to other users, or by getting users to click a link which will cause the attacker’s JavaScript to be executed by the user’s browser. However, XSS attacks can originate from any untrusted source of data, such as cookies or Web services, whenever the data is not sufficiently sanitized before including in a page.