-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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: {{value | .Method}} panics and prevents escaping #7379
Labels
Milestone
Comments
Labels changed: added release-go1.3, repo-main, size-s. Owner changed to @robpike. Status changed to Accepted. |
Comment 2 by rpolzer@google.com: I should add that problem 2 seems a lot more disturbing, as that may be usable for XSS. This seems to stem from this function: func escapeTemplates(tmpl *Template, names ...string) error { e := newEscaper(tmpl) for _, name := range names { c, _ := e.escapeTree(context{}, name, 0) var err error // ... tmpl.escaped = true } e.commit() return nil } This writes to tmpl.escaped once ANY of the templates is escaped, even if a later one fails escaping! This assignment should simply not exist, as tmpl.escaped is already set in Template.Execute when this function returns. The panic BTW happens in commit(), when escaped is already set. Even worse, in lookupAndEscapeTemplate, tmpl.escaped is checked for whether to escape another than the root template. This looks dangerous. Probably this escaped field should rather exist once per template... otherwise mixing calls of .Execute() and .ExecuteTemplate() can cause non-escaped data too. |
Comment 3 by rpolzer@google.com: (Deleted and edited my comment, as it was quite wrong... sorry) I should add that problem 2 seems a lot more disturbing, as that may be usable for XSS. This seems to stem from this function: func escapeTemplates(tmpl *Template, names ...string) error { e := newEscaper(tmpl) for _, name := range names { c, _ := e.escapeTree(context{}, name, 0) var err error // ... tmpl.escaped = true } e.commit() return nil } This writes to tmpl.escaped before the commit() call, which panics in my case. The result is that commit() never takes place. Fix suggestion: moving the tmpl.escaped = true either to both callers (currently only one caller does it), or to behind the e.commit(). |
CL https://golang.org/cl/85240043 references this issue. |
This issue was closed by revision 51fba7d. Status changed to Fixed. |
This issue was closed.
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
by rpolzer@google.com:
The text was updated successfully, but these errors were encountered: