fix(miniflare): capture decoded bytes for base64 email attachments
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 82/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- typescript
Research direction
Start in packages/miniflare/src/workers/email/send_email.worker.ts, where the issue says attachment metadata and files use the original content value; check how base64 content is represented and decoded there. Then read the attachment test in packages/miniflare/test/plugins/email/index.spec.ts, which currently expects a literal string. Done when a valid base64 attachment is captured as decoded bytes with the decoded size, while the existing binary behavior still works.
Written by the indexing model from the issue text.
Description
What versions & operating system are you using?
Wrangler 4.168.0 from the npm latest tag, with Miniflare 5.20261123.1-beta and workerd 1.20261123.1. Node.js 26.12.0 on Linux x86_64. Source inspected at workers-sdk main commit 927f070ee0589a2567a76f2000dcff60b1b3d2eb. Only the local simulator was exercised.
Please provide a link to a minimal reproduction
Inline two-file reproduction.
Describe the Bug
Summary
In local wrangler dev, a structured Email Sending message with a base64 attachment succeeds, but the captured file contains the base64 characters. Local Explorer also reports the encoded length as the attachment size. The equivalent binary input produces the expected file and size, so these local inspection results depend on how the same attachment bytes were passed to the binding.
Steps to reproduce
- In an empty directory, save the two files below as
wrangler.jsoncandworker.mjs. The configuration starts a local-only email binding. The Worker sends an attachment to a reserved example address with base64 content on/base64and equivalent binary content on/binary. Both requests return the simulated send result. - Install and run Wrangler using these commands. Use the loopback URL printed next to
Ready onfor$BASE_URL.
npm install --save-exact [email protected]
npx wrangler dev --local --ip 127.0.0.1 --port 0
- Request
/base64and/binaryat that URL. Each response supplies amessageId. Remove the angle brackets to find its matching<message-id>-1.binbelow.wrangler/tmp/email/, then examine the file withod -An -tx1. File capture runs asynchronously, so wait for the file to appear. - Request
$BASE_URL/cdn-cgi/local/explorer/api/local/email/sending?worker=attachment-checkand compareresult[].attachments[0].sizefor the two subjects.
Reproduction script: wrangler.jsonc
{
"name": "attachment-check",
"main": "worker.mjs",
"compatibility_date": "2026-11-25",
"send_metrics": false,
"send_email": [
{
"name": "EMAIL"
}
]
}
Reproduction script: worker.mjs
export default {
async fetch(request, env) {
const mode = new URL(request.url).pathname;
const binary = Uint8Array.of(0, 1, 2, 255);
const content = mode === "/base64" ? "AAEC/w==" : binary;
return Response.json(await env.EMAIL.send({
from: "[email protected]",
to: "[email protected]",
subject: "Attachment check " + mode,
text: "See attached.",
attachments: [{
content,
filename: "fixture.bin",
type: "application/octet-stream",
disposition: "attachment",
}],
}));
},
};
Expected behavior
The local capture for the documented base64 attachment should produce an inspectable .bin file with the four decoded bytes and report 4 bytes in Local Explorer. The equivalent binary request serves as a control on the tested release.
Actual behavior
Both endpoints returned HTTP 200 with a message ID. The base64 file contained the eight ASCII characters of AAEC/w==, and Local Explorer reported size 8. The binary control captured the expected four bytes, and Local Explorer reported size 4.
/base64 41 41 45 43 2f 77 3d 3d size=8
/binary 00 01 02 ff size=4
Evidence
- Expected source: The Workers binding interface describes
contentas a base64 string or binary. It warns that binary input is unsupported in local development. The binary request still worked as a control in this Wrangler run. The repository's Email Worker fixture under What to Expect describes opening captured files to inspect their contents and says attachments retain their original extensions. - Failure source: The local Wrangler run above. On the inspected default branch,
packages/miniflare/src/workers/email/send_email.worker.tspasses the original value tocontentByteLengthandstoreTempFilewhen populating the capture metadata and file, respectively. The existing attachment test inpackages/miniflare/test/plugins/email/index.spec.tsexpects the literalbase64contentstring, a 13-character input that is not valid base64. - Evidence provenance: observed
- Local verification: reproduced
- Reproduction completeness: complete
Restoration check
Repeat both local requests and compare their captured files and Local Explorer rows. Each request should still return a message ID. Each file should contain 00 01 02 ff, and each row should report size 4.
Triage assessment
- Impact level: P2
- Assessment status: supported
- Impact basis: Developers inspecting locally captured base64 attachments get different file bytes and attachment sizes from equivalent binary inputs, which can produce misleading local verification of attachment data.
- Workaround status: available
- Workaround basis: Decode the captured file with
base64 -d < capture.bin > decoded.binand inspect the decoded file and its byte count. This produced the same four bytes as the binary control without changing the Worker.
- Dominant language
- TypeScript
- Stars
- 4.7k
- Forks
- 1.7k
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 282
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from cloudflare/workers-sdk
-
Difficulty 2/5 1-3 hours Newbie friendliness 86/100
cloudflare/workers-sdk#17215 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 88/100
cloudflare/workers-sdk#17189 · 3 comments ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
cloudflare/workers-sdk#17187 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 77/100
cloudflare/workers-sdk#17175 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 79/100
cloudflare/workers-sdk#17165 · 1 comment ·
Maintainers usually reply within 1 day
All issues in cloudflare/workers-sdk
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
earendil-works/pi#12615 ·
Maintainers usually reply within 1 day
-
My Caps shows "Shared" on private Caps that were never sharedPossibly taken @AksharP5 claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
CapSoftware/Cap#4569 · 1 comment ·
Maintainers usually reply within 1 day
-
bug
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
OHDSI/Data2Evidence#3749 ·
Maintainers usually reply within 4 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
Flagsmith/flagsmith-nodejs-client#332 ·
Maintainers usually reply within 2 days