Repository navigation
fix(ai): load no remote images, and pin the on-device model - #13
Merged
Merged
Conversation
Two holes in the on-device AI's promise that no note text leaves the browser. Remote images. AI answers render as Markdown, and the CSP's img-src allowed any https host. A prompt hidden in a note (pasted from a web page, say) could steer the model into writing a Markdown image whose URL carries other notes' text, and the browser would fetch it. An image in a shared note also told its sender when it was opened. Markdown now shows images as links, and img-src allows only 'self' and data:. The WebLLM model. web-llm's own record downloads the model's files and its WebAssembly library from the main branches of Hugging Face and GitHub, unchecked. WEBLLM_CONFIG pins both at a commit (Hugging Face 9bd564b, binary-mlc-llm-libs 025bcaf, the commit that added the v0_2_84 library) and gives web-llm SRI hashes for the config, tokenizer.json and the library, with onFailure "error". Loading and removing the model both use it. A test compares it with web-llm 0.2.85's own record. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017cSwEz3Q2o3DpuJ8qSQzY5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Two fixes for #12's on-device AI, so its promise holds that no note text leaves the browser. This PR targets #12's branch, so merging it puts both into #12 before the deploy.
Changes
img-srcallowed anyhttps:host. A prompt hidden in a note (pasted from a web page, say) could steer the model into writing a Markdown image whose URL carries other notes' text, and the browser would fetch it. An image in a shared note also told its sender when it was opened.frontend/src/components/Markdown.tsx: images render as links to them, never as<img>.frontend/public/.ic-assets.json5:img-src 'self' data:. The app has no remote images (checked: no<img>, no CSSurl()insrc/).huggingface.co/.../resolve/main/and its WebAssembly library fromraw.githubusercontent.com/mlc-ai/binary-mlc-llm-libs/main/, with no hash check, so a push to either repository could change the code that reads decrypted notes.frontend/src/lib/localAi.ts:WEBLLM_CONFIGpins the model at Hugging Face commit9bd564band the library at025bcaf(the binary-mlc-llm-libs commit that added the v0_2_84 libraries; the file is unchanged since). It gives web-llm SRI hashes formlc-chat-config.json,tokenizer.jsonand the library, withonFailure: "error".CreateMLCEngineanddeleteModelAllInfoInCacheboth get it.README.md: the "On-device AI" bullet now covers the pin, and a new "No remote images" bullet explains the image rule.Verification
frontend/,pnpm format:check,pnpm typecheck,pnpm test(9 files, 56 tests) andpnpm buildpass, andsrc/canistersis unchanged.verifyIntegrityaccepts all three, and it refuses the library with one bit changed (IntegrityError). Today'smaincopy of the library has the same hash as the pinned one.img-srcallowinghttps:;main;onFailure: "warn";tests/markdown.test.tsx: no<img>, the image is a link.tests/csp.test.ts:img-srcis exactly'self' data:.src/lib/localAi.test.ts: the record is web-llm's own with commits and hashes, and it is the one loading and removal use.Notes
modelVersion) needs a new pin.localAi.test.tsfails on that upgrade, because the record no longer matches web-llm's.Generated by Claude Code