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

Open
snej opened this issue Mar 1, 2022 · 1 comment
Open

Escape HTML in substituted text #233

snej opened this issue Mar 1, 2022 · 1 comment

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.

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

1 participant