Don't mark striptags output as safe in search results#3048
Open
apoorva-01 wants to merge 1 commit into
Open
Conversation
striptags output isn't HTML-safe, so |safe on it is exactly what Django's docs warn against. Dropping |safe alone would double-escape (strip_tags leaves entities encoded), so unescape the description at index time and let autoescaping do the work.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The search result templates run
result.descriptionthrough|safe, but that'sstriptagsoutput, which the docs say to never mark safe. Went with the fix from the issue:html.unescape(striptags(...))in theprepare_descriptionmethods so the indexed value is real plain text, then dropped|safeand let autoescaping handle it. Renders the same.Old index entries stay entity-encoded until a
rebuild_index, so that'll need a reindex on deploy. Andpages.page.htmldoesn't actually usedescription|safe, so that one's just for consistency.Closes
|safetostriptagsoutput #3046