Re: [go-nuts] Are golang templates safe for end-user editing ?

1,003 views
Skip to first unread message

Kyle Lemons

unread,
Sep 14, 2012, 2:50:17 PM9/14/12
to sahme...@gmail.com, golan...@googlegroups.com
It depends what you mean by "from a security perspective."  No, parsing a template should not open you up to arbitrary code execution or anything, but it requires careful thought about how the templates are executed and presented to users.  If they're all being served from the same domain, you could get into trouble if a malicious admin crafts his page correctly.

Also, use html/template. 

On Fri, Sep 14, 2012 at 6:47 AM, <sahme...@gmail.com> wrote:
If I had a web interface where I let end-users edit templates, is this safe from a security perspective?

I will obviously make sure I provide a data structure to my template that will not expose any data that poses a security risk.

I'm curious if it provides the same level of security like: http://liquidmarkup.org/

--
 
 

Patrick Mylund Nielsen

unread,
Sep 14, 2012, 2:55:16 PM9/14/12
to sahme...@gmail.com, golan...@googlegroups.com
No, it is not safe. For anything HTML-related you should use html/template, which is a wrapper around text/template that escapes stuff that might lead to XSS attacks.

If what you mean by letting users edit templates is that you let them control the information passed to Execute for that template, then yes, it's safe with html/template. If you let them edit the template files themselves, it is not.

Patrick Mylund Nielsen

unread,
Sep 14, 2012, 2:56:40 PM9/14/12
to sahme...@gmail.com, golan...@googlegroups.com
To clarify, by controlling stuff I mean supplying e.g. strings, numbers or form maps from requests to your template. If you let them pass html/template.HTML to your template, programmatically, then that too is unsafe.

Alex Zorin

unread,
Mar 20, 2014, 7:08:05 PM3/20/14
to golan...@googlegroups.com, sahme...@gmail.com
> then that too is unsafe

Is this statement borne only out of concern for XSS/browser attacks, or are there additional security implications? What about html/template templates for email messages, or proprietary messaging protocol that supports HTML rendering? 

Mainly, I am concerned about remote code execution and or resource exhaustion attacks (such as the possibility of a very large or infinite loop in template execution). 

Thank you and apologies for the necro,
Alex

Kyle Lemons

unread,
Mar 21, 2014, 8:52:30 PM3/21/14
to Alex Zorin, golang-nuts, sahme...@gmail.com
Allowing arbitrary editing to anything that is not autoescaped before being sent to the browser, including the template itself, is a recipe for disaster.  As an innocuous example, imagine adding <script>alert("pwned!")</script> to the template.  It assumes that's what you want, even though that would've been escaped to be safe if it were injected via html/template.


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages