Уязвимость внедрения произвольного JavaScript-кода через некорректную обработку обратных кавычек (`) в шаблонах Go
Описание
Шаблоны не учитывают обратные кавычки (`) как разделители строк JavaScript и не экранируют их должным образом. Обратные кавычки, начиная с ES6, используются для строковых литералов (template literals) в JavaScript. Если шаблон содержит действие Go внутри JavaScript-литерала, содержимое этого действия может быть использовано для завершения литерала и внедрения произвольного JavaScript-кода в шаблон Go.
Из-за сложности ES6-литералов, которые поддерживают интерполяцию строк, было принято решение полностью запретить использование действий Go внутри них (например, var a = {{.}}
), так как безопасного способа разрешить такое поведение нет. Этот подход аналогичен реализации в библиотеке github.com/google/safehtml
.
После исправления метод Template.Parse
возвращает ошибку при обнаружении таких шаблонов с кодом ошибки 12. Этот код ошибки пока не экспортируется, но будет доступен в релизе Go 1.21. Пользователи, полагающиеся на предыдущее поведение, могут восстановить его с помощью флага GODEBUG=jstmpllitint
.
Тип уязвимости
Внедрение JavaScript-кода
Ссылки
- Vendor Advisory
- 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 jstmpllit...
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 jstmpllit...
Уязвимость агента универсальной системы мониторинга Zabbix, позволяющая нарушителю выполнить произвольный код
EPSS
9.8 Critical
CVSS3