In another forum thread, Ken made a side note:
This is curious and I have some questions but since it is kind of a unique issue, I decided to start a new thread. So here it is.
For slightly additional context, here is the template I am currently working with:
{% extends 'base.html' %}
{% block content %}
{% if contents %}
{{ contents.body|safe }}
{% endif %}
{% endblock %}
But the specific line in question Ken already identified which is the one that reads: {{ contents.body|safe }}
The Django docs explain built-in filters available for writing templates. Here is the marker for the safe filter in the docs. It’s used to enable website users to add body text content with HTML markup.
In the use case for my CMS website, the only users with the permission to add content to that body attribute (TextField) are about 6 hand-picked people I know and see in real life on a regular basis who I will personally authorize. I will be the only staff admin and will grant them selective group permissions to post body hypertext with the aid of a WYSIWYG editor. So not only do I “trust” them (not random visitors creating accounts) and can verify their identity in real life, they are additionally non-technical. By “non-technical”, I mean they would be incapable of performing an SQL injection or exploiting any similar attack vector by inserting malicious code.
So as far as I am concerned (and I could be wrong - - I would be happy to have someone correct me) with the specs outlined above, the so-called aircraft carrier threat isn’t an issue.
I can see and understand how and why using Django to write a message board web app (for the sake of comparison) which enables any public web visitor to create an account and begin posting content - - in this context, using the |safe
filter would be extremely foolish because it would enable all kinds of potential drastic malicious activity. That’s a fair assessment, agreed?
But that scenario / configuration isn’t present with my site because my users who have write permission for posting content - - not only do I trust the small number of them - - they also aren’t sophisticated enough to exploit any such security vulnerability.
So far I have addressed the security aspect and I welcome any feedback if someone wants to jump in to correct me.
The other good point Ken made was that mismatched HTML tags could disrupt the intended appearance when Django serves a template in a web browser. I can see that happening. What is the best way to mitigate this issue while still allowing authorized content writers to style their text using a WYSIWYG tool like CKEditor?