Skip to content

Gate Bugzilla attachment downloads behind a mimetype allowlist - #6707

Open
msujaws wants to merge 1 commit into
mozilla:masterfrom
msujaws:attachment-mimetype-allowlist
Open

Gate Bugzilla attachment downloads behind a mimetype allowlist#6707
msujaws wants to merge 1 commit into
mozilla:masterfrom
msujaws:attachment-mimetype-allowlist

Conversation

@msujaws

@msujaws msujaws commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

get_bug_attachments and download_attachment applied no mimetype filter, so a video attachment on a bug got downloaded, read, and billed as tens of thousands of tokens before the agent gave up on decoding it (run 5daab632). download_attachment now refuses anything outside ALLOWED_ATTACHMENT_TYPES plus every text/* subtype, and probes metadata with exclude_fields=data first so a refused attachment's bytes never leave Bugzilla. get_bug_attachments(include_data=true) is narrower still, since a tool result is text and a base64 image is therefore never an image block: it inlines only textual types under 256KiB, for the first 10 that qualify, and points at download_attachment for everything else.

is_patch resolves to text/plain and application/octet-stream resolves from Python's built-in mimetypes table rather than the host's /etc/mime.types, so an update.log behaves identically on a laptop and in the agent containers. The cost is 1 + K requests for K inlined attachments, each wrapped so one inaccessible attachment sets data_error rather than discarding the ones already fetched. libs/agent-tools/tests/test_bugzilla.py goes from 4 tests to 26 and covers download_attachment's body for the first time; dest_path is still an unconstrained agent-supplied string and belongs with the path-hardening work.

Fixes #6701

@msujaws
msujaws requested review from a team as code owners August 24, 2026 21:26
@msujaws
msujaws force-pushed the attachment-mimetype-allowlist branch 2 times, most recently from 9af8d0c to 024c16e Compare August 24, 2026 22:15

@crythms crythms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added a few suggested changes for review

Comment thread libs/agent-tools/agent_tools/bugzilla.py Outdated
Comment thread libs/agent-tools/agent_tools/bugzilla.py Outdated
… a video attachment cost a full download and tens of thousands of tokens and still came back undecodable

get_bug_attachments and download_attachment now check an attachment's effective content type against ALLOWED_ATTACHMENT_TYPES plus every text/* subtype, and probe metadata with exclude_fields=data first so a refused attachment's bytes never leave Bugzilla. is_patch resolves to text/plain and application/octet-stream resolves from Python's built-in mimetypes table rather than the host's /etc/mime.types, so an update.log still comes through and an untyped .mp4 does not, identically on a laptop and in the agent containers.

Fixes mozilla#6701
@msujaws
msujaws force-pushed the attachment-mimetype-allowlist branch from 024c16e to 1abdd75 Compare August 25, 2026 16:34

@crythms crythms left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing the feedback. Looks great!

@msujaws
msujaws enabled auto-merge (squash) August 25, 2026 17:53
@suhaibmujahid
suhaibmujahid requested a review from a team August 25, 2026 21:35
@suhaibmujahid

Copy link
Copy Markdown
Member

@mozilla/hackbot-webcompat is PR okay for you since it changes something you also use?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

frontend-triage (and potentially other agents) should not download and attach screencasts / screen recordings

3 participants