-
Notifications
You must be signed in to change notification settings - Fork 17.7k
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
html/template: clarify, perhaps expand allowed URLs in urlFilter #20586
Comments
For reference: https://tools.ietf.org/html/rfc3966. |
CC @stjj89 |
CC @mikesamuel |
Unless @stjj89 or @mikesamuel object, it seems fine to treat tel: like mailto:. |
Would wrapping the tel URL in template.URL be sufficient? i.e. https://play.golang.org/p/fVJv1ORih2 I would prefer not to whitelist tel, just because those URLs can trigger unexpected actions on behalf of the user of the generated HTML (e.g. initiate a paid phone call). Requiring the developer to explicitly cast such URLs as template.URL gives us a soft guarantee that the developer has considered the implications of allowing this scheme. |
I completely understand the escaping in
to make that safe regardless of how {{.}} is filled in. In this example, html/template is working with the user to help ensure that the results match what the user intends, namely setting the q parameter. In contrast I do not understand the sanitizing in
Why does "https://evil.site/attack.html" pass through unmodified while "ftp://ftp5.freebsd.org/" and "tel:555-1212" do not? Here it seems like html/template moves from working with the user to second-guessing, passing judgement, or even babysitting. |
the same problem
|
The relevant code is https://golang.org/src/html/template/url.go#L22 https://golang.org/pkg/html/template/#hdr-Security_Model explains the reasoning obliquely
So we reject Since writing that, we on the security engineering team have come to the opinion that These exploits are widely understood by security researchers, but not by HTML developers, so qualify as an Unexpected Side Effect. |
In similar internal URL filters, we adopt a more permissive policy that allows |
In general, there's a long history of (often fairly obscure) security-relevant inconsistencies and bugs in specs and implementations of the Web Platform [Zalewski, 2012]. Based on this, we should be inclined to be fairly conservative in the design of frameworks and libraries that interact with the Web Platform. This is for instance the reason why data: URLs have traditionally not been allowed by URL sanitizers: We know that some data: URLs can result in same-origin script exeuction and hence XSS ( As for Specific concerns around tel: URLs are (as far as I recall) to a large extent due their handling in iOS Safari:
[Zalewski, 2012] Zalewski, Michal. The tangled Web: A guide to securing modern web applications. No Starch Press, 2012. |
@xtofian add something like .DisableSecurityCheck(true) ? |
@rchunping - the canonical way to suppress the default sanitization/validation for a particular value is to wrap it in an appropriate type that indicates to html/template that the value should be considered safe for a given context; in this case, template.URL. See the example that @stjj89 gave above, https://play.golang.org/p/fVJv1ORih2 |
@xtofian thanks ,but the link was broken.
|
Thanks @mikesamuel, this is a good explanation. @stjj89, can you send a CL expanding the internal comment on func urlFilter to explain a bit more about this, and maybe also think about whether the set there needs to be expanded? We don't have to do that until next cycle, but if you want to send the CL now to get it off your plate, that's fine. Thanks. |
Change https://golang.org/cl/52853 mentions this issue: |
What version of Go are you using (
go version
)?1.8
What operating system and processor architecture are you using (
go env
)?darwin
amd64
What did you do?
https://play.golang.org/p/RL6eqxvEfg
What did you expect to see?
What did you see instead?
The source here only whitelists http, https, and mailto: https://github.com/golang/go/blob/master/src/html/template/url.go#L22
I also found this thread talking about it and asked if I should work on a fix. No response yet.
The text was updated successfully, but these errors were encountered: