From: Bjørn Erik Pedersen Date: Wed, 1 Apr 2026 11:54:10 +0000 (+0200) Subject: Fix potential content XSS by escaping dangerous URLs in links and images X-Git-Url: http://git.maquefel.me/?a=commitdiff_plain;h=479fe6c654937a850b65e74551dc4e857d52898f;p=brevno-suite%2Fhugo Fix potential content XSS by escaping dangerous URLs in links and images * This issue in question was fixed upstream in https://github.com/yuin/goldmark/releases/tag/v1.8.2 * We do, however, have a copy of the affected functions, used as fallbacks when no render hook are defined for e.g. links and images, so we need to port these fixes to our copy of the affected functions. --- diff --git a/markup/goldmark/goldmark_integration_test.go b/markup/goldmark/goldmark_integration_test.go index b1c182034..c088201b3 100644 --- a/markup/goldmark/goldmark_integration_test.go +++ b/markup/goldmark/goldmark_integration_test.go @@ -1035,3 +1035,33 @@ foo[^1] and bar[^2] "

foo1 and bar2

\n
\n
\n
    \n
  1. \n

    footnote one back

    \n
  2. \n
  3. \n

    footnote two back

    \n
  4. \n
\n
", ) } + +func TestRenderLinkDefaultDangerous(t *testing.T) { + t.Parallel() + + /* + Content:

Link: Click me + AutoLink: javascript:alert(1) + Image: alt

+ */ + + files := ` +-- content/p1.md -- +--- +title: "p1" +--- +Link: [Click me](javascript:alert(1)) +AutoLink: +Image: ![alt](javascript:alert(3)) +-- layouts/all.html -- +Content: {{ .Content }} +` + + b := hugolib.Test(t, files) + + b.AssertFileContent("public/p1/index.html", + `! alert(1)"`, + `! href="javascript:alert(2)"`, + `! alert(3)"`, + ) +} diff --git a/markup/goldmark/render_hooks.go b/markup/goldmark/render_hooks.go index 1e91f7ab1..418358054 100644 --- a/markup/goldmark/render_hooks.go +++ b/markup/goldmark/render_hooks.go @@ -230,8 +230,9 @@ func (r *hookedRenderer) renderImageDefault(w util.BufWriter, source []byte, nod } n := node.(*ast.Image) _, _ = w.WriteString("