Check AI model files downloaded through ModelHub against a published SHA-256 hash
Categories
(Core :: Machine Learning: On Device, enhancement)
Tracking
()
People
(Reporter: dudetechitout, Unassigned)
Details
Summary
The WebAssembly runtime is checked against a hash before Firefox uses it, but the AI model files downloaded through ModelHub don't appear to be. I'd like to suggest giving model files the same check.
Current behavior
- WebAssembly runtime - the
ml-onnx-runtimeRemote Settings collection lists the runtime's hash and size. The first time it's needed, Firefox downloads it, checks the hash, and caches it in OPFS. - Model files - these come from the allowed hubs (model-hub.mozilla.org and the approved Hugging Face accounts) and are cached in OPFS. The
modelFilesIndexedDB database tracks each file's ETag, size and revision so Firefox knows whether a cached copy is current, but nothing confirms that the file matches what the publisher released.
More detail in the docs: https://firefox-source-docs.mozilla.org/toolkit/components/ml/architecture.html#downloading-models
In the code:
OPFS.download()intoolkit/components/ml/content/OPFS.sys.mjsacceptssha256HashandfileSizeand verifies the file withmaybeVerifyBlob()when they're provided.MLEngineParent.downloadRSAttachment()intoolkit/components/ml/actors/MLEngineParent.sys.mjspasses both values from the Remote Settings record when it downloads the runtime.ModelHub.getModelDataAsFile()intoolkit/components/ml/content/ModelHub.sys.mjscallsOPFS.download()without either value, so model files are stored as received. A missing hash is not treated as an error -maybeVerifyBlob()just skips the check - so the fix is mostly a matter of supplying the values.
Why it matters
Model files are large binaries that native code has to open and parse. Firefox compiles llama.cpp into its standard build, and llama.cpp has fixed several issues where a specially crafted file could overflow a buffer while loading, for example CVE-2024-21802, CVE-2024-23496, CVE-2025-53630, CVE-2026-27940 and CVE-2026-33298. HTTPS and the list of allowed hubs protect the connection, but they can't detect a file that was changed at the source, on a CDN or in a cache. A hash published separately from the download, in a place Firefox already trusts, would catch a changed file before Firefox ever parses it.
Proposed change
- Publish a SHA-256 hash and expected size for every file in every model revision somewhere Firefox already trusts. Remote Settings, next to
ml-inference-options, seems like a natural fit, since its records are already signed. - In
ModelHub.getModelDataAsFile(), look up the expected hash and size and pass them toOPFS.download(), the same wayMLEngineParent.downloadRSAttachment()does for the runtime. Discard any file that doesn't match. - Optionally, verify cached copies again when they're loaded from OPFS.
- For models without a published hash, either skip them or load them only after the user agrees.
| Reporter | ||
Comment 1•4 days ago
|
||
I wrote up the background in more detail in AI models deserve a hash check too
Description
•