Skip to content

fix: verify pulled blobs and manifests against their digest - #266

Open
Rohilalala wants to merge 1 commit into
oras-project:mainfrom
Rohilalala:fix/verify-digest
Open

Rohilalala wants to merge 1 commit into
oras-project:mainfrom
Rohilalala:fix/verify-digest

Conversation

@Rohilalala

@Rohilalala Rohilalala commented Oct 28, 2026 •

Copy link
Copy Markdown
Contributor

Content fetched from a registry was never checked against the digest it was requested by: download_blob saved whatever bytes came back, get_manifest returned any manifest for a repo@sha256:… reference, and the OCI layout pull stored the manifest under its Docker-Content-Digest header without checking the header against the body (the distribution spec says a client that uses that header must verify it).

Now:

  • download_blob hashes the blob while streaming it into a temporary file beside outfile and moves it into place only when it matches, so a mismatched or interrupted download never leaves a file under the blob's name. A mismatch raises ValueError. The logic is oras.utils.write_verified_file, with oras.utils.check_digest for manifests.
  • get_manifest checks a manifest requested by digest.
  • The layout pull checks the manifest against the header it records and the requested digest, and each index child against its descriptor, so mismatched content is never stored in the layout.

A digest algorithm hashlib doesn't support now raises instead of downloading unchecked. Tag pulls through get_manifest (which don't use the header) are unchanged.

Closes #247 (picks it up after #245 was closed).

@Rohilalala
Rohilalala requested a review from vsoch as a code owner October 28, 2026 11:06
Comment thread oras/provider.py Outdated
for chunk in r.iter_content(chunk_size=8192):
if chunk:
f.write(chunk)
# Write beside the target and move it into place only once it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Please make this into an isolated function we can call, in utils or alongside digest helpers would be preferable.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Moved it into oras/utils/fileio.py next to get_file_hash. write_verified_file(filename, chunks, digest) does the streamed write and check, and check_digest(content, digest) covers manifests, so layout.py calls that too instead of a method on the provider.

Two small changes came with the move. The staging file is now .<uuid>.partial in the same directory, because a fixed <name>.partial could overwrite a real file with that name and failed for names close to the 255-byte limit. And get_manifest now checks the digest after parsing the JSON, so a digest-pinned pull that gets an HTML page back still shows the #223 message.

Comment thread oras/version.py Outdated
__license__ = "Apache-2.0"

__version__ = "0.2.44"
__version__ = "0.2.45"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Double check the version here - I think we haven't released 0.2.44 yet.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Right, main is on 0.2.44 again, so I dropped the bump and rebased onto main. The changelog entry is under 0.2.44 now. I also moved the #223 line from #268 to 0.2.44 to match your downgrade. I can take that out if you would rather keep it separate.

download_blob now hashes the blob while streaming it into a temporary
file beside the target, and moves it into place only when the content
matches the requested digest, so a mismatched or interrupted download
never leaves a file under the blob's name. get_manifest checks the
manifest when it is requested by digest, and the OCI layout pull checks
the manifest against the Docker-Content-Digest header it records, the
requested digest, and each index child against its descriptor.

Both checks live in oras.utils (check_digest, write_verified_file) next
to get_file_hash.

Closes oras-project#247

Signed-off-by: Aditya <205600203+Rohilalala@users.noreply.github.com>

This branch has not been deployed

No deployments
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.

Project does not verify that the content provided by a remote registry matches what was requested

2 participants