GHSA-h9g5-28mm-hx3g: XSS

Published Oct 28, 2026
·
Updated

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)

go 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.com Server 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.

Affected Software

2 affected componentsFixes available
go/github.com/labstack/echo/v4<4.16.0
4.16.0
go/github.com/labstack/echo/v5<5.4.0
5.4.0

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade go/github.com/labstack/echo/v4 to a version that resolves this vulnerability.

    Fixed in 4.16.0
  2. Upgrade

    Upgrade go/github.com/labstack/echo/v5 to a version that resolves this vulnerability.

    Fixed in 5.4.0
  3. Upgrade

    Upgrade github.com/labstack/echo/v5 to a version that resolves this vulnerability.

    Fixed in v5.4.0
  4. Upgrade

    Upgrade github.com/labstack/echo/v4 to a version that resolves this vulnerability.

    Fixed in v4.16.0
  5. Configuration

    Validate the callback in the handler before calling Context.JSONP or Context.JSONPBlob, and set X-Content-Type-Options: nosniff.

    Echo JSONP handlers callback validation and X-Content-Type-Options = Validate against ^[A-Za-z_$][A-Za-z0-9_$]*(\.[A-Za-z_$][A-Za-z0-9_$]*)*$; nosniff
  6. Configuration

    Migrate away from JSONP entirely by using CORS with application/json; do not serve data requiring authentication through JSONP.

    Echo JSONP JSONP usage = disabled

Event History

Oct 28, 2026
Advisory Published
via GitHub·07:54 PM
Data Sourced
via GitHub·07:54 PM
DescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

Which applications are exposed?

Applications using go/github.com/labstack/echo/v4 or go/github.com/labstack/echo/v5 are exposed when a route passes attacker-controlled input into Context.JSONP, Context.JSONPBlob, or the internal jsonPBlob helper as the callback value. The affected input can originate from a query string, form, header, or path parameter.

2

What does an attacker need to exploit this?

An attacker needs network access and a way to cause a user to interact with a crafted request or response. No privileges are required, but the application must use an attacker-controlled callback value in one of the affected JSONP functions.

3

How can we identify affected code paths?

Review routes and handlers for calls to Context.JSONP or Context.JSONPBlob, and trace the callback argument back to request-controlled sources. Any callback value that is not validated, escaped, or restricted by an allow-list can be inserted directly into the JavaScript response.

4

Are the currently identified releases affected?

The issue is stated to be present in current master and v5.1.0, the latest release at the time of publication. No unaffected version is provided in the available data.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203