fix(miniflare): capture decoded bytes for base64 email attachments

Open Beginner friendly
#17,174 0 comments 0 reactions 0 assignees View on GitHub

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
Domain
backend, testing

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
  1. In an empty directory, save the two files below as wrangler.jsonc and worker.mjs. The configuration starts a local-only email binding. The Worker sends an attachment to a reserved example address with base64 content on /base64 and equivalent binary content on /binary. Both requests return the simulated send result.
  2. Install and run Wrangler using these commands. Use the loopback URL printed next to Ready on for $BASE_URL.
npm install --save-exact [email protected]
npx wrangler dev --local --ip 127.0.0.1 --port 0
  1. Request /base64 and /binary at that URL. Each response supplies a messageId. Remove the angle brackets to find its matching <message-id>-1.bin below .wrangler/tmp/email/, then examine the file with od -An -tx1. File capture runs asynchronously, so wait for the file to appear.
  2. Request $BASE_URL/cdn-cgi/local/explorer/api/local/email/sending?worker=attachment-check and compare result[].attachments[0].size for 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 content as 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.ts passes the original value to contentByteLength and storeTempFile when populating the capture metadata and file, respectively. The existing attachment test in packages/miniflare/test/plugins/email/index.spec.ts expects the literal base64content string, 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.bin and 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

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudflare/workers-sdk

All issues in cloudflare/workers-sdk

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.