Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .changeset/verify-out-owner-only.md
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@ linters:
- .NewErr(
- .NewErrf(
- .WriteFile(
- .WriteFileMode(

formatters:
enable:
Expand Down
3 changes: 2 additions & 1 deletion docs/manual.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
5 changes: 4 additions & 1 deletion internal/core/verify/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
20 changes: 20 additions & 0 deletions internal/core/verify/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"context"
"os"
"path/filepath"
"runtime"
"strings"
"testing"
"time"
Expand Down Expand Up @@ -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) {
Expand Down
Loading