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

Aperta Adatta ai principianti
#17,174 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
82/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
typescript
Ambito
backend, testing

Direzione di ricerca

Inizia da packages/miniflare/src/workers/email/send_email.worker.ts, dove l’issue dice che i metadati e i file degli allegati usano il valore del contenuto originale; verifica come viene rappresentato e decodificato lì il contenuto base64. Poi leggi il test degli allegati in packages/miniflare/test/plugins/email/index.spec.ts, che attualmente si aspetta una stringa letterale. Il lavoro è completato quando un allegato base64 valido viene acquisito come byte decodificati con la dimensione decodificata e il comportamento binario esistente continua a funzionare.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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.
Lingua principale
TypeScript
Stelle
4.7k
Fork
1.7k
Merge medio
1g 23h
PR unite (30g)
290

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di cloudflare/workers-sdk

Tutte le issue di cloudflare/workers-sdk

Issue simili

Altre issue su TypeScript

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.