CVE-2026-118652: Echo vulnerable to Reflected Cross-Site Scripting (XSS) via unsanitized JSONP callback in Context.JSONP / Context.JSONPBlob
Echo's Context.JSONP and Context.JSONPBlob write the caller-supplied callback name straight into a JavaScript response with no validation, giving reflected XSS on any route that passes a query parameter in as the callback. Fixed in github.com/labstack/echo/v4 4.16.0 and github.com/labstack/echo/v5 5.4.0.
Published Oct 28, 2026 · Analysis Nov 1, 2026
What an attacker can do
jsonPBlob and JSONPBlob in context.go build the body as callback + "(" + data + ");" and serve it as application/javascript. If a handler passes c.QueryParam("callback") as the callback, a request such as /api?callback=alert(document.domain)// returns alert(document.domain)//({"status":"ok"});. That is attacker-controlled script.
The attacker needs a victim to load a crafted link or a page that includes the URL as a script. The script runs in the origin of the vulnerable site, so it can read cookies not marked HttpOnly, call authenticated APIs as the user, log keystrokes or rewrite the page. The advisory says a strict CSP does not help, because the response is a script file. The CVSS scope-changed vector (UI required) reflects this.
Only applications that call JSONP or JSONPBlob with request-derived input are exposed. The Echo JSONP cookbook example uses exactly this pattern.
Who is affected
github.com/labstack/echo/v4 before 4.16.0 and github.com/labstack/echo/v5 before 5.4.0 (the advisory text notes the issue exists up to v5.1.0 and master at the time). You are exposed only if your code calls c.JSONP(...) or c.JSONPBlob(...).
go list -m github.com/labstack/echo/v4 github.com/labstack/echo/v5
grep -rnE 'JSONP(Blob)?\(' --include=*.go .github.com/labstack/echo/v5
- Ecosystem
- Go
- Affected
- < 5.4.0
- Fixed in
- 5.4.0
- Check
go list -m github.com/labstack/echo/v5
github.com/labstack/echo/v4
- Ecosystem
- Go
- Affected
- < 4.16.0
- Fixed in
- 4.16.0
- Check
go list -m github.com/labstack/echo/v4
How to fix it
Upgrade to echo/v4 4.16.0 or echo/v5 5.4.0:
go get github.com/labstack/echo/[email protected]After the fix, the callback must be empty, a JavaScript identifier, or a dot-separated path of identifiers (ASCII letters, digits, _, $). Anything else returns a 400 Bad Request wrapping ErrInvalidJSONPCallback and writes nothing. JSONP responses also carry X-Content-Type-Options: nosniff.
Workaround if you cannot upgrade: validate the callback in your handler against ^[A-Za-z_$][A-Za-z0-9_$]*(\.[A-Za-z_$][A-Za-z0-9_$]*)*$ and set X-Content-Type-Options: nosniff. Better, drop JSONP and use CORS with application/json. Do not serve authenticated data over JSONP, since any website can read it with the user's cookies.
How to tell if you were hit
Search web server and proxy logs for requests to JSONP routes where the callback parameter contains characters other than letters, digits, _, $ and ., for example (, ), <, ;, // or %28. Review your code for handlers that pass query, form or header values to JSONP. After upgrading, rejected callbacks show up as 400 responses wrapping ErrInvalidJSONPCallback, which is a useful signal of probing.
Original advisory
From the GitHub Advisory Database (CC BY 4.0).
Summary
The Context.JSONP, Context.JSONPBlob, and internal jsonPBlob helper in context.go directly concatenate the caller-supplied callback parameter into a JavaScript response without any validation, escaping, or allow-listing.
This creates a high-impact reflected XSS that can be triggered by any route passing attacker-controlled data (query string, form, header, path param, etc.) into the callback.
Present in current master and v5.1.0 (latest release).
Vulnerable Code (verbatim)
func (c *Context) jsonPBlob(code int, callback string, i any) (err error) {
c.writeContentType(MIMEApplicationJavaScriptCharsetUTF8)
c.response.WriteHeader(code)
if _, err = c.response.Write([]byte(callback + "(")); err != nil {
return
}
if err = c.echo.JSONSerializer.Serialize(c, i, ""); err != nil {
return
}
if _, err = c.response.Write([]byte(");")); err != nil {
return
}
return
}
func (c *Context) JSONP(code int, callback string, i any) (err error) {
return c.jsonPBlob(code, callback, i)
}
func (c *Context) JSONPBlob(code int, callback string, b []byte) (err error) {
c.writeContentType(MIMEApplicationJavaScriptCharsetUTF8)
c.response.WriteHeader(code)
if _, err = c.response.Write([]byte(callback + "(")); err != nil {
return
}
if _, err = c.response.Write(b); err != nil {
return
}
_, err = c.response.Write([]byte(");"))
return
}No sanitization is performed on the callback string.
Exploit (one-request repro)
Any route using the official pattern is vulnerable:
Goe.GET("/api", func(c echo.Context) error {
return c.JSONP(200, c.QueryParam("callback"), map[string]string{"status": "ok"})
})Attacker request:
GET /api?callback=alert(document.domain)%2f%2f HTTP/1.1
Host: target.comServer response:
Content-Type: application/javascript; charset=utf-8
alert(document.domain)//({"status":"ok"});→ Immediate arbitrary JavaScript execution (full reflected XSS).
Impact
- Session hijacking, cookie theft, account takeover, keylogging, defacement.
- Works even with strict CSP (response is served as application/javascript).
Affected Versions
- All versions ≤ v5.1.0 (including current master)
Workarounds
Manually sanitize the callback before calling JSONP/JSONPBlob:
Gofunc safeCallback(cb string) string {
if matched, _ := regexp.MatchString(`^[a-zA-Z0-9_.\[\]]+$`, cb); !matched {
return "callback"
}
return cb
}Or migrate away from JSONP entirely (use CORS + application/json).
References
- https://github.com/labstack/echo/blob/master/context.go
- https://echo.labstack.com/docs/cookbook/jsonp
Patches
Fixed in github.com/labstack/echo/v5 v5.4.0 and github.com/labstack/echo/v4 v4.16.0. Context.JSONP and Context.JSONPBlob accept only a callback that is empty, a JavaScript identifier or a dot-separated path of identifiers (ASCII letters, digits, _ and $); any other callback returns a 400 Bad Request error wrapping ErrInvalidJSONPCallback and nothing is written. JSONP responses also carry X-Content-Type-Options: nosniff.
Workarounds
Validate the callback in your handler before calling Context.JSONP, for example against ^[A-Za-z_$][A-Za-z0-9_$]*(\.[A-Za-z_$][A-Za-z0-9_$]*)*$, and set X-Content-Type-Options: nosniff. JSONP responses can be read by any website with the user's cookies, so do not serve data that requires authentication through JSONP.
Credited to blitzkrieg-patch, Sengtocxoen.
Questions
- Does a Content-Security-Policy stop this XSS?
The advisory says it works even under a strict CSP because the response is served as application/javascript and loaded as a script. Fix the callback validation rather than relying on CSP.
- Am I affected if I never call Context.JSONP?
No. The flaw is only in Context.JSONP and Context.JSONPBlob. Handlers that use c.JSON or other response helpers are not part of this issue.
- Which Echo versions fix CVE-2026-118652?
Echo v4 4.16.0 and Echo v5 5.4.0. Both reject callbacks that are not plain identifiers or dotted identifier paths.
References
How this page is made: the data panel comes from the GitHub Advisory Database, CISA’s KEV catalog, the NVD and FIRST EPSS, and updates twice a day. The analysis is written by an AI model from the sources listed above and checked by automated rules before it is published. Check versions against the vendor's advisory before you act. Methodology
More Go vulnerabilities
All Go entriesCVE-2026-118266
Echo has CSRF Protection Bypass via MethodOverride Rewriting POST to Safe Method
medium5.3Oct 28, 2026CVE-2026-118650
Echo's middleware.Static: `%2F`-encoded path bypasses route/group middleware guarding a statically-served path
high7.5Oct 28, 2026CVE-2026-118651
Echo: Reverse Proxy Forwards Attacker-Supplied X-Real-IP to Upstream by Default
medium5.3No fixOct 28, 2026CVE-2026-118653
Echo has Rate Limiter Bypass via Spoofed X-Forwarded-For Header in Default Configuration
medium5.3No fixOct 28, 2026CVE-2026-118654
Echo static file middleware route protection bypass via encoded dot-dot traversal
medium5.9Oct 28, 2026CVE-2026-118655
Echo has a Static Middleware Double-Unescape Path Traversal
medium5.9Oct 28, 2026
