diff --git a/.changeset/verify-out-owner-only.md b/.changeset/verify-out-owner-only.md new file mode 100644 index 000000000..fb9bf03aa --- /dev/null +++ b/.changeset/verify-out-owner-only.md @@ -0,0 +1,10 @@ +--- +"@stainless-code/verdict": patch +--- + +`verify` writes `.verify.out` at `0600` on Unix instead of `0644`: the stream is +the command's raw output, so a command that prints a credential leaves the value +in it, and the file is now the operator's to read and nobody else's — the same +permission `run` gives `.run.out`. The recorded tail in `patch.json` and the +deep-validation receipts stay redacted as before. Windows has no mode bits to +set, so there the file keeps the directory's inherited ACL. diff --git a/.golangci.yml b/.golangci.yml index 11689ad22..364e7fe63 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -266,6 +266,7 @@ linters: - .NewErr( - .NewErrf( - .WriteFile( + - .WriteFileMode( formatters: enable: diff --git a/docs/manual.md b/docs/manual.md index 288339082..552358c4b 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -3333,7 +3333,8 @@ environment, and the split is deliberate (the security rationale is in your secret-named variables and the argument secrets the argv redaction hides, so the argv and the tail agree about what a credential is. `.run.out` is the child's raw stream — it may hold a credential the child printed — so - it is written `0600` on Unix, the way `.verify.out` keeps its raw stream. + it is written `0600` on Unix, the permission `verify` gives `.verify.out`, + its raw stream beside `patch.json`. Windows has no mode bits for Go to set, so there it takes the directory's inherited ACL and the owner-only guarantee does not apply. diff --git a/internal/core/verify/service.go b/internal/core/verify/service.go index 541c9c245..5bd858799 100644 --- a/internal/core/verify/service.go +++ b/internal/core/verify/service.go @@ -296,8 +296,11 @@ func recordOutcome(dir, now string, exit int, timedOut bool, tail string, sandbo return nil } +// raw output can carry a printed credential, so it is owner-only like .run.out. +const verifyOutputMode = 0o600 + func writeOutputs(outPath, combined string) error { - return atomic.WriteFile(outPath, []byte(combined)) + return atomic.WriteFileMode(outPath, []byte(combined), verifyOutputMode) } func recordTimeoutMarker(timeoutPath, marker string) *core.RefusalError { diff --git a/internal/core/verify/service_test.go b/internal/core/verify/service_test.go index 1ea527206..cf9631822 100644 --- a/internal/core/verify/service_test.go +++ b/internal/core/verify/service_test.go @@ -5,6 +5,7 @@ import ( "context" "os" "path/filepath" + "runtime" "strings" "testing" "time" @@ -192,6 +193,25 @@ func TestVerifyRedaction(t *testing.T) { } } +func TestVerifyOutputOwnerOnly(t *testing.T) { + if runtime.GOOS == "windows" { + t.Skip("NTFS carries no POSIX mode bits") + } + bundle(t, `{"verifyCmd":"printf tok"}`) + cmdr := &scriptCommander{res: core.Result{Stdout: "tok=leakedvalue123"}} + if _, ref := verifycore.Run(context.Background(), + verifyRequest(&collector{}, cmdr, "10", []string{"PATH=/bin"}, true)); ref != nil { + t.Fatalf("Run refusal: %v", ref) + } + info, err := os.Stat(".verdict/state/5201/.verify.out") + if err != nil { + t.Fatalf("stat .verify.out: %v", err) + } + if perm := info.Mode().Perm(); perm != 0o600 { + t.Errorf(".verify.out mode = %#o, want 0o600", perm) + } +} + // TestVerifyTimeout proves a timed-out run records timedOut with the // seconds marker. func TestVerifyTimeout(t *testing.T) {