Closed waneck closed 11 years ago
True, but we also need an explicit way to remove that filter when required.
On Thu, May 9, 2013 at 10:04 AM, Cauê Waneck notifications@github.comwrote:
It would be great to add a way (maybe even default it) to add a escape function (e.g. htmlEscape) for the variable output, as not adding it opens up some possible security holes.
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15 .
I think that adding a dynamic function called escape to the template class would be a good way to do it.
But that implies having to call that function manually, no?
On Mon, May 13, 2013 at 2:34 PM, Cauê Waneck notifications@github.comwrote:
I think that adding a dynamic function called escape to the template class would be a good way to do it.
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15#issuecomment-17838737 .
we can do it using the hscript interpreter / macro code
What if @(value)/@value always escapes the results, but @.(value)/@.value doesn't? It means introducing a new syntax but seems justified in this case.
On Mon, May 13, 2013 at 4:06 PM, Cauê Waneck notifications@github.comwrote:
we can do it using the hscript interpreter / macro code
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15#issuecomment-17844313 .
I'm fine with it! Do you think we still need to add a "escape" dynamic function this way, or just call htmlEscape directly?
2013/5/13 Franco Ponticelli notifications@github.com
What if @(value)/@value always escapes the results, but @.(value)/@.value doesn't? It means introducing a new syntax but seems justified in this case.
On Mon, May 13, 2013 at 4:06 PM, Cauê Waneck notifications@github.comwrote:
we can do it using the hscript interpreter / macro code
— Reply to this email directly or view it on GitHub< https://github.com/ciscoheat/erazor/issues/15#issuecomment-17844313> .
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15#issuecomment-17844849 .
I don't think we need an explicit escape function. It might be interesting to add an erazor helper library to inject commonly used helpers.
On Mon, May 13, 2013 at 4:19 PM, Cauê Waneck notifications@github.comwrote:
I'm fine with it! Do you think we still need to add a "escape" dynamic function this way, or just call htmlEscape directly?
2013/5/13 Franco Ponticelli notifications@github.com
What if @(value)/@value always escapes the results, but @.(value)/@.value doesn't? It means introducing a new syntax but seems justified in this case.
On Mon, May 13, 2013 at 4:06 PM, Cauê Waneck notifications@github.comwrote:
we can do it using the hscript interpreter / macro code
— Reply to this email directly or view it on GitHub< https://github.com/ciscoheat/erazor/issues/15#issuecomment-17844313> .
— Reply to this email directly or view it on GitHub< https://github.com/ciscoheat/erazor/issues/15#issuecomment-17844849> .
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15#issuecomment-17844968 .
I implemented this new syntax on my fork https://github.com/astro75/erazor Default behavior is escaping only @.value but not @value Escape methods can be replaced easily.
I also found clemos fork that has ability to enable escaping https://github.com/clemos/erazor To disable escaping on specific strings they need to extend TStrig class. eg. new SafeString("")
I think clemos approach is better, because it moves the code for "do not escape this" away from template.
edit: I also made haxe 3 compatible version of clemos approach https://github.com/astro75/erazor/tree/auto_escape
@astro75 , thank you for your implementation. Some thoughts:
Thanks!
Erazor is not only for html. Maybe there could be HtmlTemplate that extends Template and makes escaping the default behavior. I don't like the @.value syntax any more. I think that @Raw(value) or @Html.Raw(value) is better. (identical to original Razor templates). This makes it more obvious than a single dot.
I agree that Erazor is not for Html only and I see many potential advantages in having an HtmlTemplate class with specific behaviors. The first that comes to my mind is being able to stuff like @if(cond)
On Tue, Oct 1, 2013 at 4:46 AM, astro75 notifications@github.com wrote:
Erazor is not only for html. Maybe there could be HtmlTemplate that extends Template and makes escaping the default behavior. I don't like the @.value syntax any more. I think that @Raw(value) or @Html.Raw(value) is better. (identical to original Razor templates). This makes it more obvious than a single dot.
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15#issuecomment-25439840 .
So where do we stand? I'm fine with either @. or @raw(). But I'd like to have an outlook of what it will take to implement this. While I understand that erazor is not only used for HTML templates, I still think that we should make it "secure by default", even if this means a version bump
I don't stand anywhere :) ... I think that if we go the @raw way we need proper injection of helpers first. If we go @. maybe we can define 2 standard functions for escaped/unescaped that return the same raw value in Template but they are overridden in HtmlTemplate.
On Tue, Oct 1, 2013 at 10:04 AM, Cauê Waneck notifications@github.comwrote:
So where do we stand? I'm fine with either @. or @raw(). But I'd like to have an outlook of what it will take to implement this. While I understand that erazor is not only used for HTML templates, I still think that we should make it "secure by default", even if this means a version bump
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15#issuecomment-25463534 .
Sorry if I sounded rude :) As I said, I'm fine with both possiblities. But I don't have enough experience with the original razor templates to think of a good way to deal with helpers - so I'm more inclined to go with the first. About the HtmlTemplate, what do you think if add a constructor argument that will control this? This way we still let the user choose and not generate bugs or security errors
No worries. I have no time right now to look into this more into depth so I would say that the decision should fall on the first that is going to provide a satisfactory solution and implementation.
On Tue, Oct 1, 2013 at 10:37 AM, Cauê Waneck notifications@github.comwrote:
Sorry if I sounded rude :) As I said, I'm fine with both possiblities. But I don't have enough experience with the original razor templates to think of a good way to deal with helpers - so I'm more inclined to go with the first. About the HtmlTemplate, what do you think if add a constructor argument that will control this? This way we still let the user choose and not generate bugs or security errors
— Reply to this email directly or view it on GitHubhttps://github.com/ciscoheat/erazor/issues/15#issuecomment-25466658 .
Agreed!
Just implemented HtmlTemplate and macro.HtmlTemplate using @raw syntax. I also made a simple way for injecting helpers into Template. macro.Template currently allows injection only by extending it.
Like it. can you submit a PR?
PR applied, many thanks.
It would be great to add a way (maybe even default it) to add a escape function (e.g. htmlEscape) for the variable output, as not adding it opens up some possible security holes.