-
Notifications
You must be signed in to change notification settings - Fork 69
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
Allow the developer to choose the escaping strategy #387
Comments
Interpolation of user data directly into JS expressions is something that easily results in XSS, so we don't really plan to support context dependent escaping for JS. The parse error you get can be avoided by using a JSON serializer. |
But I want it to be escaped? I just want it to be escaped correctly. |
Hm, the whole idea of output escaping in jte is, that the user does not need to do it manually. So adding a new keyword to escape JS really would not fit into very well. The
|
Well but it is certainly not exhaustive. Currently it just leads to incorrect behaviour, and the developer doesn't have the choice. I would see the $js{} as an optional way. Default wouldn't change. Like you can currently do with $unsafe. For reference in Thymeleaf there they have th:inline="script" so that all values get rendered correctly to JS syntax.
As I wrote in the other issue, there is currently no way to plug in to this behaviour right? I know you guys are very into the "safe" template but it's very restricting. |
Similar thing like here: #326 Instead of the user having to configure a custom policy or using unsafe, there could be $attr{} that knows how to properly escape a whole "attribute='value'" combination. I think an extensible system like this could lead to more advanced usages with JTE Default should lead to safe templates but the developers should be able to either extend JTE or choose the correct strategy for the use case. |
Yes, it is very restricting, by design. It should be hard to do the wrong thing and easy to do the right thing.
That opens a whole can of worms. Which attributes are safe? |
Well for example $attr{} would have two parameters.
The attributes which are in the html standard are safe. Currently everything that doesn't start with on* is escaped like a normal attribute. |
No, for example |
But the problem with the solution is not that it is not safe but it is not smart enough to know about other custom elements and thereby doesn't choose the correct escaping technique. In this case it doesn't escape The question is what is the correct way to enable developers to user JTE with custom attributes like this. |
@tschuehly you can do
and pass this template output to |
Currently when outputting values in an attribute JTE only checks if the attribute starts with
on
and then escapes it as javascript attribute:jte/jte-runtime/src/main/java/gg/jte/html/OwaspHtmlTemplateOutput.java
Line 70 in b097448
If I'm using alpine.js x-data or htmx hx-on this doesn't get triggered and it leads to an error as the attribute is rendered as a multiline string:
This JTE template:
renders to this:
leading to an JavaScript exception:
If the correct Escaping strategy is chosen it renders correctly
I think we should introduce an additional syntax similar to
$unsafe{comment.escapedText()}
but instead using$js{comment.escapedText()}
that then either choosesgg.jte.html.escape.Escape#javaScriptBlock
orgg.jte.html.escape.Escape#javaScriptAttribute
to escape the value.The text was updated successfully, but these errors were encountered: