The cross-harness, self-improving memory layer for AI agents. Join our community: https://discord.com/invite/zdNChS2fBu
Go agent-ai-cliagent-harnessesagent-securitybrowser-extensionciclaude-codecloudcodexcursordetection-engineeringjevknowledge-basememorymobile-device-managementobservabilitysecuritysecurity-information-and-event-managementsecurity-toolstelemetrytraces
fix(hooks): only claim a hook whose executable is the hooks binary (#1228)
kyle-elliott-asymptotee1d66905d383
diff --git a/cli/beacon/internal/endpoint/hooks/cursor_test.go b/cli/beacon/internal/endpoint/hooks/cursor_test.goindex 3e3aa6b9..5cb2a47c 100644--- a/cli/beacon/internal/endpoint/hooks/cursor_test.go+++ b/cli/beacon/internal/endpoint/hooks/cursor_test.go@@ -154,7 +154,7 @@ func TestReadCursorHooksFileReturnsCorruptJSONError(t *testing.T) {func TestRemoveEndpointHooksDeletesFileWhenOnlyBeaconHooksRemain(t *testing.T) {path := filepath.Join(t.TempDir(), "hooks.json")- existing := `{"version":1,"hooks":{"sessionStart":[{"command":"BEACON_ENDPOINT_MODE=1 beacon-hooks session-start"}],"stop":[{"command":"beacon-hooks stop"}]}}`+ existing := `{"version":1,"hooks":{"sessionStart":[{"command":"BEACON_ENDPOINT_MODE=1 beacon-hooks session-start"}],"stop":[{"command":"'/opt/beacon/hooks/beacon-hooks' --platform cursor --log '/var/log/beacon-agent/runtime.jsonl' stop"}]}}`if err := os.WriteFile(path, []byte(existing), 0644); err != nil {t.Fatal(err)}@@ -171,6 +171,31 @@ func TestRemoveEndpointHooksDeletesFileWhenOnlyBeaconHooksRemain(t *testing.T) {}}+// A user's own hook whose script is merely named after the binary is not Beacon's, even when it+// takes a --config flag of its own; uninstall must leave it in place.+func TestRemoveEndpointHooksKeepsUserWrapperNamedAfterTheBinary(t *testing.T) {+ path := filepath.Join(t.TempDir(), "hooks.json")+ wrapper := `'/home/u/scripts/my-beacon-hooks-wrapper.sh' --config ~/.w.json stop`+ existing := `{"version":1,"hooks":{"stop":[{"command":"'/opt/beacon/hooks/beacon-hooks' --platform cursor --log '/var/log/beacon-agent/runtime.jsonl' stop"},{"command":"` + wrapper + `"}]}}`+ if err := os.WriteFile(path, []byte(existing), 0644); err != nil {+ t.Fatal(err)+ }++ if _, err := removeEndpointHooks(path); err != nil {+ t.Fatalf("removeEndpointHooks returned error: %v", err)+ }+ data, err := os.ReadFile(path)+ if err != nil {+ t.Fatalf("read hooks.json: %v", err)+ }+ if !strings.Contains(string(data), "my-beacon-hooks-wrapper.sh") {+ t.Fatalf("user's wrapper hook was removed: %s", data)+ }+ if strings.Contains(string(data), "/opt/beacon/hooks/beacon-hooks") {+ t.Fatalf("Beacon hook was not removed: %s", data)+ }+}+func TestInstallCursorHooksJSONReplacesExistingBeaconHook(t *testing.T) {path := filepath.Join(t.TempDir(), "hooks.json")existing := `{"version":1,"hooks":{"preToolUse":[{"command":"BEACON_ENDPOINT_MODE=1 old-beacon-hooks pre-tool"},{"command":"echo keep"}]}}`diff --git a/docs/changelog/cli.mdx b/docs/changelog/cli.mdxindex a7218a5f..3ae945b7 100644--- a/docs/changelog/cli.mdx+++ b/docs/changelog/cli.mdx@@ -13,11 +13,14 @@ Stay up to date with the latest changes to the Agent Beacon CLI.Changes on `main` since v1.3.58. They ship in the next release.+- **Beacon leaves your own hooks alone when their command mentions `beacon-hooks`** · Install, repair and uninstall used to claim any hook whose command merely contained `beacon-hooks` -- a script like `~/scripts/my-beacon-hooks-wrapper.sh`, `echo beacon-hooks`, or a log file named `beacon-hooks.log` -- as one Beacon had written, so they overwrote or deleted it, and the DeepSeek Harness and Kiro installers replaced a hooks file they should have refused to touch. A hook now counts as Beacon's only when the program it runs is the hooks binary itself and the command carries the endpoint settings an install writes. This applies to every runtime (Cursor, Hermes, VS Code, Kimi Code, OpenHands, Devin, DeepSeek Harness, Kiro and the rest), and `beacon endpoint hooks status` and discovery agree with what uninstall would remove.+- **Redaction covers snake_case secret flags and Stripe webhook secrets, and keeps a URL's other query parameters** · Flags written in snake_case or named for key material (`--client_secret`, `--api_key`, `--private-key`, `--secret-key`) have their values redacted, and so do Stripe webhook signing secrets (`whsec_…`). A secret passed as a URL query parameter (`?api_key=…&user=alice`) is redacted up to the next `&` or `#`, so the parameters after it stay readable; after any other label, `#`, `&` and `?` are still part of the redacted value. A diff line such as `-SECRET_KEY = '…'` keeps its `=`.- **Run and repository metadata is redacted and capped** · The `run` block (CI provider, workflow, branch, pull-request ref, actor), the `vcs` block, and the top-level `model`, `repository` and `branch` were written as they arrived, so a credential in a branch name or remote URL reached the log, and a branch name larger than the event size limit made the whole event unwritable. They now get the same secret redaction and 2 KB limit as every other attribute string, in both the collector's writer and the CLI's.- **Renamed-binary approval bypass catches rm copies under any name** · `approval-bypass-via-renamed-binary` (v3) no longer requires a temp-dir copy of `rm` to be named like `rm`: after a denied dangerous command, running any executable from `/tmp/`, `/var/tmp/`, or `$(mktemp ...)` at command position with an rm-style recursive+force flag (`-rf`, `-v -rf`, a trailing `-rf`) correlates. Temp paths passed as arguments to other tools (`cp /tmp/build -rf`, `tar -C /tmp/stage -rf`, `find /tmp/build -printf`) do not.+- **A repository cannot turn auto-share on through the hook environment** · The hooks read the auto-share setting from `~/.beacon/endpoint/share.json` in the home of the account they run as, looked up from the account (the passwd entry, or the Windows process token), not from `$HOME` or `USERPROFILE`, so a repository that sets `HOME` for its hooks cannot plant a `share.json` that publishes its sessions. On Linux, an account that is not in `/etc/passwd` (LDAP, SSSD) still falls back to `$HOME`. `beacon share auto` writes the same file, and the restricted-log spool also moved to the account's home. The cloud-sandbox shuttle now uploads on Stop and SessionEnd only with `BEACON_ORIGIN=cloud`, which the cloud agent setups already set; `BEACON_CLOUD_*` without it does nothing.- **Fleet package installs turn the local dashboard off** · An unattended first install of the `.deb` or `.rpm`, the macOS `.pkg` or the Windows MSI (Salt, Ansible, an MDM, a silent `msiexec`) now turns the local dashboard off for every account on the machine, root included, as `BEACON_DASHBOARD=disabled` already did: that install sets up the machine for the people who use it, and they should not be able to open a view of its telemetry unless an administrator says so. A person who installs the package on their own machine (`sudo` at a terminal, including the one-line `install.sh`, Installer.app, or the MSI's full interface) keeps the dashboard, by the same test that adds them to `beacon-log`. Upgrades, and reinstalls over a kept config or log, keep the setting an endpoint already has, so set `BEACON_DASHBOARD=disabled` to turn it off on machines installed from an earlier release. `BEACON_DASHBOARD=enabled` keeps it on an unattended install, and `sudo beacon endpoint repair --system --dashboard enabled` turns it back on. Installs from the `beacon` CLI are unchanged. See [Turning the dashboard off](/cli/dashboard#turning-the-dashboard-off).diff --git a/pkg/asymptoteobserve/hookcmd/hookcmd.go b/pkg/asymptoteobserve/hookcmd/hookcmd.goindex 6e47ba9e..7af8f675 100644--- a/pkg/asymptoteobserve/hookcmd/hookcmd.go+++ b/pkg/asymptoteobserve/hookcmd/hookcmd.go@@ -33,17 +33,19 @@ var CursorEvents = map[string][]string{// Both directions are costly. A false negative makes repair add a second hook beside the first// and leaves uninstall's behind; a false positive rewrites or deletes a hook somebody else// installed.+//+// The executable has to be the hooks binary, and running it is not enough on its own: every+// command an install has written also carries endpoint settings or, for the legacy binary, the+// platform. A Beacon-named binary with neither is not something Beacon wrote -- every installer+// has named the platform since the first one -- so claiming it would only ever delete a user's+// own hook.func IsEndpointHook(command, platform string) bool {fields := Fields(command)hasPlatform := platform == "" || hasPlatform(fields, platform)- namesPlatform := namesPlatform(fields)beacon, legacy := binaries(fields)if carriesEndpointSettings(fields) && beacon {- return hasPlatform || !namesPlatform- }- if beacon && !namesPlatform {- return true+ return hasPlatform || !namesPlatform(fields)}return legacy && hasPlatform}@@ -91,22 +93,58 @@ func carriesEndpointSettings(fields []string) bool {return false}-// binaries reports whether any token names the Beacon or legacy hooks binary: its basename, with-// either path separator, contains the stem (so `beacon-hooks.exe` and a renamed-// `old-beacon-hooks` both count). Looking at each token's basename rather than searching the-// whole command keeps a directory named after the binary from passing as the binary itself.+// binaries reports whether the command's executable is the Beacon or legacy hooks binary.+//+// Only the executable counts: the first token after an optional `env` and any `VAR=value`+// assignments, which is where every installer has put the binary. A token anywhere else that+// mentions the binary -- `echo beacon-hooks`, a log file named after it -- is an argument to some+// other program. Its basename, with either path separator and with any `.exe` dropped, must end+// with the stem, so `beacon-hooks.exe` and a renamed `old-beacon-hooks` both count while a user's+// `my-beacon-hooks-wrapper.sh` does not, and a directory named after the binary is not the binary.func binaries(fields []string) (beacon, legacy bool) {- for _, field := range fields {- name := field[strings.LastIndexAny(field, `/\`)+1:]- beacon = beacon || strings.Contains(name, BinaryStem)- legacy = legacy || strings.Contains(name, LegacyBinaryStem)+ name := executable(fields)+ name = name[strings.LastIndexAny(name, `/\`)+1:]+ if len(name) > len(".exe") && strings.EqualFold(name[len(name)-len(".exe"):], ".exe") {+ name = name[:len(name)-len(".exe")]+ }+ return strings.HasSuffix(name, BinaryStem), strings.HasSuffix(name, LegacyBinaryStem)+}++// executable returns the program a command runs, skipping the `env` and `VAR=value` prefixes+// POSIX hook commands have been written with (Hermes's were `env BEACON_ENDPOINT_MODE=1 ...`).+func executable(fields []string) string {+ i := 0+ if i < len(fields) && fields[i][strings.LastIndex(fields[i], "/")+1:] == "env" {+ i+++ }+ for i < len(fields) && isAssignment(fields[i]) {+ i+++ }+ if i == len(fields) {+ return ""+ }+ return fields[i]+}++// isAssignment reports whether field is a shell `NAME=value` environment assignment.+func isAssignment(field string) bool {+ name, _, found := strings.Cut(field, "=")+ if !found || name == "" {+ return false+ }+ for i, r := range name {+ letter := r == '_' || (r >= 'A' && r <= 'Z') || (r >= 'a' && r <= 'z')+ if !letter && (i == 0 || r < '0' || r > '9') {+ return false+ }}- return beacon, legacy+ return true}-// namesPlatform reports whether a command specifies a platform at all. A command that names none-// is treated as an any-platform install, which is how hooks written before the flag existed are-// still recognized. Both `--platform x` and `--platform=x` count.+// namesPlatform reports whether a command specifies a platform at all. A command that carries+// endpoint settings but names none is treated as an any-platform install: the settings already+// show an endpoint install wrote it, and nothing ties it to one runtime. Both `--platform x` and+// `--platform=x` count.func namesPlatform(fields []string) bool {for _, field := range fields {if field == "--platform" || strings.HasPrefix(field, "--platform=") {diff --git a/pkg/asymptoteobserve/hookcmd/hookcmd_test.go b/pkg/asymptoteobserve/hookcmd/hookcmd_test.goindex cd477c5b..b11914e3 100644--- a/pkg/asymptoteobserve/hookcmd/hookcmd_test.go+++ b/pkg/asymptoteobserve/hookcmd/hookcmd_test.go@@ -84,8 +84,11 @@ func TestIsEndpointHook(t *testing.T) {{"equals form, foreign", `/opt/beacon/hooks/beacon-hooks --platform=grok`, "cursor", false},{"equals form, own", `/opt/beacon/hooks/beacon-hooks --platform=cursor --log=/var/log/beacon-agent/runtime.jsonl`, "cursor", true},{"equals form, another runtime", `/opt/beacon/hooks/beacon-hooks --platform=cursor --log=/var/log/beacon-agent/runtime.jsonl`, "vscode", false},- // Written before --platform existed. Repair has to keep finding these or it will leave two.- {"no platform named", `/opt/beacon/hooks/beacon-hooks pre-tool`, "cursor", true},+ // The pre-flag shape: endpoint settings with no platform is an any-platform install.+ {"settings, no platform named", `BEACON_ENDPOINT_MODE=1 /opt/beacon/hooks/beacon-hooks pre-tool`, "cursor", true},+ // Nothing an install ever wrote ran the binary with neither settings nor a platform, so a+ // command like this is somebody else's, and repair or uninstall must leave it alone.+ {"no settings and no platform", `/opt/beacon/hooks/beacon-hooks pre-tool`, "cursor", false},{"legacy binary", `/opt/asym/asym-hooks --platform cursor pre-tool`, "cursor", true},{"legacy binary, another runtime", `/opt/asym/asym-hooks --platform claude pre-tool`, "cursor", false},// A directory named after the binary is not the binary.@@ -101,6 +104,57 @@ func TestIsEndpointHook(t *testing.T) {}}+// Every shape an installer writes, or has written, must keep matching its own platform; otherwise+// repair adds a duplicate and uninstall leaves the old hook behind.+func TestIsEndpointHookRecognizesEveryWrittenShape(t *testing.T) {+ cases := []struct {+ name string+ command string+ platform string+ }{+ {"current POSIX form", `'/Users/dev/.beacon/endpoint/hooks/beacon-hooks' --platform claude --log '/Users/dev/.beacon/endpoint/logs/runtime.jsonl' --config '/Users/dev/.beacon/endpoint/config.json' stop`, "claude"},+ {"current form on Windows through Git Bash", `'C:\Users\dev\.beacon\endpoint\hooks\beacon-hooks.exe' --platform claude --log 'C:\Users\dev\.beacon\endpoint\logs\runtime.jsonl' stop`, "claude"},+ {"Kimi on Windows, double-quoted for cmd.exe", `"C:\Program Files\Beacon\hooks\beacon-hooks.exe" --platform kimi --log "C:\ProgramData\Beacon\Endpoint\logs\runtime.jsonl" --config "C:\ProgramData\Beacon\Endpoint\config.json" pre-tool`, "kimi"},+ {"upper-case extension", `"C:\Beacon\beacon-hooks.EXE" --platform kimi --log "C:\r.jsonl" pre-tool`, ""},+ {"older env-prefix form", `BEACON_ENDPOINT_MODE=1 BEACON_ENDPOINT_LOG='/var/log/beacon agent/runtime.jsonl' BEACON_ENDPOINT_CONFIG='/etc/beacon/config.json' '/opt/beacon/hooks/beacon-hooks' --platform cursor stop`, "cursor"},+ {"older Hermes env form", `env BEACON_ENDPOINT_MODE=1 BEACON_ENDPOINT_LOG='/tmp/r.jsonl' BEACON_ENDPOINT_CONFIG='/tmp/c.json' '/opt/beacon/hooks/beacon-hooks' --platform hermes post-tool`, "hermes"},+ {"Cursor cloud", `BEACON_ENDPOINT_MODE=1 BEACON_ORIGIN=cloud BEACON_RUN_PROVIDER=cursor_cloud BEACON_RUN_EPHEMERAL=true BEACON_ENDPOINT_LOG='/tmp/runtime.jsonl' '/opt/beacon/beacon-hooks' --platform cursor pre-tool`, "cursor"},+ {"Claude web", `BEACON_ENDPOINT_MODE=1 BEACON_ENDPOINT_LOG='/tmp/runtime.jsonl' '/opt/beacon/beacon-hooks' --platform claude session-start`, "claude"},+ {"renamed binary as the executable", `BEACON_ENDPOINT_MODE=1 old-beacon-hooks --platform claude post-tool`, "claude"},+ {"legacy binary", `/tmp/asym-hooks --platform claude post-tool`, "claude"},+ }+ for _, tc := range cases {+ t.Run(tc.name, func(t *testing.T) {+ if !IsEndpointHook(tc.command, tc.platform) {+ t.Fatalf("IsEndpointHook(%q, %q) = false, want true", tc.command, tc.platform)+ }+ })+ }+}++// A user's own hook that merely mentions the binary's name is not Beacon's, for any platform.+// Claiming one let repair overwrite it and uninstall delete it.+func TestIsEndpointHookRejectsCommandsThatOnlyMentionTheBinary(t *testing.T) {+ commands := []string{+ `'/home/u/scripts/my-beacon-hooks-wrapper.sh' stop`,+ `'/home/u/scripts/my-beacon-hooks-wrapper.sh' --config ~/.w.json stop`,+ `'/home/u/scripts/my-beacon-hooks-wrapper.sh' --platform cursor --log /tmp/r.jsonl stop`,+ `echo beacon-hooks`,+ `BEACON_ENDPOINT_MODE=1 echo beacon-hooks --platform cursor`,+ `python run.py --log /tmp/beacon-hooks.log`,+ `python run.py --platform cursor --log /tmp/beacon-hooks.log stop`,+ `/usr/local/bin/audit --config /opt/asym-hooks --platform cursor`,+ `env FOO=1 /home/u/beacon-hooks-helper --log /tmp/r.jsonl --platform cursor`,+ }+ for _, command := range commands {+ for _, platform := range []string{"", "cursor", "hermes", "vscode", "kimi", "openhands", "devin-cli", "dsh", "kiro"} {+ if IsEndpointHook(command, platform) {+ t.Errorf("IsEndpointHook(%q, %q) = true, want false", command, platform)+ }+ }+ }+}+func TestRuns(t *testing.T) {cases := []struct {name string@@ -116,7 +170,7 @@ func TestRuns(t *testing.T) {{"another subcommand", `'/opt/beacon/beacon-hooks' --platform cursor --log /tmp/r.jsonl pre-tool`, "post-tool", false},{"another platform", `'/opt/beacon/beacon-hooks' --platform claude --log /tmp/r.jsonl prompt-submit`, "prompt-submit", false},// Recognised for repair as an any-platform hook, but it is not a Cursor entry Beacon wrote.- {"no platform named", `/opt/beacon/hooks/beacon-hooks --log /tmp/r.jsonl stop`, "stop", false},+ {"settings, no platform named", `/opt/beacon/hooks/beacon-hooks --log /tmp/r.jsonl stop`, "stop", false},{"someone else's binary", `/usr/local/bin/audit --platform cursor --log /tmp/r.jsonl prompt-submit`, "prompt-submit", false},{"wrapper without endpoint settings", `/opt/my-wrapper/beacon-hooks --platform cursor stop`, "stop", false},{"binary name only in a directory with a space", `'/Users/dev/beacon-hooks backup/audit' --platform cursor --log /tmp/r.jsonl stop`, "stop", false},