Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape HTML in substituted text #233

Closed
snej opened this issue Mar 1, 2022 · 3 comments
Closed

Escape HTML in substituted text #233

snej opened this issue Mar 1, 2022 · 3 comments

Comments

@snej
Copy link

snej commented Mar 1, 2022

Inja doesn't [seem to] have a way to escape HTML entities in a text substitution. So in any situation where you're displaying a user-provided string in a template, like <div>{{commentText}}</div>, you're open to an HTML (and JS...) injection attack unless you've already escaped the string before putting it in the JSON context.

It would be very nice if inja came with an escape(str) function that escaped all HTML meta-characters in str.

Some template engines escape everything by default, and require you to use a special syntax to bypass it for when you truly want to insert HTML. This is much better from a security standpoint, but has obvious backward-compatibility issues :). Maybe it could be enabled with a flag in the environment?

@snej
Copy link
Author

snej commented Mar 23, 2022

Here's how Jinja does HTML escaping

I really like the |pipe syntax for filters; that would be a great feature to add.

@berthubert
Copy link
Contributor

I really want to use Inja since it looks so nice and minimal, but without any support for escaping it is very hard to use. I have large JSON objects that I would somehow have to escape manually beforehand which seems very weird. Even a simple autoescape would be useful!

@pantor
Copy link
Owner

pantor commented Oct 5, 2024

Resolved by #292.

@pantor pantor closed this as completed Oct 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants