diff --git a/changelog.d/fixed-14811-transcript-symlink.md b/changelog.d/fixed-14811-transcript-symlink.md new file mode 100644 index 0000000000..0f28602727 --- /dev/null +++ b/changelog.d/fixed-14811-transcript-symlink.md @@ -0,0 +1 @@ +- Refuse symlinked Copilot session logs when archiving kick transcripts and judging busy visibility (#14811) diff --git a/src/crux/agent/busy_visibility_test.go b/src/crux/agent/busy_visibility_test.go index c104f86b41..5605686221 100644 --- a/src/crux/agent/busy_visibility_test.go +++ b/src/crux/agent/busy_visibility_test.go @@ -587,3 +587,21 @@ func TestScanTranscriptActivityWalksAgentsConcurrently(t *testing.T) { } } } + +func TestNewestCopilotTranscriptActivityIgnoresSymlinkedEvents(t *testing.T) { + home := t.TempDir() + target := filepath.Join(t.TempDir(), "events.jsonl") + if err := os.WriteFile(target, []byte("{}\n"), 0o644); err != nil { + t.Fatal(err) + } + dir := filepath.Join(home, ".copilot", "session-state", "linked") + if err := os.MkdirAll(dir, 0o755); err != nil { + t.Fatal(err) + } + if err := os.Symlink(target, filepath.Join(dir, "events.jsonl")); err != nil { + t.Fatal(err) + } + if got, ok := newestCopilotTranscriptActivity(home); ok { + t.Fatalf("symlinked events.jsonl counted as activity: %v", got) + } +} diff --git a/src/crux/agent/kick_transcript_test.go b/src/crux/agent/kick_transcript_test.go index 9db3b510e5..0b9e771635 100644 --- a/src/crux/agent/kick_transcript_test.go +++ b/src/crux/agent/kick_transcript_test.go @@ -409,3 +409,27 @@ func TestListKickLogs_ReportsHeaderSource(t *testing.T) { t.Errorf("missing file source = %q", got) } } + +// A symlink planted at events.jsonl is refused: the archive falls back to the +// scrollback rather than reading through the link. +func TestArchiveKickLog_RefusesSymlinkedTranscript(t *testing.T) { + m, agent, dir, home := transcriptTestManager(t, "copilot", kickLogSourceAuto) + path := writeTestTranscript(t, home, "copilot", "") + target := filepath.Join(t.TempDir(), "secret.jsonl") + if err := os.WriteFile(target, []byte(readTranscriptFixture(t, "copilot_events.jsonl")), 0o600); err != nil { + t.Fatal(err) + } + if err := os.Remove(path); err != nil { + t.Fatal(err) + } + if err := os.Symlink(target, path); err != nil { + t.Fatal(err) + } + if !m.archiveKickLogLocked(agent, "kick") { + t.Fatal("archive not written") + } + body := newestArchiveBody(t, m, dir) + if !strings.Contains(body, "source: scrollback\n") || strings.Contains(body, "fix issue 42") { + t.Errorf("symlinked transcript was read:\n%s", body) + } +}