Skip to content

Instantly share code, notes, and snippets.

@VaclavSir
Created December 3, 2016 09:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save VaclavSir/77bdd99f3f55d5f90daf2d4924be80b0 to your computer and use it in GitHub Desktop.
Save VaclavSir/77bdd99f3f55d5f90daf2d4924be80b0 to your computer and use it in GitHub Desktop.
Why Is Context-Aware Escaping a Leaky Abstraction

This is what the documentation says:

All is done automatically, consistently and correctly. You don't have to worry about security holes.

This is simply not true. What if you write this:

<a href="javascript:{$variable}">...</a>

Which way is automatically consistently correct? JS code inside HTML attribute, or JS value inside HTML attribute?

And will it differ from this?:

<a href="javascript:alert({$variable})">...</a>

The coder still has to know, how the value should be dealt with and in Latte, he or she also has to know the default behavior of the engine.

If the engine treats everything as an HTML by default, the code is more explicit and less magic:

<a href="javascript:{{ code }}">...</a>
<a href="javascript:alert({{ value | escape('js') }})">...</a>
Engine You have to worry about context You have to worry about engine's behavior in the context
Latte
Twig
Blade
@dg
Copy link

dg commented Dec 4, 2016

„If the engine treats everything as an HTML by default“ what exactly it means? There are a lot of contexts even in HTML.

@VaclavSir
Copy link
Author

htmlspecialchars()

@dg
Copy link

dg commented Dec 5, 2016

It cannot be used in HTML comments and inside SCRIPT and STYLE elements.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment