From 19110a4727adfa598fc4db52e81d64696184a9f6 Mon Sep 17 00:00:00 2001 From: Coff0xc <184964491+Coff0xc@users.noreply.github.com> Date: Sat, 21 Nov 2026 19:52:13 +0000 Subject: [PATCH] fix(traffic): keep spilled capture blobs owner-only HTTP and raw-stream bodies written under _blobs were 0644 in a 0755 directory, so any local user could read captured traffic. New blobs are 0600 and the bucket directory is 0700. An existing blob is tightened when it is seen again. --- CHANGELOG.md | 1 + traffic/blob_perm_test.go | 38 ++++++++++++++++++++++++++++++++++++++ traffic/raw_tcp.go | 4 ++-- traffic/traffic.go | 9 +++++++-- 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 traffic/blob_perm_test.go diff --git a/CHANGELOG.md b/CHANGELOG.md index 5af6fb65..8ae6b52f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,7 @@ All notable changes to this project are documented in this file. The format is b ### Fixed +- **Captured traffic blobs are owner-only**: HTTP and raw-stream bodies spilled out of the database are written `0600`, and their bucket directory is `0700`. An existing blob is tightened when it is seen again. - **Docker Compose database passwords with URL-special characters**: `docker-compose.yml` no longer pastes `POSTGRES_PASSWORD` into `ARTEX_PG_DSN`. The server builds the URL from `ARTEX_PG_HOST`, `ARTEX_PG_PORT`, `ARTEX_PG_USER`, `ARTEX_PG_PASSWORD`, `ARTEX_PG_DBNAME` and `ARTEX_PG_SSLMODE`, percent-encoding the user and password, so `/`, `?`, `%`, `@`, `:` and spaces connect. An explicit `ARTEX_PG_DSN` still wins and is not rewritten. `ARTEX_PG_PASSWORD` is removed from the environment with the other startup secrets (#450). ## [0.7.0] - 2026-11-21 diff --git a/traffic/blob_perm_test.go b/traffic/blob_perm_test.go new file mode 100644 index 00000000..4fc5a78c --- /dev/null +++ b/traffic/blob_perm_test.go @@ -0,0 +1,38 @@ +package traffic + +import ( + "bytes" + "os" + "path/filepath" + "runtime" + "testing" +) + +func TestSpillBlobIsOwnerOnly(t *testing.T) { + dir := t.TempDir() + tr := &Traffic{dir: dir} + body := bytes.Repeat([]byte("a"), maxInlineBody+1) + got := tr.spill(body, "text/plain") + if got.hash == "" { + t.Fatal("expected a spilled blob") + } + blobDir := filepath.Join(dir, "_blobs", "sha256", got.hash[:2]) + blobPath := filepath.Join(blobDir, got.hash+".bin") + info, err := os.Stat(blobPath) + if err != nil { + t.Fatal(err) + } + dirInfo, err := os.Stat(blobDir) + if err != nil { + t.Fatal(err) + } + if runtime.GOOS == "windows" { + return + } + if info.Mode().Perm() != 0o600 { + t.Fatalf("blob mode %o, want 0600", info.Mode().Perm()) + } + if dirInfo.Mode().Perm() != 0o700 { + t.Fatalf("blob dir mode %o, want 0700", dirInfo.Mode().Perm()) + } +} diff --git a/traffic/raw_tcp.go b/traffic/raw_tcp.go index 5bb7a741..ace0167f 100644 --- a/traffic/raw_tcp.go +++ b/traffic/raw_tcp.go @@ -63,7 +63,7 @@ func (t *Traffic) spillRawDir(data []byte, previewCap int) (preview []byte, blob sum := sha256.Sum256(data) h := hex.EncodeToString(sum[:]) blobDir := filepath.Join(t.dir, "_blobs", "sha256", h[:2]) - if err := os.MkdirAll(blobDir, 0o755); err != nil { + if err := os.MkdirAll(blobDir, 0o700); err != nil { log.Printf("[traffic/socks5] failed to create blob directory: %v", err) return append([]byte(nil), data[:previewCap]...), "" } @@ -96,7 +96,7 @@ func writeBlobAtomic(blobDir, blobPath, hash string, data []byte) error { _ = tmp.Close() return err } - if err := tmp.Chmod(0o644); err != nil { + if err := tmp.Chmod(0o600); err != nil { _ = tmp.Close() return err } diff --git a/traffic/traffic.go b/traffic/traffic.go index 8eba165d..8b3ae51f 100644 --- a/traffic/traffic.go +++ b/traffic/traffic.go @@ -873,16 +873,21 @@ func (t *Traffic) spillAt(body []byte, contentType string, maxInline int) stored // One bucket level (256 buckets) is enough to keep any single directory small; // the store only ever holds bodies above maxInlineBody, deduplicated by hash. blobDir := filepath.Join(t.dir, "_blobs", "sha256", h[:2]) - if err := os.MkdirAll(blobDir, 0o755); err != nil { + if err := os.MkdirAll(blobDir, 0o700); err != nil { log.Printf("[traffic] failed to create blob directory: %v", err) return storedBody{inline: clipBytes(body, blobPreview), index: indexText()} } + if err := os.Chmod(blobDir, 0o700); err != nil { + log.Printf("[traffic] failed to restrict blob directory: %v", err) + } blobPath := filepath.Join(blobDir, h+".bin") if _, err := os.Stat(blobPath); os.IsNotExist(err) { - if err := os.WriteFile(blobPath, body, 0o644); err != nil { + if err := os.WriteFile(blobPath, body, 0o600); err != nil { log.Printf("[traffic] failed to write blob %s: %v", h, err) return storedBody{inline: clipBytes(body, blobPreview), index: indexText()} } + } else if err := os.Chmod(blobPath, 0o600); err != nil { + log.Printf("[traffic] failed to restrict blob %s: %v", h, err) } sb := storedBody{hash: h, index: indexText()} if text {