Re-do markdown handling for better user experience and security
authorMagnus Hagander <magnus@hagander.net>
Sun, 8 Nov 2020 16:03:04 +0000 (17:03 +0100)
committerMagnus Hagander <magnus@hagander.net>
Thu, 12 Nov 2020 17:52:04 +0000 (18:52 +0100)
commitea9becd74604f30064784185ff54f0d8eafb8467
tree4084dfddc595745856fde15b8b4863a45bfb8046
parent1d43adaf2a7206a131ab5026587f06593455bf50
Re-do markdown handling for better user experience and security

* Get rid of the django_markwhat dependency, and implement our own
  classes to get more control. In passing also remove django-markdown,
  because we never used that.
* Instead of trying to clean markdown with regexps, use the bleach
  library (NEW DEPENDENCY) with special whitelisting of allowed tags
  based off standard markdown. This means that one can input links or
  formatting in HTML if one prefers, as long as it renders to the same
  subset of tags that markdown allows.
* Replace javascript based client side preview with an actual call to a
  preview URL that renders the exact result using the same function,
  since the use of showdown on the client was increasingly starting to
  differ from the server, and since that cannot be kept secure the same
  way. Rewrite the client side javascript to work better with the now
  longer interval between updates of the preview.

Long in planning, but never got around to it.

Suggestion to use bleach for escaping from David Fetter.
25 files changed:
media/css/markdown_preview.css [moved from media/css/showdown_preview.css with 100% similarity]
media/js/admin_pgweb.js
media/js/forms.js
media/js/markdown_preview.js [new file with mode: 0644]
media/js/showdown_preview.js [deleted file]
pgweb/account/urls.py
pgweb/account/views.py
pgweb/core/templatetags/pgmarkdown.py [new file with mode: 0644]
pgweb/settings.py
pgweb/util/helpers.py
pgweb/util/markup.py [new file with mode: 0644]
pgweb/util/moderation.py
requirements.txt
templates/admin/change_form_pgweb.html
templates/base/form.html
templates/downloads/productlist.html
templates/events/archive.html
templates/events/item.html
templates/events/rss_description.html
templates/featurematrix/featuredetail.html
templates/news/item.html
templates/news/mail/default.html
templates/news/mail/pgproject.html
templates/news/newsarchive.html
templates/news/rss_description.html