Skip to content

fix(dashboard): file-download honours the owner's file-delivery grant - #17899

Merged
chenmingwei23 merged 1 commit into
mainfrom
fix/17404-download-consent
Oct 8, 2026
Merged

chenmingwei23 merged 1 commit into
mainfrom
fix/17404-download-consent

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The dashboard owner can download their own file when the credential scan flags it, by turning on the existing flagged-file delivery setting.

A self-contained HTML page with inline data:image/png;base64,… images cannot be downloaded from the dashboard. GET /api/file-download runs the credential scan; the bare-secret pass finds a key-shaped 40-char window inside the base64 run and the route returns 400 content_redacted. Unlike GET /api/outbox/{filename}, this route has no owner override at all, and the error tells the user to "remove the secret", which is not possible for an image.

Why it matters

Any owner who saves or generates a self-contained HTML report, or any file whose base64 content happens to look key-shaped, hits a dead end: the file is theirs, the route is already owner-only, and nothing they can do in the product releases it.

Not a goal

  • Changing the redaction heuristics (redaction.py). The length cap and the data: carve-out proposed in the issue both reopen a bypass: a real key glued to adjacent base64 chars, or padded inside a data: URI, is caught only because the window slides across the whole run.
  • Making the default state (no grant) accept this file. That needs a structure-aware image check in the scanner and is a separate design question.
  • Extending redaction_switch to downloads. test_credential_redaction_switch.py pins that admission gates do not use the owner view; that pin is untouched.
  • A one-click link from the error to the setting.

What changed (motivation → approach → change)

Symptom: owner's own flagged file is refused with no way out. Root cause: api_file_download never consults the owner_dashboard file-delivery grant, although file_delivery_consent.CLASS_OWNER_DASHBOARD already names the download route in its audience and api_outbox_download already honours it for the same owner-only audience. Change: this route asks the same gate, through one shared helper.

  • handlers/files.py: new shared _owner_grant_releases_flagged (grant read off-loop AND is_owner_dashboard_request), _audit_owner_grant_refusal (names which conjunct refused, and the caller on a cross-principal refusal), _audit_consented_download. api_outbox_download calls them in place of its closures; its behaviour is unchanged.
  • file_api/transfer.py: on a flagged file, api_file_download asks the shared helper. Refused: the same 400 content_redacted, plus a consent audit_refusal entry. Released: the SEL success entry carries sensitive_content_delivered_with_consent and a consent delivered entry is written. The front require_owner_dashboard_request gate is unchanged.
  • file_api/transfer.py also runs the wide pass (wide_content_is_flagged) that every other owner-facing file gate runs (platform.wide_content_is_flagged documents it as running at every file-delivery gate). Behaviour change: a file holding a credential written at UTF-16/UTF-32 spacing, which this route served before, is now refused with the same 400 content_redacted unless the owner's grant is on. Without it, the grant gate added here would be the only owner-facing gate that releases on a narrower notion of "flagged" than its peers.
  • file_delivery_consent.py: docstring lists /api/file-download in the owner_dashboard class.
  • Frontend: the blocked copy names Settings → Security → Flagged-file delivery instead of "Remove the secret", in all 12 locales; en-XA regenerated.

Existing grants: a grant recorded before this PR now also releases flagged files on this route. The Settings copy (file_delivery_desc) already says the grant lets the product "hand such a file to this computer and your dashboard's Files view", and this route is the Files view's Download, serving the same owner to the same authenticated browser. The audience does not widen, so no re-consent is asked for.

Backwards compatibility

Compatible: the outbox route's behaviour and every refusal response shape are unchanged; a non-owner is still stopped at the front gate (403). The one new refusal (wide-encoded credential, no grant) is listed above.

Removes nothing: no route, key, field or function main exposes is removed or renamed; the outbox closures become module helpers with the same logic.

Tests

test/test_file_download.py::TestFlaggedDownloadHonoursOwnerGrant (mocked requests, no server):

Case Expect
inline-PNG HTML, no grant 400 content_redacted
inline-PNG HTML, grant + owner 200, original bytes, consent delivered entry
grant + non-owner (front gate forced open) 400, refusal names non-owner caller
grant + non-owner (real front gate) 403
real-shaped key, no grant 400, refusal no grant
UTF-16 key, no grant (wide pass) 400
clean file 200, grant never read

Four of these fail on origin/main. Structural pins in test_file_delivery_consent.py read the shared helper and assert both routes call it; test_dashboard_files_composition_contract.py lists the three new facade definitions. PierreWorkspaceTreeImpl.test.tsx asserts the new copy names the setting.

Manual verification

Ran: test_file_download.py test_file_delivery_consent.py test_outbox_binary.py test_credential_redaction_switch.py test_dashboard_files_composition_contract.py test_security_posture.py test_owner_gate_file_readers.py test_dashboard_files_onloop_fs.py test_no_config_dir_in_async.py (all pass), and vitest src/i18n + PierreWorkspaceTreeImpl.test.tsx (854 pass). flake8, isort, black (non-baselined files) and the comment-history gate are clean. The screenshot below is the built SPA with the download route stubbed to its refusal.

Screenshots / video

The file viewer's ⋯ → Download on a flagged file, no grant: the error now names the setting that releases it.

download-blocked

Related Issues

Fixes #17404

Pattern harvest

Not generalizable: the defect is one route that never read an existing grant; the class (owner-facing gates reading the grant) is now pinned by test_the_download_gate_requires_both_conjuncts, which asserts every owner-facing download route calls the one shared helper.

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

Contribution License Agreement

Contributed under the project's Apache-2.0 license.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

UX-level review of 68861383c860d150d8fbc334839330c78af26085 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

UX-Verdict: PASS

Check the Settings → Security → Flagged-file delivery page tells the user the grant covers every flagged file, not just this one. The blind reader could not tell which.

[UX-REVIEWED] 6886138

Description read

[DESCRIPTION-READ] 655290bb0b4483bb93f8f49ecd98d236c5b33945a9a9127e61699e8ddaa70761

That sha256 names everything this verdict read: the PR description, plus the 4 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 68861383c860d150d8fbc334839330c78af26085 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the file_delivery_desc Settings copy really covers whole-workspace downloads: existing grants now release any flagged workspace file, not just outbox files.

[DESIGN-REVIEWED] 6886138

Description read

[DESCRIPTION-READ] d4dc2c7a82e609c0353582f242b0ce8c334d76c9ed7671fc482a263bcdb36d44

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 68861383c860d150d8fbc334839330c78af26085 — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

First-Principles-Verdict: PASS

Verify before merge: without a grant, a file holding a UTF-16/UTF-32 credential used to download from this route and is now refused.

What this change ships

Inventory (6 items) — 6 justified

Intent: let the dashboard owner download their own file when the credential scan flags it, by turning on the existing flagged-file delivery setting. This is a FIX (#17404).

  1. The owner, with the flagged-file delivery grant on, can now download a flagged file through Files → Download — justified
  2. A grant recorded before this PR now also releases flagged files on this route — justified
  3. Without a grant, a file holding a wide-encoded (UTF-16/UTF-32) credential is newly refused on this route — justified
  4. The "Download blocked" message in all 12 locales now points to Settings → Security → Flagged-file delivery instead of "Remove the secret" — justified
  5. Refused and released flagged downloads on this route now write consent-audit entries, and the success log entry is marked as delivered with consent — justified
  6. The outbox download's grant check and audit closures become shared module helpers that both routes call — justified

[FIRST-PRINCIPLES-REVIEWED] 6886138

Description read

[DESCRIPTION-READ] 3ddd90fa16b0a8f40d8ad39e242b713f88d10d9da5827c1ff73ef9b204698be1

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 68861383c860d150d8fbc334839330c78af26085 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 6886138

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 68861383c860d150d8fbc334839330c78af26085: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed 68861383c860d150d8fbc334839330c78af26085 — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] 6886138

Verdict parsed from the review's SHA-scoped output markers for commit 68861383c860d150d8fbc334839330c78af26085.

False positive or not applicable? A repository writer can comment:
/ai-review override fable 68861383c860d150d8fbc334839330c78af26085: <one-sentence reason>

@iamwhatever

iamwhatever commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor Author

Screenshot evidence: the Download blocked message in the file viewer, naming the flagged-file delivery setting.

download-blocked

@iamwhatever
iamwhatever force-pushed the fix/17404-download-consent branch from af47c16 to 40eef6a Compare October 7, 2026 22:45
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Dispositions for the review on af47c16b (new head 40eef6a6, rebased on main):

GPT 6.1 (blocking) — fixed. isolated_consent_store in test/test_file_download.py now takes _floor_monkeypatch instead of the shared monkeypatch.

UX Review (BLOCK, missing screenshot) — fixed. The description now carries a screenshot of the file viewer's Download refusal from the built SPA, showing the new copy that names Settings → Security → Flagged-file delivery. Watch items: a direct link from the error to the setting is listed under "Not a goal" (a follow-up, not needed for the fix); the screenshot shows the full English string fits in the panel's notice.

Design Review (CONCERNS).

  • Existing grants now cover this route: answered in the description under "What changed". The Settings copy already says the grant lets the product hand such a file to "this computer and your dashboard's Files view"; this route is that view's Download, same owner, same authenticated browser. The audience does not widen, so no re-consent.
  • Wide pass refuses files it served before: the description now states this as a behaviour change.

First Principles (CONCERNS) — kept, by maintainer decision. The wide pass was asked for explicitly in this item's scope ("add the wide pass the outbox route runs if it fits cleanly"). It fits as one short-circuited branch on the same grant gate. The reason it belongs with the fix: once this route honours the shared grant, it should agree with the peer gates on what "flagged" means, or the one grant releases on two different definitions. The behaviour change is stated in the description.

Frontend Tests (fr spacing) — fixed. U+202F before the colon in the French copy.

Backend Tests (Windows) shards 2/6/8 failed in test_http_server_bind_ratchet, test_session_control_doc and test_members_dm_thread (a Windows temp-dir PermissionError). None of those subjects is in this diff; the new head is rebased on main and reruns them.

@iamwhatever
iamwhatever force-pushed the fix/17404-download-consent branch from 40eef6a to 7cd9356 Compare October 7, 2026 23:19
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Dispositions for 7cd93565:

UX Review (CONCERNS) — no change in this PR.

  • "Doesn't say what the scan found": the route only knows that the scan flagged the file, not which span matched, and naming the match would echo part of a possible secret into the UI. The copy keeps to what is true: the scan flagged it, and how the owner can release a file of their own. A clearer reason line can be done as a copy-only follow-up across all 12 locales.
  • "Download vs delivery": the setting's own label is "Flagged-file delivery", and the copy quotes it verbatim so the owner can find it. Renaming the setting is out of this PR's goal.

CI reds on this head, none in this diff:

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 7, 2026
GET /api/file-download refused every flagged file with no owner
override, so a self-contained HTML page with inline base64 images
could not be downloaded. The route now applies the owner_dashboard
grant plus owner identity, through one helper shared with
GET /api/outbox/{filename}, and runs the same wide pass.

The redaction heuristics are unchanged. The blocked copy points at
Settings -> Security -> Flagged-file delivery.

Fixes #17404
@iamwhatever
iamwhatever force-pushed the fix/17404-download-consent branch from 7cd9356 to 6886138 Compare October 8, 2026 00:14
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 8, 2026
@KiroCrewCaptain
KiroCrewCaptain enabled auto-merge (squash) October 8, 2026 04:23
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Self-review (crew-pr-reviewer, read-only): HOLD for a maintainer / security owner

Reviewed head 6886138. The owner can now download their own flagged file when the existing flagged-file delivery setting is on. This changes a credential-scan release path, so a security owner must approve. All three lanes PASS.

@chenmingwei23
chenmingwei23 merged commit 7ef82c2 into main Oct 8, 2026
101 checks passed
@chenmingwei23
chenmingwei23 deleted the fix/17404-download-consent branch October 8, 2026 05:59
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants