Skip to content

{{ xx | safe }} filter is always being "applied" #1236

@ang-zeyu

Description

@ang-zeyu

Tell us about your environment

  • MarkBind Version: 2.14.1

What did you do? Please include the actual source code causing the issue.

// Suppose you have
<variable name="xx">
<span>... any more html ...</span>
... html
</variable>

{{ xx }}

What did you expect to happen?

Should output the escaped version of the html &lt; ... &gt; .....

What actually happened? Please include the actual, raw output.

However the unescaped version is outputted. (<span>...</span>)


This occurs because during the resolveBaseUrl stage, decodeEntities is turned on, which turns previously escaped characters back to the unescaped versions. (noticed this in an upcoming pr that inadvertedly fixes this).

Is this intended? (note that this goes against standard nunjucks behaviour)

Our docs have also been relying on this behaviour a lot, as does the 2103 site.
While it is convenient from a user standpoint, once we start adding features that pipe in data/variables from potentially unsafe sources, it poses a security problem.

On the other hand, containing html-in-variables is really quite convenient.
If we do decide to preserve the current behaviour formally (turning off autoEscape in nunjucks variable rendering), we should provide an unsafe filter of sorts

Metadata

Metadata

Assignees

No one assigned

    Labels

    c.Bug 🐛s.UnderDiscussionThe team will evaluate this issue to decide whether it is worth adding

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions