Skip to content

fix(file_send): deliver every binary type to the owner as a download - #34159

Open
LucaButBoring wants to merge 2 commits into
kirodotdev:mainfrom
LucaButBoring:crew/mate/file-send-binary-attachment
Open

LucaButBoring wants to merge 2 commits into
kirodotdev:mainfrom
LucaButBoring:crew/mate/file-send-binary-attachment

Conversation

@LucaButBoring

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: file_send delivers a zip, a tarball, an Office document or any other binary file to the owner's dashboard as a download.

file_send refuses every binary (non-UTF-8) file whose MIME type is not in BINARY_MIME_ALLOWLIST, a list of audio, video, image and PDF types. The outbox routes repeat the check: POST /api/outbox/notify answers 400 and GET /api/outbox/{filename} answers 403. An agent that packages its output as export.zip gets Error: binary file type not allowed: application/zip, and the tool description tells it to give the user a path instead.

Why it matters

Agents often produce archives, tarballs and Office documents, and the dashboard delivers none of them to the owner today. The owner has to copy the file off the host by its path, which needs shell or file access to that host.

The refusal on these surfaces does not address the risk that the allowlist exists for. The allowlist's comment says the listed types are safe to render on the dashboard origin and that SVG is left out because it can carry scripts, so the risk it covers is inline rendering. A browser does not render a response served as Content-Disposition: attachment with X-Content-Type-Options: nosniff, and GET /api/file-download already serves every binary type to the owner with those headers.

Not a goal

  • Changing what the Slack and channel upload legs accept: _gate_upload_file refuses types outside the allowlist and runs the binary credential scan.
  • Changing what an outbox caller other than the owner receives, such as a Slack allow-listed user who opens the dashboard with !dashboard. That caller still gets only allow-listed binary types, after the credential scan.
  • Adding a type to the allowlist.

What changed (motivation → approach → change)

With this PR, the allowlist selects the binary types that the dashboard serves inline, and it no longer controls the owner's access to a binary file.

Surface Binary type outside the allowlist on main With this PR
file_send refused copied to the outbox, file card posted
POST /api/outbox/notify 400 file card posted
GET /api/outbox/{filename}, owner 403 200, attachment, nosniff
GET /api/outbox/{filename}, any other caller 403 403
Slack and channel upload legs 400 400

The download serves an unlisted type as an attachment even when the route serves its prefix inline, as for image/tiff. A compressed file such as report.pdf.gz holds gzip bytes and goes out as application/octet-stream. The owner receives it. Any other caller gets a 403, since the credential scan cannot read compressed bytes. The filename check, the SVG and text attachment rules and the non-owner content scan stay in place. The file_send description says that the dashboard previews media, opens a PDF and offers other binary formats as a download that Slack and channel uploads refuse. The allowlist's comment in display_safety.py and the Binary File Handling section of docs/system-specs/modules/security.md describe the allowlist as the inline-render list, and error-code-baseline.json drops the removed notify 400.

The initial import added the allowlist, and a later commit extended it to the Slack upload leg. PR #24792 removed the content scan from the owner's surfaces and kept the allowlist on them without a stated reason. The tool description has stated the refusal since PR #17171, which answered #15433, and this PR replaces that text.

Backwards compatibility

Compatible: Every file that main delivers keeps its status, Content-Type and disposition, except a compressed file such as report.pdf.gz. Main served that file under its inner type, inline to the owner and after the scan to any other caller. The PR adds deliveries to the owner for files that main refuses.

Removes nothing: The owner-side refusal is the code that the diff deletes, and its readers were the tests that this PR updates.

Tests

  • test/test_mcp_core_coverage.py: file_send copies a zip to the outbox and notifies the dashboard. When the Slack leg refuses the zip, the result reports the refusal and the file stays in the outbox.
  • test/test_outbox_binary.py: Notify posts a card for a zip. The owner downloads a zip and a .tiff file as attachment with nosniff, and any other caller still gets a 403 for an .exe file, before the content scan. The owner downloads report.pdf.gz as an application/octet-stream attachment, and any other caller gets a 403 for it.
  • test/test_file_send_skip_reason.py: The description lists each allowlist category and the download outcome.
  • test/test_dashboard_files_composition_contract.py: The per-file error-code sum drops by the removed notify 400.

Proof: PROVEN test/test_dashboard_files_composition_contract.py::test_the_error_code_rows_match_each_owner, test/test_file_send_skip_reason.py::TestToolDescriptionMatchesBehaviour::test_the_description_names_the_types_the_dashboard_renders, test/test_mcp_core_coverage.py::TestFileSend::test_a_zip_is_copied_to_the_outbox_and_notified, test/test_mcp_core_coverage.py::TestFileSend::test_a_zip_the_slack_leg_refuses_stays_in_the_outbox, test/test_outbox_binary.py::TestOutboxNotifyBinary::test_binary_outside_the_allowlist_accepted (head a895f81)

Determinism: The 126 tests in the changed test classes passed in 3 repeated runs and in a run in shuffled order.

Manual verification

N/A: The tests drive the real file_send handler and the real outbox routes through aiohttp's test server. The dashboard file card renders a type other than audio, video or an image as a download link on main, and this PR leaves the card unchanged.

Related Issues

Closes #34158

Sibling sweep

Swept: git grep -n "BINARY_MIME_ALLOWLIST" -- src/
Sibling: src/kiro_crew/dashboard/file_api/channel_upload.py -- not affected -- the upload legs still refuse types outside the allowlist, as Not a goal states
Sibling: src/kiro_crew/wecom/transport.py -- not affected -- it mentions the upload gate's allowlist in comments only
Sibling: src/kiro_crew/dashboard/handlers/files.py -- not affected -- it re-exports the constant for the outbox and upload routes

Pattern harvest

Not generalizable: A single constant served both as the inline-render list and as a delivery gate, and the gate role had no stated requirement behind it.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@LucaButBoring
LucaButBoring requested review from a team and KiroCrewCaptain as code owners November 9, 2026 22:27
@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention labels Nov 9, 2026
@LucaButBoring

Copy link
Copy Markdown
Contributor Author

This PR changes src/kiro_crew/security/display_safety.py, which Sensitive Change Review lists as a sensitive path. The check states that a fork PR changing such a path cannot pass it and that a maintainer takes the PR over on a branch of this repository. Could a maintainer move this change to a repository branch, in a PR that writes Supersedes #34159, keeps me as co-author with Co-authored-by:, runs the real sandbox and is driven green there? I can rebase or answer review comments on whichever PR carries it.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 11, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/file-send-binary-attachment branch from a895f81 to 146d52e Compare November 11, 2026 22:28
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 11, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/file-send-binary-attachment branch from 146d52e to 5b1cb6f Compare November 12, 2026 08:51
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 12, 2026
@KiroCrewCaptain

Copy link
Copy Markdown
Collaborator

Code change approver recommendation: A person should decide

Why: the decider thinks the change is probably fine but estimates a 15% chance that this change introduces a defect, above the 12% limit for approving on its own.

The PR drops the binary-MIME allowlist gate on the owner's own surfaces (file_send, outbox notify, and the owner's outbox download). Unlisted types go to the owner only as attachment + nosniff, the same pattern /api/file-download already uses for the owner. Non-owner download still gets the 403 type refusal before the content scan. The Slack and channel upload legs are untouched. Compressed files (.pdf.gz) are now served as octet-stream instead of an inline inner type. Tests cover each changed path and the inverted ones were updated. Docs, tool description and error-code baseline match the code. No regression or trust-boundary weakening found.

An automated recommendation, not a review: a maintainer still decides. It approves on its own only when the estimated chance of a defect is at most 12% and the change has at most 400 changed lines. Decider v3c (217fe607) · commit 5b1cb6f072 · 258 changed lines. If this recommendation is wrong, reply here: replies are how the approver is evaluated.

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 14, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/file-send-binary-attachment branch from 5b1cb6f to 244bd49 Compare November 14, 2026 14:59
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 14, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/file-send-binary-attachment branch from 244bd49 to aeaed77 Compare November 15, 2026 23:43
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 16, 2026
@LucaButBoring
LucaButBoring force-pushed the crew/mate/file-send-binary-attachment branch from aeaed77 to 52af3b3 Compare November 16, 2026 02:45
@github-actions github-actions Bot added merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed merge conflict Branch has merge conflicts with its base — author must resolve before merge labels Nov 16, 2026
…r type

mimetypes.guess_type reads report.pdf.gz as application/pdf with a gzip
encoding, and the download served the gzip bytes inline as a PDF. A guess
that carries an encoding now falls back to application/octet-stream, which
the owner gets as an attachment and a non-owner gets refused with a 403.
@LucaButBoring
LucaButBoring force-pushed the crew/mate/file-send-binary-attachment branch from 52af3b3 to 4d759bd Compare November 16, 2026 16:30
@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 16, 2026

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention

Projects

None yet

Development

Successfully merging this pull request may close these issues.

file_send cannot deliver a zip or other non-media binary file to the owner

2 participants