0

I have a form with a jwysiwyg editor. Looking at it, it can use basic-formatting html tags using the formatting buttons like SO's. Upon submitting the form, I notice its saved into the database as-is, whereas if I enter stuff like <iframe> ... </iframe> into the editor I notice that it is html-encoded inside the table.

Now, when I need to output whatever the user has submitted, can I safely use {{ output|safe }} to display the formatted text?

Is this reasonably secure enough or how should I rectify?

1 Answer 1

3

Use the safe filter only if you html-escape the data first. Otherwise you should use escape. If you want your users to be able to input data with html tags you could try to sanitize the input to prevent users from using <iframe>, <script>, etc, but allow other tags to be white-listed, and then mark it as safe.

Sign up to request clarification or add additional context in comments.

2 Comments

assuming that my wysiwyg editor on the client side already handles the unsafe tags before sending to the server, can i safely assume using |safe is alright?
If you trust it, then yes. You can also use django.utils.safestring.mark_safe to mark a string as safe.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.