You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
imcp2-deploy 1/6: an icp-project host for a bundle, treated as untrusted input - #230
Adds the imcp2-deploy crate and the library's Host for a bundle, the .tar.gz that icp project bundle writes. Nothing drives it yet.
The bundle is untrusted input. A bundle is handed over by an agent, so the host takes it for exactly what a bundle is and no more:
extract_bundle unpacks it into a scratch directory under a compressed-size limit (256 MiB) and a decompressed-stream limit (1 GiB), refusing symlinks and other non-file entries, more than 250,000 files and directories (counting the parents an entry's path implies), entry paths over 4096 bytes, and anything under .icp/ in any letter case, the id and artifact state a deploy seeds itself.
The FileSystem the library reads the project through is the library's own files::Confined: the root is opened once as a directory handle and every read is made beneath it, so a path that leaves the root (by climbing, by being absolute elsewhere, or by a symlink) is refused, and so is a path through a symlink wherever it leads. The project loader reads through a metered view of it, with a 256 MiB budget on what it retains.
The loaded project is vetted by the library's untrusted rule (icp_project::untrusted::Vetted, what icp deploy --untrusted applies): each build step a pre-built module, each sync step a plugin, each file named a regular file the confined filesystem will give. A script step, a module or plugin fetched from a URL, or a recipe (untrusted::NoRecipes) fails the load, before any phase.
IcMainnet is the network seam: the reserved ic network as the loader supplies it, nothing else. A manifest declaring another network that claims the mainnet root key over an endpoint of its own is refused.
BundledWasm serves local wasm sources from the bundle, sha256 verified. NoScripts is the script runner the syncer is composed with; it spawns nothing.
check_bundle validates the whole bundle before a deploy would run: one pre-built step per canister naming a wasm in the archive that hashes to its recorded checksum (and, gzipped, expands to no more than 100 MiB), canister names that differ by more than letter case, every sync plugin in the archive with the bytes its files: declare held to a sum, Candid text held to core's guard_candid_text, an environment on ic.
Dependencies. The four icp CLI crates (icp-project, icp-events, icp-sync-plugin, icp-canister-interfaces) come from crates.io at 0.1, which carries dfinity/icp-cli#873 on #868. icp-sync-plugin brings wasmtime into the workspace, which is why this is its own crate and not a module of imcp2-core. The crate is publish = false. The manifest lists only what this PR uses; later PRs in the stack add theirs.
What changed in this PR at the re-cut
The icp CLI crates are crates.io 0.1 releases, where this PR had a git pin on icp-cli's main. Cargo.lock grows by 96 packages over main, where the git pin added 129.
One commit, where there were thirteen following the upstream pin.
host.rs is in its final form: the Candid guard on a bundle's arguments and interfaces, which the pipeline PR used to add here, is in.
aterga asked whether some of the third-party crates can be avoided, and for an analysis of the pinned versions. The move to crates.io releases answers the pin half in part: versions are released ones, resolved in Cargo.lock. No per-crate analysis has been written; that is still open.
Changes
crates/imcp2-deploy (new): Cargo.toml, src/lib.rs, src/host.rs (915 lines of code, 748 of tests).
Workspace Cargo.toml adds the member; Cargo.lock.
imcp2-core: guard_candid_text made public and re-exported.
Testing
cargo build --locked --workspace --all-targets
cargo test --locked --workspace --all-targets
cargo fmt --all -- --check
The tests are offline: the network seam, every extraction refusal named above, the confined filesystem serving what the bundle carries and nothing outside it, the load refusing a script step, a remote module, a recipe and a module named through a link, a sync step's declared paths, the loader's read budget, and a module checked once however many canisters name it.
The stack
Six stacked PRs that bring icp deploy to the MCP servers through the icp CLI's own project library. Re-cut on 2026-11-18 so that each file arrives once, in the form it has at the top; the tree at the top is unchanged from before the re-cut, rebased onto current main.
Adds an unpublished imcp2-deploy crate implementing an icp-project host for untrusted project bundles. This establishes the foundation for the deployment pipeline and local MCP tools in the next two PRs.
Changes:
Adds bounded archive extraction, an index-backed filesystem, and bundle validation.
Implements network, wasm, and build adapters, with script execution refused and offline tests included.
Registers the crate and locks the pinned icp-cli dependencies, including the Wasmtime runtime.
File
Description
crates/imcp2-deploy/src/lib.rs
Documents the crate’s scope and exports the host module.
crates/imcp2-deploy/src/host.rs
Implements bundle extraction, host adapters, validation, and tests.
crates/imcp2-deploy/Cargo.toml
Defines the unpublished crate and pins icp-cli dependencies.
Cargo.toml
Adds the workspace member and changes root version declarations.
Cargo.lock
Records the new dependency tree and package version updates.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unresolved critical flaws allow case-insensitive aliases to introduce unintended deployment targets or substitute Wasm artifacts, while unbounded decompression and quadratic index scans expose the server to memory and CPU exhaustion.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Critical resource-budget gaps in archive extraction, plugin execution, and project loading allow crafted bundles to exhaust server memory, disk space, or inodes.
No open issues 🎉
3 previously missed issues
In code that hasn't changed since last review
Repeated file-backed arguments bypass the project-loading memory limit
crates/imcp2-deploy/src/host.rs:361
Project loading can exhaust memory before check_bundle runs: the pinned loader reads each file-backed argument into a separate owned value retained by its canister. Fifty canisters referencing the same 100 MiB binary argument retain roughly 5 GiB despite staying within the extraction limits. Enforce a cumulative project-loading read budget, counting repeated reads, before allocating and returning these buffers to ProjectLoadImpl.
Plugin execution lacks a store memory resource limiter
crates/imcp2-deploy/src/host.rs:744
The pinned Wasmtime runner executes bundle-supplied plugins in the server process with stack and epoch limits but no store resource limiter. A small component can allocate and touch multiple GiB of linear memory, potentially exhausting server memory before the timeout; archive limits do not constrain these allocations. Use a runner with aggregate memory, table, and instance budgets, or run plugins in an OS-resource-limited subprocess.
Implicit archive directories bypass the filesystem-object limit
crates/imcp2-deploy/src/host.rs:827
The entry cap counts archive records, but unpack_in also creates every missing parent directory. A bundle of empty files beneath distinct, deep directory chains can stay within both byte limits and the entry cap while creating millions of directories, exhausting disk space or inodes. Count distinct implicit parent directories against a filesystem-object budget before unpacking each entry.
The three "previously missed" findings in the last review, addressed in ec3c3c3:
Repeated file-backed arguments bypass the project-loading memory limit. The project loader now reads through a metered view of the bundle (Metered in host.rs), charged by file size before each read, with MAX_PROJECT_BYTES (256 MiB) for everything it loads: manifests, argument files and variable files, counted once per canister that names them. The phases keep reading the bundle itself, so a module read several times over a deploy is not charged. Tested at loading_the_project_is_held_to_its_read_budget (two canisters naming one file: the second read is what trips the budget).
Implicit archive directories bypass the filesystem-object limit. Extraction now counts files and directories alike against MAX_BUNDLE_ENTRIES, charging each directory an entry's path implies once (read off the index and the directory entries written so far). Since that walk costs a lookup per component, an entry's path is first held to MAX_ENTRY_PATH_BYTES (4096, Linux's PATH_MAX). Tested at the_directories_an_archive_implies_count_against_its_cap and an_entry_path_past_the_length_limit_is_refused.
Plugin execution lacks a store memory resource limiter. Not bounded here, and host_for's docs now say so. The runner is icp_sync_plugin::Wasmtime, which builds its own Engine and Store inside a private function; nothing on this side of its Run trait can attach a StoreLimits, and the real plugins (e.g. the certified-assets plugin) declare no memory maximum, so a static check on the component would refuse them. The fix is a store limiter in icp-sync-plugin's runner upstream, after which this crate bumps the pinned rev.
#231 and #232 are rebased on top locally and get pushed next.
The reason will be displayed to describe this comment to others. Learn more.
Can we avoid adding some of these 3rd party crates?
For the ones that we cannot replicate, let's have an explicit analysis of the pinned version, since this repo is particularly sensitive to supply chain vulnerabilities.
The reason will be displayed to describe this comment to others. Learn more.
Our own additions are two crates, camino and tar (flate2, tempfile and async-trait were already in the tree). The other ~125 new packages come through the four icp-cli crates: ~60 are wasmtime/cranelift via icp-sync-plugin (the CLI runs sync steps, asset upload included, as wasm plugins), ~10 are cap-std via icp-project's confined filesystem, ~10 are ic-cdk/ledger types via icp-canister-interfaces. Those can't be dropped without reimplementing the CLI's sync runtime. For the rest, I can add a cargo-vet/cargo-deny policy in CI or a per-version review of the pinned set — say which.
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Untrusted plugins can exhaust MCP server memory because the runner lacks hard guest/store memory limits, and existing archive, module-expansion, and file budgets do not constrain guest allocations.
…ted input
The crate takes the icp CLI's project library from crates.io at 0.1
(icp-project, icp-events, icp-sync-plugin, icp-canister-interfaces) and is
not published itself. `host` extracts the archive `icp project bundle`
writes under bounds on its size, entries and paths, reads it through the
library's confined filesystem, and composes the rule `icp --untrusted`
applies: no recipes, no scripts, modules and plugins from the bundle alone,
the `ic` network only.
imcp2-core makes `guard_candid_text` public, for the Candid text a bundle
carries.
Co-Authored-By: Claude Fable 5.2 <[email protected]>
raymondk
changed the title
imcp2-deploy 1/3: an icp-project host for a bundle, treated as untrusted input
imcp2-deploy 1/6: an icp-project host for a bundle, treated as untrusted input
Nov 18, 2026
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Untrusted plugins can exhaust server memory without an aggregate runtime limit, and deeply nested resolved interface types can bypass the text scanner and crash deploy workers through stack overflow.
…what it refuted
A deploy's upgrade compatibility check is candid's subtype check, run
between a bundle's `candid:service` interface and the deployed canister's,
both the caller's to write. On 0.10.35 a chain of two dozen `opt` aliases
whose leaves differ, half a kilobyte and well inside `guard_candid_text`,
ran exponentially long on a thread nothing can interrupt, and a deeper
chain panicked where the check unwrapped its own recursion-limit error.
0.10.39 removes both.
What is left: the check is polynomial in the resolved depth, about cubic,
so an interface the guard admits can still cost seconds (about 18 s
measured for 1,023 aliases of three `opt`s each on a 2 MiB stack).
Co-Authored-By: Claude Fable 5.2 <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because missing bundle-level coverage leaves Candid argument dispatch and interface validation behavior insufficiently verified.
Superseded by the stack #254 → #259, which carries the same code in six PRs from main, with the deploy tools living in imcp2-core instead of a separate crate. The bundle host is in #254.
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
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
Adds the
imcp2-deploycrate and the library'sHostfor a bundle, the.tar.gzthaticp project bundlewrites. Nothing drives it yet.The bundle is untrusted input. A bundle is handed over by an agent, so the host takes it for exactly what a bundle is and no more:
extract_bundleunpacks it into a scratch directory under a compressed-size limit (256 MiB) and a decompressed-stream limit (1 GiB), refusing symlinks and other non-file entries, more than 250,000 files and directories (counting the parents an entry's path implies), entry paths over 4096 bytes, and anything under.icp/in any letter case, the id and artifact state a deploy seeds itself.FileSystemthe library reads the project through is the library's ownfiles::Confined: the root is opened once as a directory handle and every read is made beneath it, so a path that leaves the root (by climbing, by being absolute elsewhere, or by a symlink) is refused, and so is a path through a symlink wherever it leads. The project loader reads through a metered view of it, with a 256 MiB budget on what it retains.icp_project::untrusted::Vetted, whaticp deploy --untrustedapplies): each build step a pre-built module, each sync step a plugin, each file named a regular file the confined filesystem will give. A script step, a module or plugin fetched from a URL, or a recipe (untrusted::NoRecipes) fails the load, before any phase.IcMainnetis the network seam: the reservedicnetwork as the loader supplies it, nothing else. A manifest declaring another network that claims the mainnet root key over an endpoint of its own is refused.BundledWasmserves local wasm sources from the bundle, sha256 verified.NoScriptsis the script runner the syncer is composed with; it spawns nothing.check_bundlevalidates the whole bundle before a deploy would run: one pre-built step per canister naming a wasm in the archive that hashes to its recorded checksum (and, gzipped, expands to no more than 100 MiB), canister names that differ by more than letter case, every sync plugin in the archive with the bytes itsfiles:declare held to a sum, Candid text held to core'sguard_candid_text, an environment onic.Dependencies. The four icp CLI crates (
icp-project,icp-events,icp-sync-plugin,icp-canister-interfaces) come from crates.io at0.1, which carries dfinity/icp-cli#873 on #868.icp-sync-pluginbrings wasmtime into the workspace, which is why this is its own crate and not a module ofimcp2-core. The crate ispublish = false. The manifest lists only what this PR uses; later PRs in the stack add theirs.What changed in this PR at the re-cut
0.1releases, where this PR had a git pin on icp-cli's main.Cargo.lockgrows by 96 packages overmain, where the git pin added 129.host.rsis in its final form: the Candid guard on a bundle's arguments and interfaces, which the pipeline PR used to add here, is in.src/lib.rsis a stub that names the module; the crate's account of itself arrives with the tools in imcp2-deploy 5/6: the MCP tools, served from the local server #232.Review so far
Cargo.lock. No per-crate analysis has been written; that is still open.Changes
crates/imcp2-deploy(new):Cargo.toml,src/lib.rs,src/host.rs(915 lines of code, 748 of tests).Cargo.tomladds the member;Cargo.lock.imcp2-core:guard_candid_textmade public and re-exported.Testing
cargo build --locked --workspace --all-targetscargo test --locked --workspace --all-targetscargo fmt --all -- --checkThe tests are offline: the network seam, every extraction refusal named above, the confined filesystem serving what the bundle carries and nothing outside it, the load refusing a script step, a remote module, a recipe and a module named through a link, a sync step's declared paths, the loader's read budget, and a module checked once however many canisters name it.
The stack
Six stacked PRs that bring
icp deployto the MCP servers through the icp CLI's own project library. Re-cut on 2026-11-18 so that each file arrives once, in the form it has at the top; the tree at the top is unchanged from before the re-cut, rebased onto currentmain.icp-projecthost for an untrusted bundleic-agent, an identity that refreshes#242 (streamed phases, interruption) and #245 (one bundle source per server, crates.io) are closed: their changes are folded into the PRs above.
Checklist
🤖 Generated with Claude Code