Repository navigation
Check the sha256 of an SMDA report before it goes into a backend path - #271
Merged
Merged
Conversation
The submit form and promote_query both hand the sha256 an .smda report declares to getSampleBySha256, which puts it into the request path unquoted. A value with dot segments therefore addressed a different backend route, and the request carried this server's token. The upload had to be a contributor's; the promote case is planted by any visitor's query and fired by the contributor who promotes it. Both places now require 64 hex digits. A report without one is refused with a 400 on submit, and cannot be promoted. Submit also lowercases the hash, as promote_query already did: the corpus holds lowercase hashes and both the lookup and addReport match exactly, so an uppercase one added a second copy of a sample that was already there.
This was referenced Oct 9, 2026
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.
An .smda report carries a
sha256field that smda copies as it finds it.submitandpromote_queryboth hand that value toMcritClient.getSampleBySha256, which puts it into the request path without quoting. A value with dot segments therefore addresses a different backend route, and the request carries this server's token. Only the backend's GET routes are reachable this way, and they include maintenance jobs thatadministration.pyguards for admins: in mcrit 1.13.0,/rebuild_indexand/recalculate_minhashesare GET routes (mcrit/server/application_routes.py), so a contributor could start them without the admin role or a CSRF token. Two ways in:A fix for the pagination XSS that the review chained with these two is a separate PR; this one only closes the backend-path half of that chain.
Change. One compiled pattern,
SMDA_SHA256(mcritweb/views/data.py:1470), 64 hex digits matched with\Zso a trailing newline does not pass.submitanswers 400 with a message when the report'ssha256is not a string of that shape (data.py:1499).promote_querytreats such a value like a missing one and stops with the existing "does not record which file it was run for" message (data.py:1658).submitalso lowercases the hash before the lookup andaddReport, aspromote_queryalready did: the corpus holds lowercase hashes and both match exactly, so an uppercase hash added a second copy of a sample that was already there.Behaviour change to know about: an .smda with a null or non-hex
sha256was accepted bysubmitbefore and is now a 400.Verification. Run from this branch's worktree,
tests/testUpload.pyandtests/testPromoteQuery.py: 85 passed. The same two files with onlymcritweb/views/data.pytaken from master: 11 failed, 74 passed: the 10 new parametrised cases, which assert that nogetSampleBySha256call is made, and the uppercase case. The backend side was not run against a real mcrit worker: the tests use the fake backend oftests/conftest.py, and which routes are GET and what they schedule was read from mcrit 1.13.0'sserver/application_routes.pyandStatusResource.py. A real submission would write to the live corpus, so the upload flow was not exercised on the testbed.Tests.
test_an_smda_report_whose_sha256_is_not_one_never_reaches_the_backendcovers dot segments, a query string, a valid digest followed by a traversal, a trailing newline, an integer and null;test_an_smda_report_with_a_real_sha256_is_looked_up_and_addedkeeps the ordinary path working and checks that an uppercase hash is looked up and added in lowercase; it fails without that line.test_a_declared_hash_that_is_not_a_sha256_never_reaches_the_backendis the promote counterpart. Intest_a_report_without_a_usable_hash_promotes_nothingI dropped the assertion that the stored upload was opened under its job id, because the promotion now stops before it looks for the file; the assertion that nothing outside the uploads folder is read stays.Relation to open PRs. #141 rewraps the same SMDA branch of
submit. Merging this branch with #141 gives no conflict in that region, and the mergedsubmitkeeps the check afterupload_sha256 = smda_report.sha256(checked withgit merge-treeof this head and #141). #141 does conflict with master by itself, in mcritweb/views/data.py near the top of the file and in mcritweb/views/params.py, with or without this branch, so it needs a rebase whichever merges first. This PR is small and independent of that rebase, so I suggest it goes first. #130 and #174 also conflict with master on their own (data.py, administration.py, client.py, utility.py for #130;__init__.py, analyze.py, explore.py for #174), and the set of conflicting files is the same with this branch added.Left out. Job ids taken from the URL path (
/data/promote_query/<job_id>,/data/result/<job_id>) also reachgetJobDataunquoted. They are not report-supplied and there are several sites, so they are not part of this change.