-
Notifications
You must be signed in to change notification settings - Fork 10
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
Kitura-TemplateEngine should escape XML entities by default #18
Comments
Just to let you know we are aware of this issue and are currently looking into solutions. We will continue looking into this and get back to you when we have decided on the best approach since you are right that customers shouldn't need to implement their own escaping. |
I proposed something to avoid double-escaping in my OP, but I breezed over it, so let me go into more detail. We can add a new parameter to the This would be a backwards compatibility break, but a fairly easy one to rectify. And maybe there's a better way, but that's what I had in mind, at least. |
@NocturnalSolutions I realise it's been a while since a comment was made here but I'm going to look into resolving this issue. Once I have something working I'll drop a link in here for you to take a look at. |
So I've spent some time exploring a possible avenue for implementing this into Kitura-TemplateEngine. It's possible but not 'clean' and it's difficult to add a case for a user not wanting to escape certain elements in their html but escape everything else. It'd be an escape all or nothing approach. However this is a valid issue, so what we've decided to do is to reach out to Kyle and offered to work with him to bring this functionality into Stencil. This should at least bring the template engines we support more in line. |
Should things be escaped at the Kitura-TemplateEngine level, we could create a simple new struct with a single string property called something like I still think it's a good idea to do this at the Kitura-TemplateEngine level for consistency's sake, since now we have a case where Mustache may escape some things that Stencil does not and vice versa, and who knows what new template engines that might come along in the future will do. That being said, Stencil seems to be the most commonly-used engine at present, so having that one be more secure by default would still be a big win. |
…unless the template engine implementation will do it, as defined by a parameter on the
TemplateEngine
class implementation. (IIRC, Mustache does it by default, but Stencil does not.)That is,
"
,'
,<
,&
, and>
. Perhaps the other HTML entities, too, but at least those ones.Why?
This could be implemented by simply mapping through
context
and performing escaping on anything in there we find that looks like aString
.We can implement a new
InsecureUnescapedString
struct which users can use when they do not want a particular string in theircontext
dictionary to be escaped; also, an option inRenderingOptions
could be set if the user wants to override the default behavior for the whole dictionary (that is, they could force escaping to happen even if the template engine says it shouldn't, or vice versa).I'm willing to put in the work to implement this and submit a PR, but I figured I'd float the idea out there first.
The text was updated successfully, but these errors were encountered: