[Feat] Support integrity verification for model artifacts#787
[Feat] Support integrity verification for model artifacts#787akaashrp wants to merge 6 commits intomlc-ai:mainfrom
Conversation
Add SRI (Subresource Integrity) hash verification for model config, WASM, and tokenizer files via an optional `integrity` field on `ModelRecord`. When specified, downloaded artifacts are verified against cryptographic hashes (SHA-256/384/512) before loading. - Add `ModelIntegrity` interface and `verifyIntegrity()` using Web Crypto API - Add `IntegrityError` class for hash mismatch errors - Verify config, WASM, and tokenizer in engine loading pipeline - Support `onFailure: "error" | "warn"` behavior - Zero new dependencies, fully backwards compatible - 25 unit tests + 8 integration tests Closes mlc-ai#761
- Show sha256/sha384/sha512 openssl commands in README hash generation - Add `npx verifyfetch sign` as simpler alternative for hash generation - Extract `verifyTokenizerIfNeeded` helper in cache_util.ts to eliminate duplicated tokenizer verification logic - Unify config merging in engine.ts by separating fetch/verify from override spreading, reducing duplication between integrity and non-integrity code paths
- Always fetch config as arraybuffer and conditionally verify, eliminating the if/else branching for fetch format - Add Windows compatibility note recommending cross-platform `npx verifyfetch sign` or Git Bash/WSL for openssl commands
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly bolsters the security of WebLLM by integrating Subresource Integrity (SRI) verification for all critical model artifacts. This new feature allows the system to cryptographically ensure that model configurations, WebAssembly binaries, and tokenizer files have not been altered or corrupted during transit or storage. By providing a robust mechanism for verifying the integrity of these components, WebLLM enhances trust and reliability, safeguarding against potential security vulnerabilities in web-based LLM deployments. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a valuable security feature: integrity verification for model artifacts using SRI hashes. The implementation is robust, leveraging the Web Crypto API for hashing and providing clear error handling with a new IntegrityError type. The changes are well-structured across the codebase, with modifications to the engine, configuration, and utility functions. The addition of a new integrity.ts module with comprehensive unit tests demonstrates high code quality. The documentation in README.md is clear and provides helpful examples and commands for generating hashes. A new example project is also included to showcase the feature. My review includes one suggestion to improve error reporting in the example code. Overall, this is an excellent contribution.
| } else { | ||
| setStatus("Error: " + error); | ||
| } |
There was a problem hiding this comment.
The current error handling for non-IntegrityError cases might not display a useful message, as it relies on the default toString() of the error object, which can result in [object Object]. It's better to explicitly handle Error instances to show the message property, and convert other types to a string for a more informative output.
} else if (error instanceof Error) {
setStatus("Error: " + error.message);
} else {
setStatus("Error: " + String(error));
}
No description provided.