You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Bug 2100601 - Add a button to download all of a bug's attachments as a ZIP file - #2855
Some bugs, such as AI security reports, carry dozens of attachments, and analyzing them locally means saving each one by hand. The attachments section of the bug page now has a Download All (ZIP) button that downloads every attachment the user can access as one file, bug-<id>-attachments.zip.
Who gets what
Requester
Gets
Not logged in
No ZIP, login is required
Can't see the bug
The usual access error, no ZIP
Can see the bug
Public attachments
Attacher of a private attachment
Also their own private attachments
Member of the insider group
Also all private attachments
Obsolete and deleted attachments are always left out.
How it works
New attachment.cgi?action=zip&bugid=<id>. The bug is loaded with Bugzilla::Bug->check, and the attachments come from Bugzilla::Attachment->get_attachments_by_bug, the same visibility rule the bug page uses.
Login is required because building a ZIP of every attachment costs far more than serving one, which would make an anonymous endpoint an easy way to abuse the system.
New param attachment_zip_max_size (KB, default 51200 = 50 MB) caps the total. It is checked against the stored sizes before any data is fetched from storage, and it also bounds the memory one request can use, since the ZIP is built in memory.
The ZIP is served as a download only (Content-Disposition: attachment, nosniff, no-store, no charset), and each file in it is logged as attachment-get, like a single download.
Files are named <attach_id>-<filename>, so attachments that share a filename don't overwrite each other. Path separators, : and control characters become _, so no name can extract outside its folder. Names are stored as UTF-8.
The logic lives in the new Bugzilla::Attachment::Zip. attachment.cgi only handles login, logging and the response.
Checked
New t/bmo/attachment-zip.t passes 26/26 against MySQL and the test web server. Over HTTP it logs in as an insider, a non-insider, the attacher and a bug-group member, and also requests anonymously, then checks exactly which files are in each ZIP and that nothing from a restricted bug leaks.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
ZIP generation blocks web workers and retains all attachment payloads in memory, while the feature still has filename compatibility issues, duplicate tab stops, and a download control that can appear when no files are downloadable.
This PR adds a Download All (ZIP) button to Bugzilla’s attachments panel so signed-in users can save a bug’s files without downloading them one at a time.
Changes:
Adds a ZIP download endpoint that respects existing bug and attachment permissions and excludes obsolete and deleted files.
Caps the combined attachment size at 50 MiB by default, prefixes filenames with attachment IDs, and logs each included download.
Adds tests for archive contents, filename handling, size limits, and access permissions.
- Read attachment data through the storage while building the ZIP, so
each attachment's data is not cached in memory alongside the archive.
- Replace characters Windows does not allow in member names, and trim
names to 255 UTF-8 bytes, keeping the id prefix and extension.
- Show the "Download All (ZIP)" button only when at least one active
attachment still has data, matching what the endpoint serves.
- Use a single button instead of a link wrapping a button, so the
control has one tab stop.
…ownload
- Recheck attachment privacy on the loaded rows, closing the window between
get_attachments_by_bug's id query and its row load.
- Hold the bytes actually read from storage to attachment_zip_max_size, since
datasize can count characters rather than bytes.
- Throw attachment_zip_missing_data when an attachment's data is gone during
the build, instead of writing an empty member.
- Strip trailing periods and spaces from member names, again after truncation.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
ZIP downloads can include attachments marked obsolete during loading, and authenticated HEAD requests build the full archive and log downloads even though they send no body.
No open issues 🎉
2 previously missed issues
In code that hasn't changed since last review
Recheck obsolescence on loaded attachments
Bugzilla/Attachment/Zip.pm:40
exclude_obsolete filters IDs before get_attachments_by_bug loads the rows. If an attachment is marked obsolete between those queries, this filter still includes it even though the loaded row is already obsolete. Recheck isobsolete on the loaded row, just as this code does for privacy.
Avoid building and logging ZIPs for HEAD requests
attachment.cgi:531
An authenticated HEAD request builds the entire ZIP and records an attachment-get for each member when logging is enabled, even though no body is sent. After checking access and the stored sizes, return just the ZIP headers for HEAD without building or logging the archive. Don’t set Content-Length on that path because the compressed size is unknown.
…ownload
get_attachments_by_bug applies exclude_obsolete to its id query and loads the
rows in a second query, so an attachment made obsolete in between was still
added to the ZIP. Check isobsolete again on the loaded rows, as is already
done for privacy.
Replying to the two items in the latest Copilot review:
Recheck obsolescence on loaded attachments (Bugzilla/Attachment/Zip.pm:40): fixed in 22a5897. attachments_for_bug now checks isobsolete again on the loaded rows, next to the privacy recheck. The existing test now also hands an obsolete row through the id query and checks that it is dropped. The follow-up bug for moving these rechecks into get_attachments_by_bug will cover obsolescence as well as privacy.
HEAD requests (attachment.cgi:531): not changing this. A single-attachment view() behaves the same way on HEAD: it builds the response and logs an attachment-get. Nothing else in attachment.cgi handles HEAD separately, so a ZIP-only branch would be a one-off. log_user_request records the request method, so a HEAD is logged as HEAD and can't be mistaken for a download. A HEAD costs no more than a GET, and attachment_zip_max_size caps both.
This branch has not been deployed
No deployments
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Some bugs, such as AI security reports, carry dozens of attachments, and analyzing them locally means saving each one by hand. The attachments section of the bug page now has a Download All (ZIP) button that downloads every attachment the user can access as one file,
bug-<id>-attachments.zip.Who gets what
Obsolete and deleted attachments are always left out.
How it works
attachment.cgi?action=zip&bugid=<id>. The bug is loaded withBugzilla::Bug->check, and the attachments come fromBugzilla::Attachment->get_attachments_by_bug, the same visibility rule the bug page uses.attachment_zip_max_size(KB, default 51200 = 50 MB) caps the total. It is checked against the stored sizes before any data is fetched from storage, and it also bounds the memory one request can use, since the ZIP is built in memory.Content-Disposition: attachment,nosniff,no-store, no charset), and each file in it is logged asattachment-get, like a single download.<attach_id>-<filename>, so attachments that share a filename don't overwrite each other. Path separators,:and control characters become_, so no name can extract outside its folder. Names are stored as UTF-8.Bugzilla::Attachment::Zip.attachment.cgionly handles login, logging and the response.Checked
t/bmo/attachment-zip.tpasses 26/26 against MySQL and the test web server. Over HTTP it logs in as an insider, a non-insider, the attacher and a bug-group member, and also requests anonymously, then checks exactly which files are in each ZIP and that nothing from a restricted bug leaks.test_sanitypasses: 70 files, 18,251 tests.