diff --git a/README.md b/README.md index 586da8f..f462082 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/src/oci.rs b/src/oci.rs index 5fc7670..b681352 100644 --- a/src/oci.rs +++ b/src/oci.rs @@ -199,8 +199,11 @@ pub fn pull(home: &Path, image: &str, refresh: bool) -> Result { } } +/// 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());