Commit 9768f1f
authored
Fix Content-Type header bugs in file downloads and MIME type handling (#14124)
Fixes #14118
This commit fixes multiple bugs related to MIME type handling in file downloads:
1. Fixed tuple-as-string bug where mimetypes.guess_type() was used directly
in f-strings, resulting in invalid Content-Type headers like
"('image/png', None)" instead of "image/png"
2. Added fallback to "application/octet-stream" when MIME type cannot be
determined (when guess_type returns None)
3. Fixed incorrect content type for JSON exports (was "json" instead of
"application/json")
4. Fixed potential AttributeError crash in inline_image template tag when
guess_type returns None and code attempted to call .startswith() on None
Files changed:
- dojo/api_v2/views.py: Risk acceptance file download (API endpoint)
- dojo/utils.py: Generic file response helper function
- dojo/finding/views.py: Finding image downloads and JSON template export
- dojo/engagement/views.py: Risk acceptance proof downloads
- dojo/templatetags/display_tags.py: Inline image template tag
All file downloads now properly set Content-Type headers with appropriate
fallbacks for unknown file types.1 parent cc52641 commit 9768f1f
5 files changed
Lines changed: 6 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
751 | 751 | | |
752 | 752 | | |
753 | 753 | | |
754 | | - | |
| 754 | + | |
755 | 755 | | |
756 | 756 | | |
757 | 757 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1568 | 1568 | | |
1569 | 1569 | | |
1570 | 1570 | | |
1571 | | - | |
| 1571 | + | |
1572 | 1572 | | |
1573 | 1573 | | |
1574 | 1574 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2175 | 2175 | | |
2176 | 2176 | | |
2177 | 2177 | | |
2178 | | - | |
| 2178 | + | |
2179 | 2179 | | |
2180 | 2180 | | |
2181 | 2181 | | |
| |||
2444 | 2444 | | |
2445 | 2445 | | |
2446 | 2446 | | |
2447 | | - | |
| 2447 | + | |
2448 | 2448 | | |
2449 | 2449 | | |
2450 | 2450 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
452 | 452 | | |
453 | 453 | | |
454 | 454 | | |
455 | | - | |
| 455 | + | |
456 | 456 | | |
457 | 457 | | |
458 | 458 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2404 | 2404 | | |
2405 | 2405 | | |
2406 | 2406 | | |
2407 | | - | |
| 2407 | + | |
2408 | 2408 | | |
2409 | 2409 | | |
2410 | 2410 | | |
| |||
0 commit comments