Skip to content

fix: security-validated inputs and expanded unit-test coverage - #356

Open
awdemos wants to merge 8 commits into
dagger:mainfrom
awdemos:coverage/unit-test-sweep
Open

fix: security-validated inputs and expanded unit-test coverage#356
awdemos wants to merge 8 commits into
dagger:mainfrom
awdemos:coverage/unit-test-sweep

Conversation

@awdemos

@awdemos awdemos commented Jul 25, 2026

Copy link
Copy Markdown

What this PR does

A combined bug-fix sweep and focused unit-test coverage improvement, since the tests validate the security-related fixes.

Bug fixes

  1. Close temp state file before git notes reads it (repository/git.go)
  2. Check pipe/scanner errors in Windows watch command (cmd/container-use/watch_windows.go)
  3. Validate git ref components and reject path traversal (repository/git.go, repository/repository.go)
  4. Allowlist shell parameter in Environment.Run (environment/environment.go)
  5. Restrict debug log file permissions to owner-only (cmd/container-use/logger.go)

Test coverage improvements

Added pure-unit tests that do not require a Dagger engine or live Git repo:

  • environment/config_extra_test.go, environment/state_test.go, environment/note_test.go
  • mcpserver/args_test.go, mcpserver/tools_test.go
  • cmd/container-use/main_test.go, updates to cmd/container-use/version_test.go
  • updates to repository/git_test.go, repository/repository_test.go

Coverage delta

Package Before After
environment 4.7% 22.1%
mcpserver 5.7% 18.9%
cmd/container-use 20.1% 22.7%
repository 25.4% 27.9%
overall 18.6% 25.9%

Tests

  • go test -short -count=1 ./... passes for all packages.
  • go vet ./... is clean.
  • go fmt ./... is clean.

Note: dagger call lint and full go test ./... could not be run locally because the Dagger/Podman engine on this host is in a bad rootless user-namespace state (cannot re-exec process to join the existing user namespace), which appears to be a Toolbx/host-level issue unrelated to these code changes.

Checklist

  • Bug fix (non-breaking change)
  • Security regression tests added
  • Pure-unit tests added (no Dagger engine required)
  • go test -short ./... passes
  • go vet ./... passes
  • go fmt ./... passes

Explicitly close and check the temporary state file after writing but before

passing its path to git notes. The previous deferred close happened after the

git command ran, which can fail on Windows (open handle prevents git from

reading the file) and masks write/close errors.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Check errors from scanner.Err() and os.Stdout.Write(), and close pipe ends

cleanly after reading. Previously these errors were silently discarded, which

could truncate output or leave pipe handles open on Windows without reporting

failure to the caller.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
Add validateGitRefComponent to reject ref/branch names that start with '-' or

contain unsafe characters before passing them to git commands. Apply validation in

Checkout, Merge, Apply, and initializeWorktree to prevent argument injection.

Also reject absolute paths and '..' traversal in exportEnvironmentFile so that

agent-provided target_file cannot escape the environment worktree on the host

filesystem.

Regression tests included for ref validation and path traversal classification.
Reject unsupported shell strings before building container exec args. This prevents

a caller from passing an arbitrary executable path as the shell interpreter

(e.g. '/bin/echo') in environment_run_cmd.

Regression test included.
Change the default debug stderr log file mode from 0644 to 0600 so that other

users on the same host cannot read potentially sensitive command output or

environment metadata.
Cover KVList CRUD, ServiceConfigs lookup, EnvironmentConfig copy/save,

State marshal/unmarshal/legacy migration, and Notes formatting.

Raises environment short-test coverage from 4.7% to 22.1%.
…se marshaling

Cover newRepositoryTool/newEnvironmentTool schema shapes, createTools,

wrapTool/wrapToolWithClient behavior, and Environment response marshaling.

Raises mcpserver short-test coverage from 5.7% to 18.9%.
Cover version extraction, runtime info string, build info, title

truncation, completion helpers, git URL normalization, safe path creation,

binary file detection, and repository path helpers.

Raises cmd/container-use coverage from 20.1% to 22.7% and repository from 25.4% to 27.9%.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants