Skip to content

Check the sha256 of an SMDA report before it goes into a backend path - #271

Merged
danielplohmann merged 2 commits into
masterfrom
fix/smda-sha256-in-backend-paths
Oct 24, 2026
Merged

danielplohmann merged 2 commits into
masterfrom
fix/smda-sha256-in-backend-paths

Conversation

@r0ny123

@r0ny123 r0ny123 commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

An .smda report carries a sha256 field that smda copies as it finds it. submit and promote_query both hand that value to McritClient.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 that administration.py guards for admins: in mcrit 1.13.0, /rebuild_index and /recalculate_minhashes are GET routes (mcrit/server/application_routes.py), so a contributor could start them without the admin role or a CSRF token. Two ways in:

  • Submit (mcritweb/views/data.py:1499): a contributor uploads an .smda file with the field set. The binary branch hashes the bytes itself and was not affected.
  • Promote (mcritweb/views/data.py:1658): a visitor's .smda query records the same field in its report; the contributor who promotes that query is the one whose request goes out.

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 \Z so a trailing newline does not pass. submit answers 400 with a message when the report's sha256 is not a string of that shape (data.py:1499). promote_query treats 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). submit also lowercases the hash before the lookup and addReport, as promote_query already 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 sha256 was accepted by submit before and is now a 400.

Verification. Run from this branch's worktree, tests/testUpload.py and tests/testPromoteQuery.py: 85 passed. The same two files with only mcritweb/views/data.py taken from master: 11 failed, 74 passed: the 10 new parametrised cases, which assert that no getSampleBySha256 call is made, and the uppercase case. The backend side was not run against a real mcrit worker: the tests use the fake backend of tests/conftest.py, and which routes are GET and what they schedule was read from mcrit 1.13.0's server/application_routes.py and StatusResource.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_backend covers 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_added keeps 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_backend is the promote counterpart. In test_a_report_without_a_usable_hash_promotes_nothing I 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 merged submit keeps the check after upload_sha256 = smda_report.sha256 (checked with git merge-tree of 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 reach getJobData unquoted. They are not report-supplied and there are several sites, so they are not part of this change.

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.
@danielplohmann
danielplohmann merged commit 089f373 into master Oct 24, 2026
8 checks passed
danielplohmann added a commit that referenced this pull request Oct 24, 2026
@r0ny123
r0ny123 deleted the fix/smda-sha256-in-backend-paths branch October 30, 2026 06:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants