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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ Non‑blocking observations:

| Command | Output |
|---------|--------|
| `witr <target> --json` | The full report: `Target`, `Process`, `Ancestry`, `Source`, `Warnings` and the rest |
| `witr <target> --json` | The full report: `Target`, `Process`, `Ancestry`, `Source`, `Warnings` and the rest. Environment variables are left out: use `--env --json` |
| `--short --json` | A list of `{PID, Command}` from the top of the chain to the process, with `PPID` and `ParentExited` where the process that started it has exited |
| `--tree --json` | `{Ancestry, Children}`, each a list of the same entries |
| `--warnings --json` | `{PID, Process, Command, Warnings}` |
Expand Down
3 changes: 0 additions & 3 deletions internal/app/testdata/json_contract.golden
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ Ancestry[].Container string
Ancestry[].ContainerHealthcheck string
Ancestry[].ContainerID string
Ancestry[].ContainerRuntime string
Ancestry[].Env[] string
Ancestry[].Exe string
Ancestry[].ExeDeleted bool
Ancestry[].FDCount number
Expand Down Expand Up @@ -60,7 +59,6 @@ Children[].Container string
Children[].ContainerHealthcheck string
Children[].ContainerID string
Children[].ContainerRuntime string
Children[].Env[] string
Children[].Exe string
Children[].ExeDeleted bool
Children[].FDCount number
Expand Down Expand Up @@ -134,7 +132,6 @@ Process.Container string
Process.ContainerHealthcheck string
Process.ContainerID string
Process.ContainerRuntime string
Process.Env[] string
Process.Exe string
Process.ExeDeleted bool
Process.FDCount number
Expand Down
14 changes: 14 additions & 0 deletions internal/output/json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,20 @@ func TestToJSONIsValidAndIncludesKeyFields(t *testing.T) {
}
}

// TestToJSONOmitsEnv keeps environment variables, which often hold secrets,
// out of the full report: only --env --json prints them.
func TestToJSONOmitsEnv(t *testing.T) {
t.Parallel()

s, err := ToJSON(jsonFixture())
if err != nil {
t.Fatalf("ToJSON returned error: %v", err)
}
if strings.Contains(s, `"Env"`) || strings.Contains(s, "FOO=bar") {
t.Errorf("ToJSON should not include environment variables; got:\n%s", s)
}
}

func TestToShortJSON(t *testing.T) {
t.Parallel()

Expand Down
6 changes: 4 additions & 2 deletions pkg/model/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ type Process struct {
// top of a chain, its parent PID now names nothing or a newer process.
ParentExited bool `json:",omitempty"`

// Environment variables (key=value)
Env []string
// Environment variables (key=value). Kept out of the full --json report,
// which would otherwise print the environment of every process in the
// chain; --env --json prints the target's own through ToEnvJSON.
Env []string `json:"-"`

// True if the executable was deleted after the process started
ExeDeleted bool
Expand Down
2 changes: 1 addition & 1 deletion plugins/witr/skills/witr/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ With several targets, the most severe result wins.

Then the JSON (the full contract is in the README, section "7.3 JSON Output"):

- **Found:** `Process` (`PID`, `Command`, `Cmdline`, `User`, `StartedAt`, `WorkingDir`, `Sockets`, ...), `Ancestry` (the chain from the top down to the process), `Source` (`Type`: `systemd`, `launchd`, `bsdrc`, `container`, `shell`, `ssh`, `cron`, `supervisor`, `windows_service`, `init` or `unknown`; `Name`; `Description`), `Warnings`, and `Container` when it runs in one.
- **Found:** `Process` (`PID`, `Command`, `Cmdline`, `User`, `StartedAt`, `WorkingDir`, `Sockets`, ...), `Ancestry` (the chain from the top down to the process), `Source` (`Type`: `systemd`, `launchd`, `bsdrc`, `container`, `shell`, `ssh`, `cron`, `supervisor`, `windows_service`, `init` or `unknown`; `Name`; `Description`), `Warnings`, and `Container` when it runs in one. Environment variables aren't included: only `--env --json` prints them, and they often hold secrets.
- **Failed lookup:** `{Target, Error}`, plus `Matches` when the target was ambiguous.
- **`--short --json`:** a list of `{PID, Command}`. Where the process that started one has exited, that entry also has `PPID` and `ParentExited: true`.
- **A container whose processes aren't visible** (Docker Desktop, a VM): `{ContainerName, Image, Ports, ..., Note}`.
Expand Down
Loading