80 Commits

Author SHA1 Message Date
Georges-Antoine Assi
f227a3145d
changes from bot review 2026-04-07 22:32:40 -04:00
Alex Vanderveen
6aca8fdfcf
Parse Content-Type essence before validating resource downloads
Problem
_check_content_type used the full Content-Type header string (lowercased) and matched it with startswith(...) against allowed prefixes.

That is mostly fine when the server sends a bare type like application/pdf. It breaks down when vendors send parameters on the same header (e.g. name="…", charset=…). In theory application/force-download; name="…" should still start with application/force-download, but in practice you can get:

Leading whitespace or a UTF‑8 BOM before the type token, so the string no longer starts with your prefix even though the MIME type is correct.
Confusing logs: logging only the lowercased full header is fine, but the decision should be based on the standardized MIME essence (type + subtype, no parameters), which is what other stacks use for “what is this?”
So the fix is to parse the header the usual way and only then apply your allowlist.

What changed
_content_type_essence(header_value)

Takes everything before the first ; (the essence).
Strips whitespace, lowercases, strips a leading BOM (\ufeff) so odd clients/proxies don’t break the check.
_check_content_type

Reads the raw content-type header once.
Runs startswith on the essence, not on the full header with parameters.
Rejects if the essence is empty (missing or useless header).
Logging uses the raw header string (or (missing header)), so operators still see exactly what the server sent.
Call sites and allowed prefixes (image/, application/pdf, etc.) are unchanged; only how the string is normalized before comparison changes.

Security / SSRF
This does not replace URL / SSRF controls; it only makes post-fetch type checking consistent with how Content-Type is defined (essence vs parameters). You are not widening the allowlist—same prefixes, stricter handling of “empty” and clearer matching on the actual type token.

Risk / regression
Low: same allowed prefixes, strictly more tolerant of benign formatting (whitespace, BOM, parameters). The only stricter case is empty essence after strip (e.g. malformed header), which correctly fails the check.

\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

I have reviewed the proposal and these edits will handle cases where the string we match against for the content_type is cleaned up more before comparing against the allow list of content_types.

I have tested this, and confirm that I do not get any errors loading PDFs for game manuals using this.  Please consider this, as this should be compatible with the existing content type allowlist, and easily work with any new types added to it.
2026-04-07 20:25:55 -04:00
Georges-Antoine Assi
b36a8b0cdf
manual types should support octet-stream and force-download response 2026-04-07 14:22:43 -04:00
Georges-Antoine Assi
bae0d0c698
more changes from rview 2026-04-03 11:29:55 -04:00
Georges-Antoine Assi
ceddf2f9e9
changes from bot review 2026-04-03 11:24:02 -04:00
Georges-Antoine Assi
ec8583016b
mega ton of fixes for 4.8 2026-04-03 10:54:31 -04:00
Georges-Antoine Assi
997e2c44aa
start pre-4.8 cleanup 2026-03-12 23:02:12 -04:00
Georges-Antoine Assi
ee8b55e6ef
last set of changes 2026-03-07 09:56:17 -05:00
Georges-Antoine Assi
76bdfb4891
changes from self review 2026-03-07 09:36:45 -05:00
Georges-Antoine Assi
b3659a1226
changes from bot review 2026-03-07 08:58:42 -05:00
Georges-Antoine Assi
b030b98062
attempt to fix vuln reported in PR 2026-03-06 19:42:56 -05:00
Georges-Antoine Assi
eb5e32ed78
[HOTFIX] Fix importing media from gamelist.xml 2025-11-10 17:06:20 -05:00
Georges-Antoine Assi
436b1972c4
tweaks from self review 2025-10-28 12:10:53 -04:00
Georges-Antoine Assi
c1ac9a2133
fix screenshots dissapearing on scan 2025-10-28 11:00:45 -04:00
Georges-Antoine Assi
4be180d1bd
ensire dest folders exist on scan 2025-10-26 13:41:19 -04:00
Georges-Antoine Assi
78bfdf0543
fixes from bot review 2025-10-24 19:13:13 -04:00
Georges-Antoine Assi
d928c9705f
fix media storage for gamelistxml 2025-10-24 19:06:45 -04:00
Georges-Antoine Assi
463bb27ea9
Add config to store media on disk 2025-10-24 16:04:54 -04:00
Georges-Antoine Assi
9fa15d20f0
totally refactor scan types 2025-10-23 16:57:40 -04:00
Georges-Antoine Assi
5aa344b3ce
select media format for scan 2025-10-22 19:08:42 -04:00
Georges-Antoine Assi
290162e56b
import media assets 2025-10-22 12:44:58 -04:00
Georges-Antoine Assi
3cfc52234a
start work on gamelist.xml extraction 2025-10-16 23:16:39 -04:00
Georges-Antoine Assi
38006e7aa0
[ROMM-2497] Add button to delete manual 2025-10-07 10:21:02 -04:00
Georges-Antoine Assi
5d9119ebe1
[ROMM-2467] Uncompress gzipped images 2025-09-21 16:06:45 -04:00
Georges-Antoine Assi
bf631cfa74
fix updating image preview + force webp 2025-09-05 09:42:25 -04:00
Michael Manganiello
e4e3928d1b
misc: Apply import sorting 2025-09-04 11:17:00 -03:00
Georges-Antoine Assi
45edc8fcc0
use stores for loading global data 2025-08-28 09:48:52 -04:00
Georges-Antoine Assi
586ce0ef30
Craete image to webp task 2025-08-27 22:12:12 -04:00
Georges-Antoine Assi
a8dc3d3e8d
Await .file_exists() when storing badges 2025-08-17 17:43:19 -04:00
Georges-Antoine Assi
81a04e4ab4
Always hash the largest file in compressed multi file roms 2025-08-13 13:43:07 -04:00
Georges-Antoine Assi
4728e5da67
[ROMM-2247] Return early if cover write fails 2025-08-10 14:51:06 -04:00
Georges-Antoine Assi
8ce943a514
use fastapi status 2025-08-02 22:17:07 -04:00
Georges-Antoine Assi
2acae8c624
swap ordering of store_artowrk 2025-07-18 23:45:18 -04:00
Georges-Antoine Assi
73545ffa97
[HOTFIX] Fix uploading cover art manually 2025-07-18 23:32:17 -04:00
Georges-Antoine Assi
51652d5084
make all path stuff async 2025-07-18 10:53:55 -04:00
Georges-Antoine Assi
0fa8d215a1
rename function 2025-07-17 21:35:12 -04:00
Georges-Antoine Assi
0df4eb1985
fix some aggressive usage 2025-07-17 21:20:02 -04:00
Georges-Antoine Assi
48eab4c957
fix a bunch of tests 2025-07-17 15:48:46 -04:00
Georges-Antoine Assi
0d95735351
finish updating endpoints 2025-07-17 14:44:13 -04:00
Georges-Antoine Assi
8e43128500
complete resources handler 2025-07-17 13:13:43 -04:00
Georges-Antoine Assi
bf9b4b3465
progress on resources handler 2025-07-17 13:00:37 -04:00
Georges-Antoine Assi
8098d7199f
complete resournces handler 2025-07-17 12:38:40 -04:00
Georges-Antoine Assi
5b80e0ca39
Calculate hashes before fetching metadata 2025-06-12 20:55:49 -04:00
Georges-Antoine Assi
fd18d8e1c9
small tweaks from copilot comments 2025-06-06 12:12:38 -04:00
Georges-Antoine Assi
8c817c7f4b
stop RA from crashing when not available 2025-06-05 11:44:47 -04:00
Georges-Antoine Assi
b9b6e17fd0
Merge pull request #1891 from ianfhunter/patch-1
During a scan, if an image fails to be read, the scan is aborted
2025-05-15 09:33:00 -04:00
Georges-Antoine Assi
9f27c81f73
run trunk check 2025-05-15 09:30:11 -04:00
Ian Hunter
6a52d43169
Update resources_handler.py 2025-05-15 12:28:15 +01:00
zurdi
e270889aa5
Merge branch 'fix/reduce-ram-usage' into feature/retroachievements 2025-05-09 17:02:04 +00:00
zurdi
14761c2c83
refactor: enhance logging with highlighted output for improved readability 2025-05-09 09:05:59 +00:00