Skip to content

BUG: Remote image fetch has no response body size limit #523

@andrinoff

Description

@andrinoff

Describe the bug

In view/html.go, when fetching remote images for HTML email rendering, io.ReadAll(resp.Body) reads the entire response body without any size limit. A malicious HTML email could reference a very large image URL (or a URL that streams infinite data slowly), causing excessive memory usage or hanging.

resp, err := client.Get(url)
// ...
data, err := io.ReadAll(resp.Body)

While the HTTP client has a 5-second timeout, a slow-drip response within that timeout could still deliver significant data.

To reproduce

  1. Receive an HTML email with an <img> tag pointing to a URL that serves a very large file
  2. Open the email in matcha
  3. Memory usage spikes as the entire response is read into memory

Expected behavior

Use io.LimitReader(resp.Body, maxSize) to cap the response body (e.g. 10MB), similar to how the plugin HTTP API limits responses to 1MB.

OS

All platforms

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workinggood first issueGood for newcomers

    Type

    No type

    Projects

    Status

    In review

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions