2013/10/22 Nick Santos <
nicholas...@gmail.com>:
> I noticed that if I have a template like this:
>
> {namespace x autoescape="contextual"}
>
> /**
> * An anchor.
> * @param href
> */
> {template .anchor}
> <a href="{$href}">text</a>
> {/template}
>
> Then, by default, closure-templates will apply the
> "filterNormalizedUri" to $href. This has a number of bizarre
> behaviors:
>
> 1) If I pass in href="
ftp://somelink", and goog.DEBUG=true, then the
> template engine will throw an error
> 2) If I pass in href="
ftp://somelink", and goog.DEBUG=false, then the
> template engine will return "#zSoyz"
> One one hand, it's not totally clear to me why ftp urls are invalid.
We chose a small white-list. "http", "https", and "mailto" are
allowed protocols. Protocol relative and path relative URIs are also
allowed.
"ftp" and "tel" did not make the cut.
> On the other hand, throwing an error seems like it defeats the whole
> point of using a template engine to sanitize user inputs. On the third
The idea was to fail hard during testing where a developer is most
likely to see the problem, and fail gracefully when it's an end-user
staring at the browser. I can see your point though.
> hand, shouldn't the default 'error link' be configurable, rather than
> hard-coding '#zSoyz'?
The idea was to pick a unique phrase that when put into your favorite
search engine would point you to the link above, and the workaround
for content that is known to be safe but which does not pass the
filter:
https://developers.google.com/closure/templates/docs/security#sanitizedcontent
> Can somebody elaborate on the reasoning behind this, and if the
> maintainers would be willing to change it?
This behavior is described at
https://developers.google.com/closure/templates/docs/security#in_urls
> When {$x} appeared inside a URL or as a CSS quantity, we rejected it because it had a protocol javascript: that was not http or https, and instead output a safe value #zSoyz. Had {$x} appeared in the query portion of a URL, we would have percent-encoded it instead of rejecting it outright (< → %3C).