Content addressing for APIs: create immutable IDs from file bytes
Content addressing identifies a file or object by a digest calculated from its content instead of by its name. The same bytes produce the same ID, while changed bytes produce another ID; this can reduce duplicate storage and help verify that fetched content has not changed. Before using it in an API, define exactly which bytes are hashed and which algorithm is used. Do not treat a digest as authorization or proof of who uploaded the content.
Content addressing identifies a file or object by a digest calculated from its content instead of by its name. The same bytes produce the same ID, while changed bytes produce another ID; this can reduce duplicate storage and help verify that fetched content has not changed. Before using it in an API, define exactly which bytes are hashed and which algorithm is used. Do not treat a digest as authorization or proof of who uploaded the content.
Name-based and content-based addresses
A name-based address finds an object by a path or key such as reports/current.json. Its contents can change while the key stays the same. A content address such as sha256:<digest> is calculated from the bytes. If those bytes change, the ID changes; manage each ID as immutable so it never points to different content.
In the notation below, <64 lowercase hexadecimal characters> stands for an actual SHA-256 output. This is a format placeholder, not a value calculated from a particular file.
sha256:<64 lowercase hexadecimal characters>A digest identifies bytes. JSON key order, whitespace, line endings, character encoding, and compression can all change the digest even when data looks semantically equivalent. State whether you hash the original uploaded bytes or a normalized representation. If you normalize, every producer and consumer needs the same deterministic rule.
API storage flow
**Define the representation to identify.** Choose whether to hash original upload bytes or an application-defined canonical representation. Document media type, character encoding, content coding, and size semantics.
**Fix the supported algorithm and format.** Choose a collision-resistant hash and include its name in the identifier. OCI content descriptors use a `sha256:<digest>` format and SHA-256 verification; the algorithm prefix also distinguishes future representations.
**Count bytes and hash while receiving.** Stream the request to temporary storage while counting actual received bytes and updating the digest. Stop if the upload exceeds the configured size cap. The server must compute the digest independently even if the client sends one.
**Compare any declared ID.** If the client provides an expected digest, compare it with the server's calculation and reject a mismatch. Do not choose the storage key solely from an untrusted client string.
**Publish verified bytes as an immutable object.** After checking size and digest, atomically publish under an internal key such as `blobs/sha256/<digest>`. If that ID already exists, verify it contains the same bytes before reusing it. Keep display names or mutable aliases such as `latest` separate from the digest ID.
**Verify on retrieval too.** When content comes from an untrusted store or network, recalculate the digest before passing it to a parser or consumer. If size or digest differs, quarantine it or fail; do not continue processing.
An OCI content descriptor stores media type, raw byte size, and digest together, and recommends verifying both size and digest before consuming content from an untrusted source. Pairing these values in an API makes the verification contract explicit.
What a digest does and does not prove
A collision-resistant hash is designed to make it impractical for two different contents to have the same digest. Comparing an independently calculated digest with one received through a trusted channel can detect changed bytes. A hash alone does not prove who uploaded the file, whether it is safe, or whether a user is authorized to access it. Provenance requires a separate trust mechanism such as a signature; authorization should use user or tenant metadata and policy.
Cross-tenant deduplication can save storage but may create a side channel: another tenant could infer that a particular file exists from response timing or upload behavior. Do not grant access merely because someone knows a digest. Store tenant-to-object relationships separately, and avoid exposing deduplication outcomes where existence is sensitive.
Before deployment
Does the contract say whether you hash original bytes or a deterministic normalized representation?
Are received bytes counted and hashed as a stream, with a size cap?
Does the server compare a client-provided digest with its own calculation?
Are retrieved bytes checked against both expected size and digest before use?
Are immutable content IDs separate from mutable names, tags, or version labels?
Are deduplication, authorization, and provenance handled as separate concerns?
Is there a migration plan that preserves algorithm prefixes and reads existing IDs?
References
[Open Containers Initiative: Content Descriptors and digests](https://github.com/opencontainers/image-spec/blob/main/descriptor.md)
[Open Containers Initiative: content-addressable blobs in Image Layout](https://github.com/opencontainers/image-spec/blob/main/image-layout.md)
[NIST FIPS 180-4: Secure Hash Standard](https://csrc.nist.gov/pubs/fips/180-4/upd1/final)