Уязвимость в обработке шаблонов Go, позволяющая внедрение JavaScript через неэкранированные обратные кавычки
Описание
Шаблоны некорректно обрабатывают обратные кавычки как разделители строк в JavaScript и не экранируют их должным образом. Обратные кавычки используются в ES6 для шаблонных строк в JavaScript. Если шаблон содержит действие Go-шаблона внутри литерала JavaScript, содержимое этого действия может быть использовано для завершения литерала, внедряя произвольный код JavaScript в Go-шаблон. Поскольку шаблонные строки ES6 сами по себе могут проводить интерполяцию строк, было принято решение запретить использование действий Go-шаблонов внутри них (например, "var a = {{.}}"
), так как нет очевидно безопасного способа разрешить такое поведение. Это аналогичный подход, который использует github.com/google/safehtml
. После исправления Template.Parse
возвращает ошибку при обнаружении подобных шаблонов с кодом ошибки 12. Этот код ошибки в настоящий момент не экспортируется, но будет экспортирован в релизе Go 1.21. Пользователи, которые полагаются на предыдущее поведение, могут восстановить его с помощью флага GODEBUG jstmpllitinte
.
Затронутые версии ПО
- Go до релиза 1.21
Тип уязвимости
Выполнение произвольного кода
Ссылки
- Patch
- Issue TrackingPatch
- Mailing List
- Vendor Advisory
- Patch
- Issue TrackingPatch
- Mailing List
- Vendor Advisory
Уязвимые конфигурации
Одно из
EPSS
9.8 Critical
CVSS3
Дефекты
Связанные уязвимости
Templates do not properly consider backticks (`) as Javascript string delimiters, and do not escape them as expected. Backticks are used, since ES6, for JS template literals. If a template contains a Go template action within a Javascript template literal, the contents of the action can 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, the decision was made 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. With fix, Template.Parse returns an Error when it encounters templates like this, with an ErrorCode of value 12. This ErrorCode is currently unexported, but will be exported in the release of Go 1.21. Users who rely on the previous behavior can re-enable it using the GODEBUG flag jstmplliti...
Templates do not properly consider backticks (`) as Javascript string delimiters, and do not escape them as expected. Backticks are used, since ES6, for JS template literals. If a template contains a Go template action within a Javascript template literal, the contents of the action can 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, the decision was made 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. With fix, Template.Parse returns an Error when it encounters templates like this, with an ErrorCode of value 12. This ErrorCode is currently unexported, but will be exported in the release of Go 1.21. Users who rely on the previous behavior can re-enable it using the GODEBUG flag jstmplliti...
Templates do not properly consider backticks (`) as Javascript string ...
Templates do not properly consider backticks (`) as Javascript string delimiters, and do not escape them as expected. Backticks are used, since ES6, for JS template literals. If a template contains a Go template action within a Javascript template literal, the contents of the action can 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, the decision was made 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. With fix, Template.Parse returns an Error when it encounters templates like this, with an ErrorCode of value 12. This ErrorCode is currently unexported, but will be exported in the release of Go 1.21. Users who rely on the previous behavior can re-enable it using the GODEBUG flag jstmplliti...
Уязвимость пакета golang операционной системы Debian GNU/Linux, позволяющая нарушителю выполнить произвольный код
EPSS
9.8 Critical
CVSS3