REDHAT-BUG-2521802: Medium severity Hugo Hugo vulnerability
Hugo's default fenced-code-block renderer writes attribute values taken from the code-fence info string into the rendered HTML without escaping them. New in markup/internal/attributes/attributes.go converts every attribute value from a byte slice to a string as it is stored, deliberately dropping the escaping that used to happen there, and RenderAttributes in the same file escapes only values that are still byte slices, so its escaping branch is never reached and every value is written verbatim. The function's documentation states that it performs HTML escaping of string attributes, which it does not. A quote inside an attribute value in the info string therefore terminates the attribute and allows a further attribute, including an event handler, to be placed on the wrapper element, and the script runs for every visitor who loads the page. This path is reached under the default configuration, with code fences enabled and without goldmark's unsafe setting or any custom render hook. Attribute names beginning with on are filtered when the attributes are parsed, so injection is achieved through the value rather than the name.
Affected Software
Event History
Frequently Asked Questions
Is a non-default configuration required for exploitation?
No. The vulnerable path is reached with the default configuration when code fences are enabled; it does not require goldmark's unsafe setting or a custom render hook.
What attacker-controlled input is needed to trigger the issue?
An attacker needs control over a fenced code block's info string and must place a quote in an attribute value. The quote can terminate the intended attribute and inject another attribute, such as an event handler, onto the wrapper element.
Who is exposed if malicious content is rendered?
Every visitor who loads the generated page containing the malicious fenced code block can execute the injected script in their browser.
Does filtering attribute names beginning with "on" prevent exploitation?
No. Names beginning with "on" are filtered during parsing, but exploitation occurs by injecting an attribute through an unescaped attribute value rather than by supplying an event-handler attribute name directly.