Fixes sec-2 (minor, security) from the code review.
Problem
The user-supplied image/name CLI argument was interpolated unsanitized into registry/{image}/initrd, so a name containing ../ (e.g. slim run ../../.ssh/authorized_keys) escaped the XDG data dir: place_data_file/create_dir_all created attacker-chosen directories, and vmlinuz/initrd were read from / written to arbitrary locations.
Fix
validate_image_name: rejects empty names, ., .., and anything outside [A-Za-z0-9._:-] (covers normal image refs like alpine:3.15)
Applied at the registry_dir chokepoint used by both build and run, so validation happens before any file operation
registry_dir now returns Result (also removes the double-.unwrap() panic on unwritable XDG dirs)
Defense in depth: containment check that the resolved path stays under the registry root
Unit tests for accepted and rejected names (first tests in the repo)
Verification
slim run '../../.ssh/authorized_keys' → invalid image name, exit 1
slim build '../../tmp/evil' → rejected (also caught by podman's own reference parsing)
@hulthe please review — will not merge until approved.
Fixes **sec-2 (minor, security)** from the code review.
## Problem
The user-supplied `image`/`name` CLI argument was interpolated unsanitized into `registry/{image}/initrd`, so a name containing `../` (e.g. `slim run ../../.ssh/authorized_keys`) escaped the XDG data dir: `place_data_file`/`create_dir_all` created attacker-chosen directories, and `vmlinuz`/`initrd` were read from / written to arbitrary locations.
## Fix
- `validate_image_name`: rejects empty names, `.`, `..`, and anything outside `[A-Za-z0-9._:-]` (covers normal image refs like `alpine:3.15`)
- Applied at the `registry_dir` chokepoint used by both `build` and `run`, so validation happens before any file operation
- `registry_dir` now returns `Result` (also removes the double-`.unwrap()` panic on unwritable XDG dirs)
- Defense in depth: containment check that the resolved path stays under the registry root
- Unit tests for accepted and rejected names (first tests in the repo)
## Verification
- `slim run '../../.ssh/authorized_keys'` → `invalid image name`, exit 1
- `slim build '../../tmp/evil'` → rejected (also caught by podman's own reference parsing)
- `slim build mock-vm` → still succeeds end-to-end
- `cargo fmt --check`, `cargo clippy -- -D warnings`, `cargo test` (2 tests) pass
@hulthe please review — will not merge until approved.
The user-supplied image/name argument was interpolated unsanitized into
registry/{name}/initrd, so a name containing '../' (e.g. 'slim run
../../.ssh/authorized_keys') escaped the XDG data dir and let slim
create directories and read/write files at attacker-chosen locations.
validate_image_name now rejects empty names, '.', '..' and anything
outside [A-Za-z0-9._:-] at the registry_dir chokepoint used by both
build and run, plus a defense-in-depth containment check that the
resolved path stays under the registry root.
Fixes sec-2 from the code review.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Fixes sec-2 (minor, security) from the code review.
Problem
The user-supplied
image/nameCLI argument was interpolated unsanitized intoregistry/{image}/initrd, so a name containing../(e.g.slim run ../../.ssh/authorized_keys) escaped the XDG data dir:place_data_file/create_dir_allcreated attacker-chosen directories, andvmlinuz/initrdwere read from / written to arbitrary locations.Fix
validate_image_name: rejects empty names,.,.., and anything outside[A-Za-z0-9._:-](covers normal image refs likealpine:3.15)registry_dirchokepoint used by bothbuildandrun, so validation happens before any file operationregistry_dirnow returnsResult(also removes the double-.unwrap()panic on unwritable XDG dirs)Verification
slim run '../../.ssh/authorized_keys'→invalid image name, exit 1slim build '../../tmp/evil'→ rejected (also caught by podman's own reference parsing)slim build mock-vm→ still succeeds end-to-endcargo fmt --check,cargo clippy -- -D warnings,cargo test(2 tests) pass@hulthe please review — will not merge until approved.
The user-supplied image/name argument was interpolated unsanitized into registry/{name}/initrd, so a name containing '../' (e.g. 'slim run ../../.ssh/authorized_keys') escaped the XDG data dir and let slim create directories and read/write files at attacker-chosen locations. validate_image_name now rejects empty names, '.', '..' and anything outside [A-Za-z0-9._:-] at the registry_dir chokepoint used by both build and run, plus a defense-in-depth containment check that the resolved path stays under the registry root. Fixes sec-2 from the code review.cb87541151to5b80885207