High severityNVD Advisory· Published Mar 5, 2026· Updated Mar 10, 2026
Gogs: Stored XSS via data URI in issue comments
CVE-2026-26022
Description
Gogs is an open source self-hosted Git service. Prior to version 0.14.2, a stored cross-site scripting (XSS) vulnerability exists in the comment and issue description functionality. The application's HTML sanitizer explicitly allows data: URI schemes, enabling authenticated users to inject arbitrary JavaScript execution via malicious links. This issue has been patched in version 0.14.2.
Affected packages
Versions sourced from the GitHub Security Advisory.
| Package | Affected versions | Patched versions |
|---|---|---|
gogs.io/gogsGo | < 0.14.2 | 0.14.2 |
Affected products
1Patches
1441c64d7bd88markup: restrict data URI scheme to safe image MIME types (#8174)
2 files changed · +32 −2
internal/markup/sanitizer.go+18 −2 modified@@ -1,6 +1,8 @@ package markup import ( + "net/url" + "strings" "sync" "github.com/microcosm-cc/bluemonday" @@ -32,14 +34,28 @@ func NewSanitizer() { sanitizer.policy.AllowAttrs("type").Matching(lazyregexp.New(`^checkbox$`).Regexp()).OnElements("input") sanitizer.policy.AllowAttrs("checked", "disabled").OnElements("input") - // Data URLs - sanitizer.policy.AllowURLSchemes("data") + // Only allow data URIs with safe image MIME types to prevent XSS via + // "data:text/html" payloads. + sanitizer.policy.AllowURLSchemeWithCustomPolicy("data", isSafeDataURI) // Custom URL-Schemes sanitizer.policy.AllowURLSchemes(conf.Markdown.CustomURLSchemes...) }) } +// isSafeDataURI returns whether the given data URI uses a safe image MIME type. +func isSafeDataURI(u *url.URL) bool { + // The opaque data of a data URI has the form "mediatype;base64,data" or + // "mediatype,data". We only allow common image MIME types. + mediatype, _, _ := strings.Cut(u.Opaque, ";") + mediatype, _, _ = strings.Cut(mediatype, ",") + switch strings.TrimSpace(strings.ToLower(mediatype)) { + case "image/png", "image/jpeg", "image/gif", "image/webp", "image/x-icon": + return true + } + return false +} + // Sanitize takes a string that contains a HTML fragment or document and applies policy whitelist. func Sanitize(s string) string { return sanitizer.policy.Sanitize(s)
internal/markup/sanitizer_test.go+14 −0 modified@@ -26,6 +26,20 @@ func Test_Sanitizer(t *testing.T) { {input: `<input type="hidden">`, expVal: ``}, {input: `<input type="checkbox">`, expVal: `<input type="checkbox">`}, {input: `<input checked disabled autofocus>`, expVal: `<input checked="" disabled="">`}, + + // Data URIs: safe image types should be allowed + {input: `<img src="data:image/png;base64,abc">`, expVal: `<img src="data:image/png;base64,abc">`}, + {input: `<img src="data:image/jpeg;base64,abc">`, expVal: `<img src="data:image/jpeg;base64,abc">`}, + {input: `<img src="data:image/gif;base64,abc">`, expVal: `<img src="data:image/gif;base64,abc">`}, + {input: `<img src="data:image/webp;base64,abc">`, expVal: `<img src="data:image/webp;base64,abc">`}, + + // Data URIs: text/html must be stripped to prevent XSS (GHSA-xrcr-gmf5-2r8j) + {input: `<a href="data:text/html;base64,PHNjcmlwdD5hbGVydCgnWFNTJyk8L3NjcmlwdD4=">Click</a>`, expVal: `Click`}, + {input: `<a href="data:text/html,<script>alert(1)</script>">XSS</a>`, expVal: `XSS`}, + {input: `<img src="data:text/html;base64,abc">`, expVal: ``}, + + // Data URIs: SVG must be stripped (can contain embedded JavaScript) + {input: `<img src="data:image/svg+xml;base64,abc">`, expVal: ``}, } for _, test := range tests { t.Run(test.input, func(t *testing.T) {
Vulnerability mechanics
Generated by null/stub on May 9, 2026. Inputs: CWE entries + fix-commit diffs from this CVE's patches. Citations validated against bundle.
References
6- github.com/advisories/GHSA-xrcr-gmf5-2r8jghsaADVISORY
- nvd.nist.gov/vuln/detail/CVE-2026-26022ghsaADVISORY
- github.com/gogs/gogs/commit/441c64d7bd8893b2f4e48660a8be3a7472e14291ghsax_refsource_MISCWEB
- github.com/gogs/gogs/pull/8174ghsax_refsource_MISCWEB
- github.com/gogs/gogs/releases/tag/v0.14.2ghsax_refsource_MISCWEB
- github.com/gogs/gogs/security/advisories/GHSA-xrcr-gmf5-2r8jghsax_refsource_CONFIRMWEB
News mentions
0No linked articles in our index yet.