Skip to content

html/template: backticks not treated as string delimiters (CVE-2023-24538) #59234

@rolandshoemaker

Description

@rolandshoemaker

Templates did not properly consider backticks (`) as Javascript string delimiters, and as such did
not escape them as expected. Backticks are used, since ES6, for JS template literals. If a template
contained a Go template action within a Javascript template literal, the contents of the action could
be used to terminate the literal, injecting arbitrary Javascript code into the Go template.

As ES6 template literals are rather complex, and themselves can do string interpolation, we've decided
to simply disallow Go template actions from being used inside of them (e.g. "var a = {{.}}"), since
there is no obviously safe way to allow this behavior. This takes the same approach as github.com/google/safehtml.
Template.Parse will now return an Error when it encounters templates like this, with a currently unexported
ErrorCode with a value of 12. This ErrorCode will be exported in the next major release.

Users who rely on this behavior can re-enable it using the GODEBUG flag jstmpllitinterp=1, with the
caveat that backticks will now be escaped. This should be used with caution.

Thanks to Sohom Datta, Manipal Institute of Technology, for reporting this issue.

This is CVE-2023-24538 and Go issue https://go.dev/issue/59234.

/cc @golang/security and @golang/release

Metadata

Metadata

Labels

FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.Security

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions