Commit b954f51
feat: add key/value allowlisting to OperationContext (#181)
## Summary
- Adds key/value allowlisting to `OperationContext.__post_init__` so
that only known keys (`app`, `skill`, `agent`) and their respective
allowlisted values are accepted
- Prevents PII from entering the User-Agent header even from standalone
callers outside the plugin (e.g., `--context "ssn=123-45-6789"` is now
rejected at the SDK layer)
## What's validated
| Key | Validation | Example valid | Example rejected |
|---|---|---|---|
| `app` | Must match `<name>/<version>` format |
`dataverse-skills/1.5.0` | `noslash` |
| `skill` | Must be one of 7 known skills | `dv-data` | `not-a-skill` |
| `agent` | Must be one of 5 known agents | `claude-code` |
`not-an-agent` |
| Unknown keys | Rejected outright | — | `ssn=123-45-6789` |
## Changes
| File | Change |
|---|---|
| `src/.../core/config.py` | Added `_ALLOWED_KEYS`, `_ALLOWED_SKILLS`,
`_ALLOWED_AGENTS`, `_APP_PATTERN`; key/value validation loop in
`__post_init__` |
| `tests/unit/test_operation_context.py` | 6 new tests: unknown key,
unknown skill, unknown agent, PII in valid format, invalid app format |
## Test plan
- [x] `pytest tests/unit/test_operation_context.py -v` — 25 passed
- [x] `pytest tests/unit/ -v` — 1394 passed, 0 regressions
- [x] `black src tests --check` — clean
🤖 Generated with [Claude Code](https://claude.com/claude-code)
---------
Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>1 parent 91ada39 commit b954f51
2 files changed
Lines changed: 65 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
23 | 23 | | |
24 | 24 | | |
25 | 25 | | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
26 | 53 | | |
27 | 54 | | |
28 | 55 | | |
29 | 56 | | |
30 | 57 | | |
31 | 58 | | |
32 | | - | |
33 | | - | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
34 | 62 | | |
35 | 63 | | |
36 | 64 | | |
37 | 65 | | |
38 | | - | |
39 | | - | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
40 | 69 | | |
41 | 70 | | |
42 | 71 | | |
| |||
54 | 83 | | |
55 | 84 | | |
56 | 85 | | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
57 | 97 | | |
58 | 98 | | |
59 | 99 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
53 | 53 | | |
54 | 54 | | |
55 | 55 | | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
56 | 77 | | |
57 | 78 | | |
58 | 79 | | |
| |||
0 commit comments