fix(#2): make image ref-file names injective
ref_path() flattened / : @ to _, so evil_bar:v1 and evil/bar:v1 shared a ref file and a poisoned one booted the wrong image with no network contact. Append a hash of the exact reference; old-style ref files are ignored (re-resolved).
This commit is contained in:
@@ -68,6 +68,7 @@ The VM is the boundary. The guest (including a prompt-injected agent or a malici
|
||||
- **vfkit arguments**: paths containing `,` `"` or control characters are refused (vfkit splits options on commas).
|
||||
Workspaces overlapping `~/.wsbx` are refused.
|
||||
- **Registry**: references are validated before any request, digest pins are enforced, and every blob/manifest is sha256-verified.
|
||||
The tag cache is keyed by the exact reference (`a_b:t` and `a/b:t` never share an entry).
|
||||
Auth realms must be https. For public registries, connections to loopback/private/link-local addresses are refused
|
||||
(token realms and redirects included).
|
||||
- **pi config**: allowlisted items only. Symlinks are followed only into `~/.pi/agent` or `~/.agents/skills`, with no cycles
|
||||
|
||||
+12
-1
@@ -199,8 +199,11 @@ pub fn pull(home: &Path, image: &str, refresh: bool) -> Result<Image> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Flattened name for humans plus a hash of the exact reference, so `a_b:t` and `a/b:t` never share a ref file.
|
||||
/// (Pre-hash ref files are simply ignored: the image is re-resolved and gc drops them.)
|
||||
fn ref_path(home: &Path, image: &str) -> PathBuf {
|
||||
home.join("images/refs").join(image.replace(['/', ':', '@'], "_"))
|
||||
let h = hex::encode(Sha256::digest(image));
|
||||
home.join("images/refs").join(format!("{}-{}", image.replace(['/', ':', '@'], "_"), &h[..16]))
|
||||
}
|
||||
|
||||
fn image_dir(home: &Path, digest: &str) -> PathBuf {
|
||||
@@ -485,6 +488,14 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ref_paths_distinct() {
|
||||
let h = Path::new("/h");
|
||||
assert_ne!(ref_path(h, "evil_bar:v1"), ref_path(h, "evil/bar:v1"));
|
||||
assert_ne!(ref_path(h, "docker_sandbox-templates_claude-code"), ref_path(h, "docker/sandbox-templates:claude-code"));
|
||||
assert_eq!(ref_path(h, "alpine"), ref_path(h, "alpine"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn digests() {
|
||||
assert!(check_digest(&format!("sha256:{}", "a".repeat(64))).is_ok());
|
||||
|
||||
Reference in New Issue
Block a user