{"id":"GHSA-vcc4-2c75-vc9v","summary":"Caddy: stripHTML template function bypass","details":"### Summary\nCaddy’s `stripHTML` template function cannot reliably remove all HTML tags from input strings. Certain malformed HTML, such as `\u003c\u003c\u003eimg src=x onerror=alert()\u003e`, can bypass the tag-stripping logic, potentially leaving dangerous content in the output if it is later rendered as HTML. This may allow client-side XSS in cases where untrusted strings are rendered unsafely.\n\n---\n\n### Details\nThe vulnerability originates from `funcStripHTML` in:\n\n[caddy/caddy/caddyhttp/templates/tplcontext.go](https://github.com/caddyserver/caddy/blob/77e9ce7404c4a76853e101a9f5687a929ee56654/modules/caddyhttp/templates/tplcontext.go)\n\n```go\nfunc (TemplateContext) funcStripHTML(s string) string {\n    var buf bytes.Buffer\n    var inTag, inQuotes bool\n    var tagStart int\n    for i, ch := range s {\n        if inTag {\n            if ch == '\u003e' && !inQuotes {\n                inTag = false\n            } else if ch == '\u003c' && !inQuotes {\n                // false start\n                buf.WriteString(s[tagStart:i])\n                tagStart = i\n            } else if ch == '\"' {\n                inQuotes = !inQuotes\n            }\n            continue\n        }\n        if ch == '\u003c' {\n            inTag = true\n            tagStart = i\n            continue\n        }\n        buf.WriteRune(ch)\n    }\n    if inTag {\n        // false start\n        buf.WriteString(s[tagStart:])\n    }\n    return buf.String()\n}\n```\n\n### POC\n\nCaddyfile setup\n\n```\n:8080 {\n    root * ./site\n    file_server\n    templates\n}\n```\n\nTemplate file (index.html)\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml lang=\"en\"\u003e\n\u003chead\u003e\n    \u003cmeta charset=\"UTF-8\"\u003e\n    \u003ctitle\u003eStripHTML Bypass Test\u003c/title\u003e\n\u003c/head\u003e\n\u003cbody\u003e\n    \u003cp\u003e{{ stripHTML \"\u003c\u003c\u003eimg src=x onerror=alert('XSS')\u003e\" }}\u003c/p\u003e\n\u003c/body\u003e\n\u003c/html\u003e\n```\n\nThe payload exploits the false start branch to smuggle a literal \u003c back into the output, then uses the following \u003e to terminate the parser’s tag state, leaving a valid \u003cimg ...\u003e tag behind.\n\nTested in v2.11.3\n\n### Impact\n\nMalformed HTML can bypass stripHTML, potentially allowing arbitrary HTML or JavaScript to be rendered if the output is used unsafely, leading to client-side XSS.\n\n### AI Disclosure\n\nAI assisted in writing the report description; however, the discovery of the issue has been done manually.","aliases":["CVE-2026-52846","GO-2026-5660"],"modified":"2026-07-24T19:26:16.598884790Z","published":"2026-06-16T21:28:55Z","database_specific":{"nvd_published_at":null,"cwe_ids":["CWE-116"],"severity":"MODERATE","github_reviewed":true,"github_reviewed_at":"2026-06-16T21:28:55Z"},"references":[{"type":"WEB","url":"https://github.com/caddyserver/caddy/security/advisories/GHSA-vcc4-2c75-vc9v"},{"type":"PACKAGE","url":"https://github.com/caddyserver/caddy"}],"affected":[{"package":{"name":"github.com/caddyserver/caddy/v2","ecosystem":"Go","purl":"pkg:golang/github.com/caddyserver/caddy/v2"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"fixed":"2.11.4"}]}],"database_specific":{"last_known_affected_version_range":"\u003c= 2.11.3","source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/06/GHSA-vcc4-2c75-vc9v/GHSA-vcc4-2c75-vc9v.json"}},{"package":{"name":"github.com/caddyserver/caddy","ecosystem":"Go","purl":"pkg:golang/github.com/caddyserver/caddy"},"ranges":[{"type":"SEMVER","events":[{"introduced":"0"},{"last_affected":"1.0.5"}]}],"database_specific":{"source":"https://github.com/github/advisory-database/blob/main/advisories/github-reviewed/2026/06/GHSA-vcc4-2c75-vc9v/GHSA-vcc4-2c75-vc9v.json"}}],"schema_version":"1.9.0","severity":[{"type":"CVSS_V3","score":"CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:L/I:L/A:N"}]}