Skip to content

fix(attachments): infer MIME type from filename when stored as octet-stream#115977

Merged
Dav1dde merged 4 commits into
masterfrom
fix/attachment-mime-type-fallback
May 21, 2026
Merged

fix(attachments): infer MIME type from filename when stored as octet-stream#115977
Dav1dde merged 4 commits into
masterfrom
fix/attachment-mime-type-fallback

Conversation

@sentry-junior
Copy link
Copy Markdown
Contributor

@sentry-junior sentry-junior Bot commented May 21, 2026

Summary

normalize_content_type in src/sentry/models/eventattachment.py treats application/octet-stream as a valid explicit content type, so filename-based MIME inference via mimetypes.guess_type is never reached. This causes the attachment download endpoint to serve images (e.g., screenshot.png) as application/octet-stream, breaking consumers that rely on the Content-Type header to process the file.

Change

Treat application/octet-stream as equivalent to None in normalize_content_type, allowing the existing mimetypes.guess_type(name) fallback to infer the correct MIME type from the filename.

Files changed

  • src/sentry/models/eventattachment.py — 2-line fix in normalize_content_type
  • tests/sentry/models/test_eventattachment.py — 6 new unit tests covering the function

Fixes #115976

…stream

normalize_content_type treats application/octet-stream as a valid
content type and returns it as-is, even when the filename has a
recognized extension (e.g., screenshot.png). This causes the download
endpoint to serve images as application/octet-stream, breaking
consumers that rely on the Content-Type header.

Treat application/octet-stream as equivalent to None so the
filename-based mimetypes.guess_type fallback can run.

Fixes #115976
@github-actions github-actions Bot added the Scope: Backend Automatically applied to PRs that change backend components label May 21, 2026
@sentry-junior sentry-junior Bot marked this pull request as ready for review May 21, 2026 11:54
@sentry-junior sentry-junior Bot requested a review from a team as a code owner May 21, 2026 11:54
Copy link
Copy Markdown
Contributor

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 5b51516. Configure here.

Comment thread src/sentry/models/eventattachment.py Outdated
- Use .lower() for case-insensitive MIME type comparison per RFC 2045
- Update test_individual_attachments expectations: foo.txt with
  application/octet-stream now correctly resolves to text/plain
- Add test for case-insensitive octet-stream detection
@sentry-junior sentry-junior Bot requested a review from a team as a code owner May 21, 2026 13:22
@Dav1dde Dav1dde added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label May 21, 2026
@github-actions github-actions Bot removed the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label May 21, 2026
@elramen elramen added the Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests label May 21, 2026
@github-actions
Copy link
Copy Markdown
Contributor

Backend Test Failures

Failures on ed7cc27 in this run:

tests/symbolicator/test_minidump_full.py::SymbolicatorMinidumpIntegrationTest::test_full_minidump_invalid_extralog
[gw1] linux -- Python 3.13.1 /home/runner/work/sentry/sentry/.venv/bin/python3
tests/symbolicator/test_minidump_full.py:139: in test_full_minidump_invalid_extra
    event = self.post_and_retrieve_minidump(
src/sentry/testutils/relay.py:127: in post_and_retrieve_minidump
    assert resp.ok
E   assert False
E    +  where False = <Response [503]>.ok

@Dav1dde Dav1dde merged commit 2592be0 into master May 21, 2026
79 of 92 checks passed
@Dav1dde Dav1dde deleted the fix/attachment-mime-type-fallback branch May 21, 2026 21:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Backend Automatically applied to PRs that change backend components Trigger: getsentry tests Once code is reviewed: apply label to PR to trigger getsentry tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Attachment download serves octet-stream for known file types

3 participants