Skip to content

Cross-Site Scripting (XSS) on /api/v1/img via content-type spoofing

High
umputun published GHSA-4c8j-mgm4-qqvp May 22, 2026

Package

gomod github.com/umputun/remark42 (Go)

Affected versions

>= v1.6.0, < v1.16.0

Patched versions

v1.16.0

Description

Summary

The remark42 image proxy fetches an arbitrary remote URL and re-serves the
response from remark42's own origin. The download path decides whether the
fetched resource is an image by looking only at the Content-Type header the
remote server claims — it never inspects the actual bytes. The serving path
then derives the response Content-Type by sniffing those bytes with
http.DetectContentType.

An attacker hosts a URL that sets Content-Type to image/png but returns an
HTML/JavaScript body:

  • the download check sees image/png → accepts it;
  • the serve path sniffs the body → emits Content-Type: text/html;
  • the browser renders attacker HTML/JS as a document in remark42's origin.

Details

Downloader

backend/app/rest/proxy/image.godownloadImage(), lines 189-206:

contentType := resp.Header.Get("Content-Type")
if !strings.HasPrefix(contentType, "image/") {
    return nil, fmt.Errorf("invalid content type %s", contentType)
}

maxSize := 5 * 1024 * 1024 // 5MB default
if p.ImageService != nil && p.ImageService.MaxSize > 0 {
    maxSize = p.ImageService.MaxSize
}
lr := io.LimitReader(resp.Body, int64(maxSize)+1)
imgData, err := io.ReadAll(lr)
if err != nil {
    return nil, fmt.Errorf("unable to read image body: %w", err)
}
if len(imgData) > maxSize {
    return nil, fmt.Errorf("image is too large")
}
return imgData, nil          // <-- bytes never validated, returned as-is

Send Content-Type: image/png and the check passes regardless of what the body
actually contains.

Server

backend/app/rest/proxy/image.goHandler(), line 131:

w.Header().Add("Content-Type", p.ImageService.ImgContentType(img))
_, err = io.Copy(w, bytes.NewReader(img))

backend/app/store/image/image.goImgContentType(), lines 242-249:

func (s *Service) ImgContentType(img []byte) string {
    contentType := http.DetectContentType(img)
    if contentType == "application/octet-stream" {
        return "image/*"
    }
    return contentType                 // <-- returns text/html for an HTML body
}

PoC

self.send_response(200)
self.send_header("Content-Type", "image/png")
self.send_header("Content-Length", str(len(body)))
self.end_headers()
self.wfile.write(body)            # body = <!DOCTYPE html><script>...</script>

Then have the victim open https://<remark42-host>/api/v1/img?src=<base64(attacker-host)>
top-level.

Impact

  • The script can issue authenticated, same-origin API calls with
    credentials: 'include' — the JWT cookie is sent automatically.
  • The script can read the XSRF-TOKEN cookie and re-send it as the
    X-XSRF-TOKEN header, defeating CSRF protection. The attacker acts as
    the victim: delete/edit their comments, change their settings, and — if
    the victim is admin — perform admin actions.

Triggering requires no remark42 account on the target instance; the
attacker only needs to host the malicious upstream URL and deliver the
proxy link to a victim by any means (email, DM, link on another site, etc.).

Fix

v1.16.0 adds layered defense to /api/v1/img and /api/v1/picture/{user}/{id}:

  • rest.SafeImgContentType validates sniffed body bytes against a strict
    allowlist (image/png, image/jpeg, image/gif, image/webp,
    image/bmp, image/x-icon). Non-image content returns 415 with no
    body echo. SVG is implicitly excluded.
  • Every response carries
    Content-Security-Policy: default-src 'none'; sandbox; frame-ancestors 'none',
    X-Content-Type-Options: nosniff, and
    Content-Disposition: inline; filename="image".
  • The ETag is bumped to "v2:<base64(src)>". Browsers that revalidate
    cached pre-fix responses get a fresh validated 200 instead of a 304
    against the poisoned cached entry.
  • The strict default-src 'none'; sandbox CSP also applies to all
    /api/v1/* routes as defense-in-depth.

Residual exposure

Browser-local caches that already hold a pre-fix text/html response with
Cache-Control: max-age=2592000 keep serving it from local store until
the TTL expires or the cache is evicted under memory pressure. The ETag
bump only reaches clients that revalidate during the cached lifetime.
Operators running a CDN/edge cache in front of remark42 should purge
/api/v1/img after deploying v1.16.0.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Changed
Confidentiality
High
Integrity
Low
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.0/AV:N/AC:L/PR:N/UI:R/S:C/C:H/I:L/A:N

CVE ID

CVE-2026-48788

Weaknesses

Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')

The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. Learn more on MITRE.

Interpretation Conflict

Product A handles inputs or steps differently than Product B, which causes A to perform incorrect actions based on its perception of B's state. Learn more on MITRE.

Credits