Attachments: three-way MIME classification + cap raise + dangerous filename gate - #178
Merged
Merged
Conversation
…ous filename gate Tighten the gateway's attachment validation layer. mime.go: - Split IsSupportedMediaType into IsDangerous / IsExtractable / IsPassthrough so different code paths can make different decisions. IsSupportedMediaType retained as a deprecated wrapper for existing callers. - New IsDangerousFilename helper catches the application/octet-stream + meaningful-extension pattern (.exe / .bat / .sh / .msi / .ps1 / ...) that pure-MIME checks miss. Gateway callers should run both. consts.go: - MaxMultimodalBodyBytes 30 -> 40 MB (room under Anthropic's 32 MB request limit after base64 + JSON overhead). - MaxDecodedAttachmentBytes 20 -> 25 MB (inline-decoded sum per request). - New MaxFileRefSizeBytes = 500 MB (URL-ref per-file ceiling). - New MaxInlineSingleFile = 25 MB (single-file inline ceiling). cmd/gateway: - task.go + openai/content.go switch the inline-attachment gate from IsSupportedMediaType to the explicit IsDangerous + IsExtractable pair. Dangerous types are rejected at every entry point; non- dangerous unsupported types fall back to URL-only refs instead of being rejected outright. tests: - mime_test.go pins the three-way no-overlap invariant + 30-case IsDangerousFilename denylist (case-insensitive, multi-dot extensions, hidden files). - consts_test.go pins cross-cap invariants. - content_test.go size-limit data updated 21 MB -> 26 MB.
Awakehsh
force-pushed
the
feat/attachment-mime-classification
branch
from
May 12, 2026 07:41
c719fa2 to
c10ac70
Compare
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Tighten the gateway's attachment validation layer: split the previous binary MIME check into an explicit three-way classifier, add a filename-based dangerous-extension gate, and raise the inline/URL-ref size caps to align with what modern multimodal models accept.
What changes
MIME classification — internal/attachments/mime.go
Splits the binary IsSupportedMediaType into three predicates so different gates can make different decisions:
New IsDangerousFilename(name) filename-extension denylist catches the common pattern where a hostile upload arrives as application/octet-stream + a meaningful extension (.exe / .bat / .sh / .msi / .ps1 / .lnk / ...). MIME-only checks miss this — gateway callers should run both.
IsSupportedMediaType is retained as a thin deprecated wrapper (IsExtractable || IsPassthrough) so existing callers keep type-checking; new code should call the explicit predicates.
Size caps — internal/attachments/consts.go
Gateway gates — cmd/gateway/internal/{handlers,openai}/
Tests
Backward compatibility
Test plan