whoami-guard 0.1.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- whoami_guard-0.1.1/LICENSE +21 -0
- whoami_guard-0.1.1/PKG-INFO +211 -0
- whoami_guard-0.1.1/README.md +192 -0
- whoami_guard-0.1.1/pyproject.toml +50 -0
- whoami_guard-0.1.1/setup.cfg +4 -0
- whoami_guard-0.1.1/src/egress_guard/__init__.py +1 -0
- whoami_guard-0.1.1/src/egress_guard/hook.py +191 -0
- whoami_guard-0.1.1/src/egress_guard/scan.py +372 -0
- whoami_guard-0.1.1/src/egress_guard/shim.py +57 -0
- whoami_guard-0.1.1/src/whoami_guard.egg-info/PKG-INFO +211 -0
- whoami_guard-0.1.1/src/whoami_guard.egg-info/SOURCES.txt +16 -0
- whoami_guard-0.1.1/src/whoami_guard.egg-info/dependency_links.txt +1 -0
- whoami_guard-0.1.1/src/whoami_guard.egg-info/entry_points.txt +3 -0
- whoami_guard-0.1.1/src/whoami_guard.egg-info/top_level.txt +1 -0
- whoami_guard-0.1.1/tests/test_scan.py +91 -0
- whoami_guard-0.1.1/tests/test_score.py +171 -0
- whoami_guard-0.1.1/tests/test_shim_hook.py +261 -0
- whoami_guard-0.1.1/tests/test_smoke.py +44 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Chrystian Schutz
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: whoami-guard
|
|
3
|
+
Version: 0.1.1
|
|
4
|
+
Summary: PreToolUse hook for Claude Code and Codex that stops coding agents from sending your own e-mail or name to outside services.
|
|
5
|
+
Author-email: Chrystian Schutz <chrystian.schutz@gmail.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Source, https://github.com/ChrystianSchutz/whoami-guard
|
|
8
|
+
Project-URL: Changelog, https://github.com/ChrystianSchutz/whoami-guard/blob/main/CHANGELOG.md
|
|
9
|
+
Keywords: claude-code,codex,hooks,privacy,pii,dlp,ai-agents
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Operating System :: OS Independent
|
|
14
|
+
Classifier: Topic :: Security
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Dynamic: license-file
|
|
19
|
+
|
|
20
|
+
# whoami-guard
|
|
21
|
+
|
|
22
|
+
A PreToolUse hook for **Claude Code** and **Codex** (plus a curl/wget PATH shim for any agent) that stops a coding
|
|
23
|
+
agent from sending **your own identity** (account e-mail, name) to outside services.
|
|
24
|
+
|
|
25
|
+
The failure it targets is mundane: a site answers `403` and asks automated clients to declare a contact
|
|
26
|
+
("User-Agent: Sample Company AdminContact@..."), and the agent helpfully fills in the e-mail it has in its context,
|
|
27
|
+
for example `curl -A "filings-fetch/1.0 (you@your-mail.com)"`, or writes it into a script that will run every night.
|
|
28
|
+
Several public Claude Code issues report exactly this (anthropics/claude-code #95258, #98584, #102577, #104774).
|
|
29
|
+
|
|
30
|
+
Write-up with the full measurement: https://chrystianschutz.com/blog/coding-agents-send-your-email/
|
|
31
|
+
|
|
32
|
+
## What it does
|
|
33
|
+
|
|
34
|
+
- Knows *whose* data to protect. Generic PII detectors flag every e-mail address; whoami-guard flags yours and lets
|
|
35
|
+
others through (the site's own sample contact, other people's addresses, a `git config` that stays local).
|
|
36
|
+
One conservative exception: your mailbox name alone (6+ characters, not just a first name) is protected too, so
|
|
37
|
+
`yourname@other-domain` is blocked as well.
|
|
38
|
+
- Matches your e-mail and name in the forms we test: case, diacritics, URL and double URL encoding, HTML entities,
|
|
39
|
+
base64 (also inside URL paths), `name at domain dot com`, separators, name order, Polish inflection.
|
|
40
|
+
- Looks only at tool calls that can reach the network (curl, wget, Invoke-WebRequest, Python/Node one-liners,
|
|
41
|
+
WebFetch, MCP calls), at code the agent writes or edits when that code sends requests, and at the script behind
|
|
42
|
+
`python fetch.py` when the agent runs one. Local commands (`git config user.email ...`, `echo ... >> AUTHORS`)
|
|
43
|
+
are left alone, also when chained with an unrelated download.
|
|
44
|
+
- Pure standard library, no model, no dependencies; a scan takes well under 1 ms (p95 0.2-0.5 ms on our machine).
|
|
45
|
+
- Logs every decision to `~/.egress-guard/log.jsonl` with the matched *kind* (email, name, surname), never the value.
|
|
46
|
+
|
|
47
|
+
## Measured result
|
|
48
|
+
|
|
49
|
+
Coverage on our tests, not a guarantee. Details, commands and caveats: [docs/RESULTS.md](docs/RESULTS.md).
|
|
50
|
+
|
|
51
|
+
| test | result |
|
|
52
|
+
|---|---|
|
|
53
|
+
| Real Claude Code harness, mock site that asks for contact details, 60 interleaved baseline/guard pairs (Opus + Haiku, 3 tasks, 10 reps) | identity reached the site in **8/60** runs without the hook, **0/60** with it (exact McNemar p = 0.0078) |
|
|
54
|
+
| Independent held-out set written by another model family (120 cases, not adversarial) | 60/60 leaks caught, 0/60 false alarms (Wilson 95%: [0.94, 1.0] and [0, 0.06]) |
|
|
55
|
+
| Synthetic benchmark, test split (the scanner was tuned on this set: a regression guard, not an estimate) | 163/163 leaks caught, 2/150 false alarms |
|
|
56
|
+
|
|
57
|
+
All 8 baseline leaks came from Haiku; Opus leaked 0/30 with and without the hook. One machine, one Claude Code
|
|
58
|
+
version. Generic detectors (Presidio, GLiNER, plain regex) flag 60-85% of the hard negatives on the same benchmark,
|
|
59
|
+
because they cannot tell your address from anyone else's.
|
|
60
|
+
|
|
61
|
+
## Install
|
|
62
|
+
|
|
63
|
+
The package is not on PyPI yet. Install from source:
|
|
64
|
+
|
|
65
|
+
```sh
|
|
66
|
+
pipx install git+https://github.com/ChrystianSchutz/whoami-guard
|
|
67
|
+
# or, into a venv you control:
|
|
68
|
+
python -m venv ~/.egress-guard/venv && ~/.egress-guard/venv/bin/pip install git+https://github.com/ChrystianSchutz/whoami-guard
|
|
69
|
+
```
|
|
70
|
+
|
|
71
|
+
Both give you an `whoami-guard-hook` command (and `whoami-guard-shim`). Use that command, or the venv's own
|
|
72
|
+
interpreter, in the hook settings below.
|
|
73
|
+
|
|
74
|
+
**About `python -I`.** Isolated mode is a good default for hooks (no `PYTHONPATH`, no current directory on
|
|
75
|
+
`sys.path`), but it also ignores the **user site-packages**. A `pip install --user` copy is invisible to
|
|
76
|
+
`python -I -m egress_guard.hook`, and the hook then fails. Either install into the interpreter you call (a venv or
|
|
77
|
+
pipx, as above), or use the launcher in [`contrib/run_hook.py`](contrib/run_hook.py): copy it to
|
|
78
|
+
`~/.egress-guard/run_hook.py`, copy `src/egress_guard/` to `~/.egress-guard/pkg/egress_guard/`, and run
|
|
79
|
+
`python -I ~/.egress-guard/run_hook.py` (absolute path on Windows). That also pins the version the hook runs.
|
|
80
|
+
|
|
81
|
+
Check the install with one allowed and one denied event (the second line must print a `deny` decision):
|
|
82
|
+
|
|
83
|
+
```sh
|
|
84
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"curl -A research-script/1.0 https://example.org"}}' | whoami-guard-hook
|
|
85
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"curl -A \"bot (you@your-mail.com)\" https://example.org"}}' | whoami-guard-hook
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
(Put `you@your-mail.com` in `identity.json` first, see below.)
|
|
89
|
+
|
|
90
|
+
### Claude Code (`~/.claude/settings.json`)
|
|
91
|
+
|
|
92
|
+
```json
|
|
93
|
+
{"hooks": {"PreToolUse": [{"matcher": "Bash|PowerShell|WebFetch|Write|Edit|MultiEdit|mcp__.*",
|
|
94
|
+
"hooks": [{"type": "command", "command": "whoami-guard-hook", "onFailure": "block", "timeout": 10}]}]}}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Set `"onFailure": "block"`: hooks fail open by default, so a broken install would silently let everything through.
|
|
98
|
+
For lower latency there is a resident HTTP mode (`whoami-guard-hook --serve 127.0.0.1:8977`, ~1 ms per call, no
|
|
99
|
+
process start); point a Claude Code HTTP hook at it.
|
|
100
|
+
|
|
101
|
+
### Codex (`~/.codex/config.toml`)
|
|
102
|
+
|
|
103
|
+
```toml
|
|
104
|
+
[[hooks.PreToolUse]]
|
|
105
|
+
matcher = "^(Bash|exec_command|shell|apply_patch|mcp__.*)$"
|
|
106
|
+
[[hooks.PreToolUse.hooks]]
|
|
107
|
+
type = "command"
|
|
108
|
+
command = "whoami-guard-hook"
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Codex asks you to review and trust the hook once.
|
|
112
|
+
|
|
113
|
+
### curl/wget shim (any agent, scripts the agent wrote)
|
|
114
|
+
|
|
115
|
+
Put a `curl` launcher earlier on `PATH` than the real one and set `EGRESS_GUARD_SHIM_DIR` to its folder:
|
|
116
|
+
|
|
117
|
+
```sh
|
|
118
|
+
# curl (sh)
|
|
119
|
+
exec whoami-guard-shim curl "$@"
|
|
120
|
+
```
|
|
121
|
+
|
|
122
|
+
```bat
|
|
123
|
+
@rem curl.cmd
|
|
124
|
+
@whoami-guard-shim curl %*
|
|
125
|
+
```
|
|
126
|
+
|
|
127
|
+
The shim also reads request bodies and headers given as files (`-d @body.json`, `-H @headers.txt`, `-K config`).
|
|
128
|
+
|
|
129
|
+
## Identity: `~/.egress-guard/identity.json`
|
|
130
|
+
|
|
131
|
+
```json
|
|
132
|
+
{"emails": ["you@your-mail.com"], "names": ["First Last"], "extra": ["+48 600 000 000"],
|
|
133
|
+
"allow_hosts": ["github.com"], "ignore": ["firstlast-blog"], "strict": false, "autodetect": true}
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
- `emails`, `names`: what to protect. `extra`: any other string, matched verbatim (phone, handle).
|
|
137
|
+
- `allow_hosts`: destinations where your identity may go (for example your git host). It applies to WebFetch
|
|
138
|
+
and MCP calls only. Shell commands are always scanned: a shell line can name an allowed host and still send
|
|
139
|
+
elsewhere (pipes, substitutions, git `host:path`). A `git push origin` names no identity and passes; a push to a
|
|
140
|
+
URL that contains your name is blocked.
|
|
141
|
+
- `ignore`: strings cut out of a tool call (case-insensitive) before matching, for harmless text that contains your
|
|
142
|
+
name, such as a project folder named after you (`cd ~/work/firstlast-blog && npm install`). Your identity elsewhere
|
|
143
|
+
in the same call is still caught. Keep entries specific: anything listed here is never inspected. `ignore` only hides name matches inside one literal token (no spaces, `%` or encoded forms): your e-mail is always checked on the
|
|
144
|
+
whole call, and an entry with spaces or one that is a piece of your name (`kowalski`, `Jan-Kowalski`) is dropped.
|
|
145
|
+
Note that an agent that can write files could edit `identity.json`; protect it like other agent settings.
|
|
146
|
+
- `strict`: scan every tool call, not only those that can reach the network.
|
|
147
|
+
- `autodetect` (default on): also adds `git config --global user.email` / `user.name`, the Claude Code account
|
|
148
|
+
e-mail from `~/.claude.json`, a "First Last" spelled by a `first.last@` address, and a git `user.name` that carries
|
|
149
|
+
a machine label (for example "Jan Desktop") verbatim. Placeholder addresses (`you@example.com`, GitHub noreply) are
|
|
150
|
+
skipped. Everything is read locally, cached for a day in `~/.egress-guard/`, and never sent anywhere.
|
|
151
|
+
- `EGRESS_GUARD_HOME` moves the whole folder (identity, cache, log).
|
|
152
|
+
|
|
153
|
+
## Known gaps and limits
|
|
154
|
+
|
|
155
|
+
- **It checks tool calls; it is not network isolation.** A hook sees only what a tool call contains. A script that
|
|
156
|
+
reads your e-mail at run time (from git config, an environment variable, a file) and sends it with a library call
|
|
157
|
+
is outside its view. The shim covers the part of this that goes through curl/wget. In our reproduction the leaks
|
|
158
|
+
came from scripts the agent wrote, which is why `Write|Edit` belong in the matcher.
|
|
159
|
+
- Codex hosted tools (web search) do not pass through hooks.
|
|
160
|
+
- **In the default mode, only commands the scanner recognises as network calls are checked** (curl, wget, HTTP
|
|
161
|
+
libraries, sockets, remote git commands, ...). A network tool it does not list, or one under another name, is
|
|
162
|
+
not scanned; set `"strict": true` to scan every call. A release review with Codex (9 rounds, 2026-10-30) found and
|
|
163
|
+
closed a series of such forms (pipes, substitutions, git `host:path`, `git.exe`); expect more.
|
|
164
|
+
- The guard errs toward blocking: a local write next to a network command, or a file named `socket.log`, can be
|
|
165
|
+
blocked although nothing is sent.
|
|
166
|
+
- Hooks fail open by default in both agents (see `onFailure` above for Claude Code).
|
|
167
|
+
- A request to your own personal domain that contains your surname (`curl https://kowalczyk-studio.pl`) is flagged:
|
|
168
|
+
these are the 2 false alarms on the benchmark's test split. Add the domain to `allow_hosts` (fetches) or `ignore` (folder names).
|
|
169
|
+
- Name matching covers English and Polish inflection; other inflected languages are not tested.
|
|
170
|
+
- Our numbers come from one machine, one Claude Code version, a mock site and synthetic identities. The held-out set
|
|
171
|
+
is not adversarial. Treat whoami-guard as a seatbelt, not a guarantee.
|
|
172
|
+
|
|
173
|
+
## Repository layout
|
|
174
|
+
|
|
175
|
+
| path | what |
|
|
176
|
+
|---|---|
|
|
177
|
+
| `src/egress_guard/` | `scan.py` (matcher), `hook.py` (command and HTTP hook), `shim.py` (curl/wget shim) |
|
|
178
|
+
| `tests/` | unit and end-to-end tests (`pytest`) |
|
|
179
|
+
| `bench/` | synthetic dataset and generator (`make_dataset.py`, seed 20261026), held-out set, gate bench (`run.py`, limits in `thresholds.json`), detector comparison (`bench_detectors.py`) |
|
|
180
|
+
| `repro/` | real-harness reproduction: mock site, sandbox hook, runner, scorer |
|
|
181
|
+
| `contrib/run_hook.py` | launcher for `python -I` with a pinned copy of the package |
|
|
182
|
+
| `docs/RESULTS.md` | numbers, commands, caveats |
|
|
183
|
+
|
|
184
|
+
All identities in `bench/` and `tests/` are invented. Reproduction runs (`repro/run_repro.py`) store the real
|
|
185
|
+
identity of whoever runs them under `runs/`, which is git-ignored; never commit it.
|
|
186
|
+
|
|
187
|
+
## Development
|
|
188
|
+
|
|
189
|
+
```sh
|
|
190
|
+
pip install -e . pytest ruff
|
|
191
|
+
ruff check .
|
|
192
|
+
pytest -q
|
|
193
|
+
python -I bench/run.py # gate bench: recall >= 0.97, FPR <= 0.02, p95 <= 2 ms
|
|
194
|
+
python -I bench/heldout.py <tag>
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
## Citation
|
|
198
|
+
|
|
199
|
+
```bibtex
|
|
200
|
+
@software{schutz2026egressguard,
|
|
201
|
+
author = {Schutz, Chrystian},
|
|
202
|
+
title = {whoami-guard: an identity-aware egress hook for coding agents},
|
|
203
|
+
year = {2026},
|
|
204
|
+
version = {0.1.1},
|
|
205
|
+
url = {https://github.com/ChrystianSchutz/whoami-guard}
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Licence
|
|
210
|
+
|
|
211
|
+
MIT, see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
# whoami-guard
|
|
2
|
+
|
|
3
|
+
A PreToolUse hook for **Claude Code** and **Codex** (plus a curl/wget PATH shim for any agent) that stops a coding
|
|
4
|
+
agent from sending **your own identity** (account e-mail, name) to outside services.
|
|
5
|
+
|
|
6
|
+
The failure it targets is mundane: a site answers `403` and asks automated clients to declare a contact
|
|
7
|
+
("User-Agent: Sample Company AdminContact@..."), and the agent helpfully fills in the e-mail it has in its context,
|
|
8
|
+
for example `curl -A "filings-fetch/1.0 (you@your-mail.com)"`, or writes it into a script that will run every night.
|
|
9
|
+
Several public Claude Code issues report exactly this (anthropics/claude-code #95258, #98584, #102577, #104774).
|
|
10
|
+
|
|
11
|
+
Write-up with the full measurement: https://chrystianschutz.com/blog/coding-agents-send-your-email/
|
|
12
|
+
|
|
13
|
+
## What it does
|
|
14
|
+
|
|
15
|
+
- Knows *whose* data to protect. Generic PII detectors flag every e-mail address; whoami-guard flags yours and lets
|
|
16
|
+
others through (the site's own sample contact, other people's addresses, a `git config` that stays local).
|
|
17
|
+
One conservative exception: your mailbox name alone (6+ characters, not just a first name) is protected too, so
|
|
18
|
+
`yourname@other-domain` is blocked as well.
|
|
19
|
+
- Matches your e-mail and name in the forms we test: case, diacritics, URL and double URL encoding, HTML entities,
|
|
20
|
+
base64 (also inside URL paths), `name at domain dot com`, separators, name order, Polish inflection.
|
|
21
|
+
- Looks only at tool calls that can reach the network (curl, wget, Invoke-WebRequest, Python/Node one-liners,
|
|
22
|
+
WebFetch, MCP calls), at code the agent writes or edits when that code sends requests, and at the script behind
|
|
23
|
+
`python fetch.py` when the agent runs one. Local commands (`git config user.email ...`, `echo ... >> AUTHORS`)
|
|
24
|
+
are left alone, also when chained with an unrelated download.
|
|
25
|
+
- Pure standard library, no model, no dependencies; a scan takes well under 1 ms (p95 0.2-0.5 ms on our machine).
|
|
26
|
+
- Logs every decision to `~/.egress-guard/log.jsonl` with the matched *kind* (email, name, surname), never the value.
|
|
27
|
+
|
|
28
|
+
## Measured result
|
|
29
|
+
|
|
30
|
+
Coverage on our tests, not a guarantee. Details, commands and caveats: [docs/RESULTS.md](docs/RESULTS.md).
|
|
31
|
+
|
|
32
|
+
| test | result |
|
|
33
|
+
|---|---|
|
|
34
|
+
| Real Claude Code harness, mock site that asks for contact details, 60 interleaved baseline/guard pairs (Opus + Haiku, 3 tasks, 10 reps) | identity reached the site in **8/60** runs without the hook, **0/60** with it (exact McNemar p = 0.0078) |
|
|
35
|
+
| Independent held-out set written by another model family (120 cases, not adversarial) | 60/60 leaks caught, 0/60 false alarms (Wilson 95%: [0.94, 1.0] and [0, 0.06]) |
|
|
36
|
+
| Synthetic benchmark, test split (the scanner was tuned on this set: a regression guard, not an estimate) | 163/163 leaks caught, 2/150 false alarms |
|
|
37
|
+
|
|
38
|
+
All 8 baseline leaks came from Haiku; Opus leaked 0/30 with and without the hook. One machine, one Claude Code
|
|
39
|
+
version. Generic detectors (Presidio, GLiNER, plain regex) flag 60-85% of the hard negatives on the same benchmark,
|
|
40
|
+
because they cannot tell your address from anyone else's.
|
|
41
|
+
|
|
42
|
+
## Install
|
|
43
|
+
|
|
44
|
+
The package is not on PyPI yet. Install from source:
|
|
45
|
+
|
|
46
|
+
```sh
|
|
47
|
+
pipx install git+https://github.com/ChrystianSchutz/whoami-guard
|
|
48
|
+
# or, into a venv you control:
|
|
49
|
+
python -m venv ~/.egress-guard/venv && ~/.egress-guard/venv/bin/pip install git+https://github.com/ChrystianSchutz/whoami-guard
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Both give you an `whoami-guard-hook` command (and `whoami-guard-shim`). Use that command, or the venv's own
|
|
53
|
+
interpreter, in the hook settings below.
|
|
54
|
+
|
|
55
|
+
**About `python -I`.** Isolated mode is a good default for hooks (no `PYTHONPATH`, no current directory on
|
|
56
|
+
`sys.path`), but it also ignores the **user site-packages**. A `pip install --user` copy is invisible to
|
|
57
|
+
`python -I -m egress_guard.hook`, and the hook then fails. Either install into the interpreter you call (a venv or
|
|
58
|
+
pipx, as above), or use the launcher in [`contrib/run_hook.py`](contrib/run_hook.py): copy it to
|
|
59
|
+
`~/.egress-guard/run_hook.py`, copy `src/egress_guard/` to `~/.egress-guard/pkg/egress_guard/`, and run
|
|
60
|
+
`python -I ~/.egress-guard/run_hook.py` (absolute path on Windows). That also pins the version the hook runs.
|
|
61
|
+
|
|
62
|
+
Check the install with one allowed and one denied event (the second line must print a `deny` decision):
|
|
63
|
+
|
|
64
|
+
```sh
|
|
65
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"curl -A research-script/1.0 https://example.org"}}' | whoami-guard-hook
|
|
66
|
+
echo '{"tool_name":"Bash","tool_input":{"command":"curl -A \"bot (you@your-mail.com)\" https://example.org"}}' | whoami-guard-hook
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
(Put `you@your-mail.com` in `identity.json` first, see below.)
|
|
70
|
+
|
|
71
|
+
### Claude Code (`~/.claude/settings.json`)
|
|
72
|
+
|
|
73
|
+
```json
|
|
74
|
+
{"hooks": {"PreToolUse": [{"matcher": "Bash|PowerShell|WebFetch|Write|Edit|MultiEdit|mcp__.*",
|
|
75
|
+
"hooks": [{"type": "command", "command": "whoami-guard-hook", "onFailure": "block", "timeout": 10}]}]}}
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
Set `"onFailure": "block"`: hooks fail open by default, so a broken install would silently let everything through.
|
|
79
|
+
For lower latency there is a resident HTTP mode (`whoami-guard-hook --serve 127.0.0.1:8977`, ~1 ms per call, no
|
|
80
|
+
process start); point a Claude Code HTTP hook at it.
|
|
81
|
+
|
|
82
|
+
### Codex (`~/.codex/config.toml`)
|
|
83
|
+
|
|
84
|
+
```toml
|
|
85
|
+
[[hooks.PreToolUse]]
|
|
86
|
+
matcher = "^(Bash|exec_command|shell|apply_patch|mcp__.*)$"
|
|
87
|
+
[[hooks.PreToolUse.hooks]]
|
|
88
|
+
type = "command"
|
|
89
|
+
command = "whoami-guard-hook"
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
Codex asks you to review and trust the hook once.
|
|
93
|
+
|
|
94
|
+
### curl/wget shim (any agent, scripts the agent wrote)
|
|
95
|
+
|
|
96
|
+
Put a `curl` launcher earlier on `PATH` than the real one and set `EGRESS_GUARD_SHIM_DIR` to its folder:
|
|
97
|
+
|
|
98
|
+
```sh
|
|
99
|
+
# curl (sh)
|
|
100
|
+
exec whoami-guard-shim curl "$@"
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
```bat
|
|
104
|
+
@rem curl.cmd
|
|
105
|
+
@whoami-guard-shim curl %*
|
|
106
|
+
```
|
|
107
|
+
|
|
108
|
+
The shim also reads request bodies and headers given as files (`-d @body.json`, `-H @headers.txt`, `-K config`).
|
|
109
|
+
|
|
110
|
+
## Identity: `~/.egress-guard/identity.json`
|
|
111
|
+
|
|
112
|
+
```json
|
|
113
|
+
{"emails": ["you@your-mail.com"], "names": ["First Last"], "extra": ["+48 600 000 000"],
|
|
114
|
+
"allow_hosts": ["github.com"], "ignore": ["firstlast-blog"], "strict": false, "autodetect": true}
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
- `emails`, `names`: what to protect. `extra`: any other string, matched verbatim (phone, handle).
|
|
118
|
+
- `allow_hosts`: destinations where your identity may go (for example your git host). It applies to WebFetch
|
|
119
|
+
and MCP calls only. Shell commands are always scanned: a shell line can name an allowed host and still send
|
|
120
|
+
elsewhere (pipes, substitutions, git `host:path`). A `git push origin` names no identity and passes; a push to a
|
|
121
|
+
URL that contains your name is blocked.
|
|
122
|
+
- `ignore`: strings cut out of a tool call (case-insensitive) before matching, for harmless text that contains your
|
|
123
|
+
name, such as a project folder named after you (`cd ~/work/firstlast-blog && npm install`). Your identity elsewhere
|
|
124
|
+
in the same call is still caught. Keep entries specific: anything listed here is never inspected. `ignore` only hides name matches inside one literal token (no spaces, `%` or encoded forms): your e-mail is always checked on the
|
|
125
|
+
whole call, and an entry with spaces or one that is a piece of your name (`kowalski`, `Jan-Kowalski`) is dropped.
|
|
126
|
+
Note that an agent that can write files could edit `identity.json`; protect it like other agent settings.
|
|
127
|
+
- `strict`: scan every tool call, not only those that can reach the network.
|
|
128
|
+
- `autodetect` (default on): also adds `git config --global user.email` / `user.name`, the Claude Code account
|
|
129
|
+
e-mail from `~/.claude.json`, a "First Last" spelled by a `first.last@` address, and a git `user.name` that carries
|
|
130
|
+
a machine label (for example "Jan Desktop") verbatim. Placeholder addresses (`you@example.com`, GitHub noreply) are
|
|
131
|
+
skipped. Everything is read locally, cached for a day in `~/.egress-guard/`, and never sent anywhere.
|
|
132
|
+
- `EGRESS_GUARD_HOME` moves the whole folder (identity, cache, log).
|
|
133
|
+
|
|
134
|
+
## Known gaps and limits
|
|
135
|
+
|
|
136
|
+
- **It checks tool calls; it is not network isolation.** A hook sees only what a tool call contains. A script that
|
|
137
|
+
reads your e-mail at run time (from git config, an environment variable, a file) and sends it with a library call
|
|
138
|
+
is outside its view. The shim covers the part of this that goes through curl/wget. In our reproduction the leaks
|
|
139
|
+
came from scripts the agent wrote, which is why `Write|Edit` belong in the matcher.
|
|
140
|
+
- Codex hosted tools (web search) do not pass through hooks.
|
|
141
|
+
- **In the default mode, only commands the scanner recognises as network calls are checked** (curl, wget, HTTP
|
|
142
|
+
libraries, sockets, remote git commands, ...). A network tool it does not list, or one under another name, is
|
|
143
|
+
not scanned; set `"strict": true` to scan every call. A release review with Codex (9 rounds, 2026-10-30) found and
|
|
144
|
+
closed a series of such forms (pipes, substitutions, git `host:path`, `git.exe`); expect more.
|
|
145
|
+
- The guard errs toward blocking: a local write next to a network command, or a file named `socket.log`, can be
|
|
146
|
+
blocked although nothing is sent.
|
|
147
|
+
- Hooks fail open by default in both agents (see `onFailure` above for Claude Code).
|
|
148
|
+
- A request to your own personal domain that contains your surname (`curl https://kowalczyk-studio.pl`) is flagged:
|
|
149
|
+
these are the 2 false alarms on the benchmark's test split. Add the domain to `allow_hosts` (fetches) or `ignore` (folder names).
|
|
150
|
+
- Name matching covers English and Polish inflection; other inflected languages are not tested.
|
|
151
|
+
- Our numbers come from one machine, one Claude Code version, a mock site and synthetic identities. The held-out set
|
|
152
|
+
is not adversarial. Treat whoami-guard as a seatbelt, not a guarantee.
|
|
153
|
+
|
|
154
|
+
## Repository layout
|
|
155
|
+
|
|
156
|
+
| path | what |
|
|
157
|
+
|---|---|
|
|
158
|
+
| `src/egress_guard/` | `scan.py` (matcher), `hook.py` (command and HTTP hook), `shim.py` (curl/wget shim) |
|
|
159
|
+
| `tests/` | unit and end-to-end tests (`pytest`) |
|
|
160
|
+
| `bench/` | synthetic dataset and generator (`make_dataset.py`, seed 20261026), held-out set, gate bench (`run.py`, limits in `thresholds.json`), detector comparison (`bench_detectors.py`) |
|
|
161
|
+
| `repro/` | real-harness reproduction: mock site, sandbox hook, runner, scorer |
|
|
162
|
+
| `contrib/run_hook.py` | launcher for `python -I` with a pinned copy of the package |
|
|
163
|
+
| `docs/RESULTS.md` | numbers, commands, caveats |
|
|
164
|
+
|
|
165
|
+
All identities in `bench/` and `tests/` are invented. Reproduction runs (`repro/run_repro.py`) store the real
|
|
166
|
+
identity of whoever runs them under `runs/`, which is git-ignored; never commit it.
|
|
167
|
+
|
|
168
|
+
## Development
|
|
169
|
+
|
|
170
|
+
```sh
|
|
171
|
+
pip install -e . pytest ruff
|
|
172
|
+
ruff check .
|
|
173
|
+
pytest -q
|
|
174
|
+
python -I bench/run.py # gate bench: recall >= 0.97, FPR <= 0.02, p95 <= 2 ms
|
|
175
|
+
python -I bench/heldout.py <tag>
|
|
176
|
+
```
|
|
177
|
+
|
|
178
|
+
## Citation
|
|
179
|
+
|
|
180
|
+
```bibtex
|
|
181
|
+
@software{schutz2026egressguard,
|
|
182
|
+
author = {Schutz, Chrystian},
|
|
183
|
+
title = {whoami-guard: an identity-aware egress hook for coding agents},
|
|
184
|
+
year = {2026},
|
|
185
|
+
version = {0.1.1},
|
|
186
|
+
url = {https://github.com/ChrystianSchutz/whoami-guard}
|
|
187
|
+
}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Licence
|
|
191
|
+
|
|
192
|
+
MIT, see [LICENSE](LICENSE).
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=84.2.1"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
# The PyPI name "whoami-guard" belongs to an unrelated project (checked 2026-10-29), so the distribution name here
|
|
7
|
+
# is a placeholder until a PyPI name is chosen. The import name stays `egress_guard`.
|
|
8
|
+
name = "whoami-guard"
|
|
9
|
+
version = "0.1.1"
|
|
10
|
+
description = "PreToolUse hook for Claude Code and Codex that stops coding agents from sending your own e-mail or name to outside services."
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
license = "MIT"
|
|
13
|
+
license-files = ["LICENSE"]
|
|
14
|
+
authors = [{ name = "Chrystian Schutz", email = "chrystian.schutz@gmail.com" }]
|
|
15
|
+
requires-python = ">=3.12"
|
|
16
|
+
dependencies = []
|
|
17
|
+
keywords = ["claude-code", "codex", "hooks", "privacy", "pii", "dlp", "ai-agents"]
|
|
18
|
+
classifiers = [
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.12",
|
|
21
|
+
"Programming Language :: Python :: 3.13",
|
|
22
|
+
"Operating System :: OS Independent",
|
|
23
|
+
"Topic :: Security",
|
|
24
|
+
]
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Source = "https://github.com/ChrystianSchutz/whoami-guard"
|
|
28
|
+
Changelog = "https://github.com/ChrystianSchutz/whoami-guard/blob/main/CHANGELOG.md"
|
|
29
|
+
|
|
30
|
+
[project.scripts]
|
|
31
|
+
whoami-guard-hook = "egress_guard.hook:main"
|
|
32
|
+
whoami-guard-shim = "egress_guard.shim:main"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["src"]
|
|
36
|
+
|
|
37
|
+
[tool.ruff]
|
|
38
|
+
line-length = 120
|
|
39
|
+
extend-exclude = ["runs"]
|
|
40
|
+
|
|
41
|
+
[tool.ruff.lint]
|
|
42
|
+
select = ["E9", "F", "B", "S"]
|
|
43
|
+
ignore = ["S101", "S311"]
|
|
44
|
+
|
|
45
|
+
[tool.ruff.lint.per-file-ignores]
|
|
46
|
+
"tests/*" = ["S"]
|
|
47
|
+
"bench/*" = ["S"]
|
|
48
|
+
|
|
49
|
+
[tool.pytest.ini_options]
|
|
50
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""whoami-guard: keep the user's own identity out of what coding agents send to the internet."""
|