maskerade 0.1.0__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.
Files changed (44) hide show
  1. maskerade-0.1.0/LICENSE +202 -0
  2. maskerade-0.1.0/PKG-INFO +229 -0
  3. maskerade-0.1.0/README.md +197 -0
  4. maskerade-0.1.0/maskerade/__init__.py +53 -0
  5. maskerade-0.1.0/maskerade/_extras.py +238 -0
  6. maskerade-0.1.0/maskerade/allowlist/__init__.py +274 -0
  7. maskerade-0.1.0/maskerade/allowlist/allowlist.yaml +3359 -0
  8. maskerade-0.1.0/maskerade/allowlist/allowlist_overrides.yaml +39 -0
  9. maskerade-0.1.0/maskerade/allowlist/build.py +734 -0
  10. maskerade-0.1.0/maskerade/cli.py +494 -0
  11. maskerade-0.1.0/maskerade/config.py +43 -0
  12. maskerade-0.1.0/maskerade/default_config.yaml +842 -0
  13. maskerade-0.1.0/maskerade/masker.py +610 -0
  14. maskerade-0.1.0/maskerade/pipeline.py +1040 -0
  15. maskerade-0.1.0/maskerade/proxy/__init__.py +23 -0
  16. maskerade-0.1.0/maskerade/proxy/fields.py +1276 -0
  17. maskerade-0.1.0/maskerade/proxy/note.py +96 -0
  18. maskerade-0.1.0/maskerade/proxy/rules.py +391 -0
  19. maskerade-0.1.0/maskerade/proxy/server.py +1110 -0
  20. maskerade-0.1.0/maskerade/proxy/store.py +730 -0
  21. maskerade-0.1.0/maskerade/proxy/stream.py +398 -0
  22. maskerade-0.1.0/maskerade/proxy/system_note.txt +29 -0
  23. maskerade-0.1.0/maskerade/stages/__init__.py +0 -0
  24. maskerade-0.1.0/maskerade/stages/allowlist/allowlist.yaml +3032 -0
  25. maskerade-0.1.0/maskerade/stages/allowlist/allowlist_overrides.yaml +39 -0
  26. maskerade-0.1.0/maskerade/stages/checksum.py +377 -0
  27. maskerade-0.1.0/maskerade/stages/custom.py +280 -0
  28. maskerade-0.1.0/maskerade/stages/form.py +1450 -0
  29. maskerade-0.1.0/maskerade/stages/gliner.py +755 -0
  30. maskerade-0.1.0/maskerade/stages/id.py +424 -0
  31. maskerade-0.1.0/maskerade/stages/keyval.py +1962 -0
  32. maskerade-0.1.0/maskerade/stages/org_evidence.py +906 -0
  33. maskerade-0.1.0/maskerade/stages/regex.py +379 -0
  34. maskerade-0.1.0/maskerade/validator.py +176 -0
  35. maskerade-0.1.0/maskerade/warm.py +241 -0
  36. maskerade-0.1.0/maskerade/wizard.py +976 -0
  37. maskerade-0.1.0/maskerade.egg-info/PKG-INFO +229 -0
  38. maskerade-0.1.0/maskerade.egg-info/SOURCES.txt +42 -0
  39. maskerade-0.1.0/maskerade.egg-info/dependency_links.txt +1 -0
  40. maskerade-0.1.0/maskerade.egg-info/entry_points.txt +2 -0
  41. maskerade-0.1.0/maskerade.egg-info/requires.txt +7 -0
  42. maskerade-0.1.0/maskerade.egg-info/top_level.txt +1 -0
  43. maskerade-0.1.0/pyproject.toml +214 -0
  44. maskerade-0.1.0/setup.cfg +4 -0
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,229 @@
1
+ Metadata-Version: 2.4
2
+ Name: maskerade
3
+ Version: 0.1.0
4
+ Summary: Local masking proxy that replaces client data in pentest prompts and HTTP traffic before it reaches the Anthropic API, and restores it in the reply
5
+ Author: Timotei Adamec
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://github.com/adamectimotei/maskerade-proxy
8
+ Project-URL: Source, https://github.com/adamectimotei/maskerade-proxy
9
+ Project-URL: Issues, https://github.com/adamectimotei/maskerade-proxy/issues
10
+ Keywords: pentest,penetration-testing,anonymization,pii,redaction,masking,proxy,anthropic,claude,llm
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Environment :: Console
13
+ Classifier: Intended Audience :: Information Technology
14
+ Classifier: Intended Audience :: System Administrators
15
+ Classifier: Operating System :: Microsoft :: Windows
16
+ Classifier: Operating System :: POSIX :: Linux
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Topic :: Security
22
+ Requires-Python: >=3.11
23
+ Description-Content-Type: text/markdown
24
+ License-File: LICENSE
25
+ Requires-Dist: pyyaml>=6.0
26
+ Requires-Dist: phonenumbers>=8.13
27
+ Requires-Dist: tiktoken>=0.7
28
+ Provides-Extra: ner
29
+ Requires-Dist: gliner2[local]==2.0.0; extra == "ner"
30
+ Requires-Dist: transformers[sentencepiece]<5; extra == "ner"
31
+ Dynamic: license-file
32
+
33
+ # maskerade
34
+
35
+ **A local masking proxy for the Anthropic API.** It runs on your own machine, replaces client data in your prompts and traffic with typed placeholders before anything is sent, and puts the real values back into the reply.
36
+
37
+ Built for penetration testers who use Claude (Claude Code, the SDKs, anything that speaks the Messages API) on client work and must not send client data to a third party.
38
+
39
+ ```
40
+ your client (Claude Code, SDK) maskerade, on 127.0.0.1 api.anthropic.com
41
+ ────────────────────────────── ────────────────────────── ─────────────────
42
+ "admin is jan.novak@acmebank.cz" ──▶ detect + mask ──▶ "admin is [EMAIL_ADDRESS_1]"
43
+ "reset it for jan.novak@acmebank.cz" ◀── restore real values ◀── "reset it for [EMAIL_ADDRESS_1]"
44
+ ```
45
+
46
+ > **Status: alpha (0.1.0).** It reduces what leaves your machine; it does not guarantee that nothing sensitive does. Read [What it does not do](#what-it-does-not-do) before relying on it, and keep reviewing what you send.
47
+
48
+ ---
49
+
50
+ ## How it works
51
+
52
+ - **Detects** client data with deterministic layers: your own rules (the client's names, domains and tenant slugs), around 100 regex patterns for credentials, tokens, keys, hashes, IPs, hostnames, emails and national IDs, checksum validators (IBAN, card numbers, national ID numbers), key/value structure (`"password": ...`), identifier shapes, and a randomness test for secrets nobody has a pattern for. The optional NER tier adds a local GLiNER model for names and organisations.
53
+ - **Masks** each value with a typed placeholder such as `[INTERNAL_HOSTNAME_1]`. The same value gets the same placeholder for the whole conversation, so the model can still reason about it ("`[USER_ID_1]` can read `[USER_ID_2]`'s invoices").
54
+ - **Forwards only the masked request** to `api.anthropic.com`, and appends a short note telling the model what the placeholders mean.
55
+ - **Restores** the real values in the reply, including streamed replies and tool-call arguments, so your client sees the real text.
56
+ - **Fails closed.** If a detector cannot run, or a detected value cannot be masked, the request is refused, never forwarded unmasked.
57
+
58
+ Everything runs locally on the CPU. No GPU, no model server, no account.
59
+
60
+ ## Install
61
+
62
+ Python 3.11 or newer.
63
+
64
+ ```bash
65
+ pip install maskerade
66
+ python -m maskerade.warm # one-time: fetches the 1.7 MB BPE encoder, checksum-verified
67
+ maskerade --version
68
+ ```
69
+
70
+ `warm` is required: the entropy detector needs that encoder, and without it the proxy refuses to start rather than run with a weaker detector.
71
+
72
+ ### Full tier (adds the NER model)
73
+
74
+ The `ner` extra pulls in PyTorch and the GLiNER model, a few GB in total. Install the **CPU** build of PyTorch first; otherwise pip fetches the much larger CUDA build, which this tool cannot use:
75
+
76
+ ```bash
77
+ pip install torch --index-url https://download.pytorch.org/whl/cpu
78
+ pip install "maskerade[ner]"
79
+ python -m maskerade.warm --full # one-time: encoder + model (~1.2 GB)
80
+ ```
81
+
82
+ Run it with `--tier full`. Startup takes noticeably longer while the model loads.
83
+
84
+ ### Docker
85
+
86
+ Images are published to `ghcr.io/adamectimotei/maskerade`: `0.1.0` (fast tier, ~190 MB) and `0.1.0-ner` (full tier, model included, ~2.6 GB). See [Docker](#docker) below before running one: **how you publish the port matters.**
87
+
88
+ ## Quick start with Claude Code
89
+
90
+ From the directory you'll work in for the engagement:
91
+
92
+ ```bash
93
+ maskerade init --engagement eng-2026-014
94
+ ```
95
+
96
+ `init` asks for the client's names and domains and writes them to `.maskerade/rules.txt`. It points Claude Code at the proxy through `.claude/settings.local.json`, and warns you about places the client's name already appears in clear text (the folder path, git remote, branch). It writes no credentials anywhere.
97
+
98
+ Then start the proxy **from that same directory** and use Claude Code as usual:
99
+
100
+ ```bash
101
+ maskerade proxy --engagement eng-2026-014 # fast tier (default)
102
+ maskerade proxy --engagement eng-2026-014 --tier full
103
+ ```
104
+
105
+ For any other client, point it at the proxy yourself:
106
+
107
+ ```bash
108
+ export ANTHROPIC_BASE_URL=http://127.0.0.1:8787 # bash
109
+ $env:ANTHROPIC_BASE_URL = "http://127.0.0.1:8787" # PowerShell
110
+ ```
111
+
112
+ Your API key, or your Claude subscription login, works unchanged; the proxy passes your credentials through and never stores or logs them.
113
+
114
+ ## Custom rules: the client's own identity
115
+
116
+ No detector can know your client's name in advance, so tell it. `.maskerade/rules.txt` is one value per line:
117
+
118
+ ```text
119
+ # acme bank, engagement 2026-014
120
+ acmebank.cz
121
+ Acme Bank a.s. = CLIENT_NAME
122
+ ACME-PAYROLL = CLIENT_SYSTEM
123
+ ```
124
+
125
+ - A bare line becomes `[CLIENT_1]`, `[CLIENT_2]`, ...; `value = TYPE` picks the type.
126
+ - Matching is case-insensitive and on word boundaries. A domain covers all its subdomains, so `acmebank.cz` also masks `portal.acmebank.cz`.
127
+ - An email address on a client domain is masked whole, as `[EMAIL_ADDRESS_n]`, never cut in half by a rule.
128
+ - The proxy re-reads the file when it changes. Check a file before trusting it:
129
+
130
+ ```bash
131
+ maskerade rules check .maskerade/rules.txt --against sample.txt
132
+ ```
133
+
134
+ ## Tiers
135
+
136
+ | | fast (default) | full (`--tier full`) |
137
+ |---|---|---|
138
+ | Install | `pip install maskerade` | `maskerade[ner]` + CPU PyTorch |
139
+ | Detectors | custom rules, ~100 regex patterns, entropy/format, key/value, checksums, identifier shapes | all of fast, plus GLiNER (names, organisations, locations) with an evidence gate for organisation names |
140
+ | Speed | milliseconds per message | slower; the model runs on CPU |
141
+ | Catches less of | free-text person and company names your rules don't list | very large bodies: the model skips inputs over 16 384 characters, the other detectors still run |
142
+
143
+ Recall and precision for both tiers will be published together with a re-measurement on this release. Until then, treat detection as **good but not complete**, and put everything you know about the client in your rules file.
144
+
145
+ ## Is it working?
146
+
147
+ - **Startup banner.** The proxy prints the bind address, the detector set (`mode`), where mask maps live, the engagement and which rules file it loaded. `custom rule none` means no rules file was found.
148
+ - **Every response carries headers:**
149
+ - `X-Maskerade-Mode`: the detectors that ran
150
+ - `X-Maskerade-Session`: the session, and `new` or `continued`
151
+ - `X-Maskerade-Rules`: how many of your rules are loaded
152
+ - `X-Maskerade-Unscanned`: request fields forwarded **without** inspection (see below)
153
+ - `X-Maskerade-Refused`: set when a request was refused instead of sent
154
+ - **Health check:** `curl http://127.0.0.1:8787/healthz`
155
+ - **Loopback only:** `netstat -ano | findstr 8787` (Windows) or `ss -ltnp | grep 8787` should show `127.0.0.1:8787` and nothing else.
156
+
157
+ ## Mask maps, sessions and retention
158
+
159
+ The mapping from placeholders to real values (the *mask map*) is stored per conversation, so the same value keeps the same placeholder across turns and the reply can be restored. **It is client data.** It lives in:
160
+
161
+ | OS | default location |
162
+ |---|---|
163
+ | Windows | `%LOCALAPPDATA%\maskerade` (deliberately not `Documents`, which OneDrive syncs) |
164
+ | Linux | `$XDG_STATE_HOME/maskerade`, or `~/.local/state/maskerade` |
165
+ | macOS | `~/Library/Application Support/maskerade` |
166
+
167
+ Set `MASKERADE_STATE_DIR` to put it elsewhere. The files are restricted to your user. On Linux and macOS the proxy refuses to start if it cannot do that; on Windows it prints a warning. It also warns if the location looks like a cloud-synced folder.
168
+
169
+ ```bash
170
+ maskerade sessions list # ids, labels, placeholder COUNTS; never values
171
+ maskerade sessions purge --older-than 30d
172
+ maskerade sessions purge --session eng-2026-014 # one engagement
173
+ maskerade sessions purge --all
174
+ ```
175
+
176
+ Sessions unused for 30 days are deleted when the proxy starts (`--retention-days` to change it).
177
+
178
+ ## Docker
179
+
180
+ ```bash
181
+ docker compose up -d # with docker-compose.yml from this repository
182
+ ```
183
+
184
+ The proxy refuses to listen anywhere but loopback unless given `--allow-remote`. Inside a container a loopback-only proxy is unreachable from the host, so **the image listens on all interfaces inside the container, and the port publish is what keeps it on your machine**:
185
+
186
+ ```bash
187
+ docker run -p 127.0.0.1:8787:8787 ... # correct: reachable from this machine only
188
+ docker run -p 8787:8787 ... # WRONG: anyone on your network can use it
189
+ ```
190
+
191
+ The proxy has no authentication, holds your mask maps and restores real values, so a wrong publish exposes client data to your whole network. The [compose file](https://github.com/adamectimotei/maskerade-proxy/blob/main/docker-compose.yml) gets this right and explains it. Also:
192
+
193
+ - Other containers on the **same Docker network** can reach the proxy. Don't attach it to networks shared with things you don't trust.
194
+ - Keep mask maps in a **named volume** (the compose file does). The proxy refuses a bind-mounted directory it cannot restrict to its own user.
195
+ - The first start downloads the 1.7 MB encoder into the volume. Later starts, including the NER image's, need no network beyond `api.anthropic.com`.
196
+ - The images are tested on Linux with Docker Engine. Docker Desktop on Windows and macOS is not tested yet.
197
+
198
+ ## What it does not do
199
+
200
+ Read this before you depend on it.
201
+
202
+ - **Only message content is inspected.** The system prompt, tool definitions and several other request fields are forwarded **as-is**, because masking them breaks the client. Every response names them in `X-Maskerade-Unscanned`. For Claude Code these fields include your **working directory, home directory, git remote and branch, and your account name**, so work from a neutrally named directory (`maskerade init` checks for this).
203
+ - **Images and documents are refused**, not forwarded: their bytes cannot be masked.
204
+ - **Detection is not complete.** A value no rule, pattern or model recognises goes through. The fast tier in particular misses free-text names that aren't in your rules.
205
+ - **It only proxies the Anthropic Messages API** (`/v1/messages`, `count_tokens`, `/v1/models`, and the OAuth token refresh). Any other path is refused.
206
+ - **It only covers traffic sent through it.** Your client's telemetry, update checks and other requests do not go through `ANTHROPIC_BASE_URL`. For Claude Code, `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1` (which `init` sets) turns most of them off. With a non-Anthropic base URL, Claude Code also disables some features, such as MCP tool search and Remote Control.
207
+ - **It over-masks on purpose.** Harmless values are sometimes masked too, because missing a real one costs far more. For example, `?email%3Dname%40example.com` becomes `?[EMAIL_ADDRESS_1]`, losing the parameter name along with the address.
208
+ - **No authentication.** Anyone who can reach the port can use it. Keep it on loopback.
209
+
210
+ ## Command reference
211
+
212
+ ```
213
+ maskerade init --engagement NAME [--client NAME ...] [--domain DOMAIN ...]
214
+ maskerade proxy [--engagement NAME] [--tier fast|full] [--port 8787]
215
+ [--custom-rules FILE] [--state-dir DIR] [--retention-days 30]
216
+ [--no-system-note | --system-note FILE]
217
+ maskerade rules check FILE [--against SAMPLE]
218
+ maskerade sessions list | purge (--all | --older-than Nd | --session ID) [--yes]
219
+ maskerade --version
220
+ python -m maskerade.warm [--full] [--to DIR] [--check]
221
+ ```
222
+
223
+ `--help` on any subcommand has the details. For an offline machine, run `python -m maskerade.warm --full --to DIR` on a connected one, copy the folder over, and set the variables it prints.
224
+
225
+ ## Licence
226
+
227
+ Apache-2.0. See [LICENSE](https://github.com/adamectimotei/maskerade-proxy/blob/main/LICENSE).
228
+
229
+ The BPE encoder (`cl100k_base`) is not redistributed here; `maskerade.warm` downloads it from its publisher. The full tier's model, `fastino/gliner2-privacy-filter-PII-multi`, is Apache-2.0 and is included in the `-ner` Docker image.
@@ -0,0 +1,197 @@
1
+ # maskerade
2
+
3
+ **A local masking proxy for the Anthropic API.** It runs on your own machine, replaces client data in your prompts and traffic with typed placeholders before anything is sent, and puts the real values back into the reply.
4
+
5
+ Built for penetration testers who use Claude (Claude Code, the SDKs, anything that speaks the Messages API) on client work and must not send client data to a third party.
6
+
7
+ ```
8
+ your client (Claude Code, SDK) maskerade, on 127.0.0.1 api.anthropic.com
9
+ ────────────────────────────── ────────────────────────── ─────────────────
10
+ "admin is jan.novak@acmebank.cz" ──▶ detect + mask ──▶ "admin is [EMAIL_ADDRESS_1]"
11
+ "reset it for jan.novak@acmebank.cz" ◀── restore real values ◀── "reset it for [EMAIL_ADDRESS_1]"
12
+ ```
13
+
14
+ > **Status: alpha (0.1.0).** It reduces what leaves your machine; it does not guarantee that nothing sensitive does. Read [What it does not do](#what-it-does-not-do) before relying on it, and keep reviewing what you send.
15
+
16
+ ---
17
+
18
+ ## How it works
19
+
20
+ - **Detects** client data with deterministic layers: your own rules (the client's names, domains and tenant slugs), around 100 regex patterns for credentials, tokens, keys, hashes, IPs, hostnames, emails and national IDs, checksum validators (IBAN, card numbers, national ID numbers), key/value structure (`"password": ...`), identifier shapes, and a randomness test for secrets nobody has a pattern for. The optional NER tier adds a local GLiNER model for names and organisations.
21
+ - **Masks** each value with a typed placeholder such as `[INTERNAL_HOSTNAME_1]`. The same value gets the same placeholder for the whole conversation, so the model can still reason about it ("`[USER_ID_1]` can read `[USER_ID_2]`'s invoices").
22
+ - **Forwards only the masked request** to `api.anthropic.com`, and appends a short note telling the model what the placeholders mean.
23
+ - **Restores** the real values in the reply, including streamed replies and tool-call arguments, so your client sees the real text.
24
+ - **Fails closed.** If a detector cannot run, or a detected value cannot be masked, the request is refused, never forwarded unmasked.
25
+
26
+ Everything runs locally on the CPU. No GPU, no model server, no account.
27
+
28
+ ## Install
29
+
30
+ Python 3.11 or newer.
31
+
32
+ ```bash
33
+ pip install maskerade
34
+ python -m maskerade.warm # one-time: fetches the 1.7 MB BPE encoder, checksum-verified
35
+ maskerade --version
36
+ ```
37
+
38
+ `warm` is required: the entropy detector needs that encoder, and without it the proxy refuses to start rather than run with a weaker detector.
39
+
40
+ ### Full tier (adds the NER model)
41
+
42
+ The `ner` extra pulls in PyTorch and the GLiNER model, a few GB in total. Install the **CPU** build of PyTorch first; otherwise pip fetches the much larger CUDA build, which this tool cannot use:
43
+
44
+ ```bash
45
+ pip install torch --index-url https://download.pytorch.org/whl/cpu
46
+ pip install "maskerade[ner]"
47
+ python -m maskerade.warm --full # one-time: encoder + model (~1.2 GB)
48
+ ```
49
+
50
+ Run it with `--tier full`. Startup takes noticeably longer while the model loads.
51
+
52
+ ### Docker
53
+
54
+ Images are published to `ghcr.io/adamectimotei/maskerade`: `0.1.0` (fast tier, ~190 MB) and `0.1.0-ner` (full tier, model included, ~2.6 GB). See [Docker](#docker) below before running one: **how you publish the port matters.**
55
+
56
+ ## Quick start with Claude Code
57
+
58
+ From the directory you'll work in for the engagement:
59
+
60
+ ```bash
61
+ maskerade init --engagement eng-2026-014
62
+ ```
63
+
64
+ `init` asks for the client's names and domains and writes them to `.maskerade/rules.txt`. It points Claude Code at the proxy through `.claude/settings.local.json`, and warns you about places the client's name already appears in clear text (the folder path, git remote, branch). It writes no credentials anywhere.
65
+
66
+ Then start the proxy **from that same directory** and use Claude Code as usual:
67
+
68
+ ```bash
69
+ maskerade proxy --engagement eng-2026-014 # fast tier (default)
70
+ maskerade proxy --engagement eng-2026-014 --tier full
71
+ ```
72
+
73
+ For any other client, point it at the proxy yourself:
74
+
75
+ ```bash
76
+ export ANTHROPIC_BASE_URL=http://127.0.0.1:8787 # bash
77
+ $env:ANTHROPIC_BASE_URL = "http://127.0.0.1:8787" # PowerShell
78
+ ```
79
+
80
+ Your API key, or your Claude subscription login, works unchanged; the proxy passes your credentials through and never stores or logs them.
81
+
82
+ ## Custom rules: the client's own identity
83
+
84
+ No detector can know your client's name in advance, so tell it. `.maskerade/rules.txt` is one value per line:
85
+
86
+ ```text
87
+ # acme bank, engagement 2026-014
88
+ acmebank.cz
89
+ Acme Bank a.s. = CLIENT_NAME
90
+ ACME-PAYROLL = CLIENT_SYSTEM
91
+ ```
92
+
93
+ - A bare line becomes `[CLIENT_1]`, `[CLIENT_2]`, ...; `value = TYPE` picks the type.
94
+ - Matching is case-insensitive and on word boundaries. A domain covers all its subdomains, so `acmebank.cz` also masks `portal.acmebank.cz`.
95
+ - An email address on a client domain is masked whole, as `[EMAIL_ADDRESS_n]`, never cut in half by a rule.
96
+ - The proxy re-reads the file when it changes. Check a file before trusting it:
97
+
98
+ ```bash
99
+ maskerade rules check .maskerade/rules.txt --against sample.txt
100
+ ```
101
+
102
+ ## Tiers
103
+
104
+ | | fast (default) | full (`--tier full`) |
105
+ |---|---|---|
106
+ | Install | `pip install maskerade` | `maskerade[ner]` + CPU PyTorch |
107
+ | Detectors | custom rules, ~100 regex patterns, entropy/format, key/value, checksums, identifier shapes | all of fast, plus GLiNER (names, organisations, locations) with an evidence gate for organisation names |
108
+ | Speed | milliseconds per message | slower; the model runs on CPU |
109
+ | Catches less of | free-text person and company names your rules don't list | very large bodies: the model skips inputs over 16 384 characters, the other detectors still run |
110
+
111
+ Recall and precision for both tiers will be published together with a re-measurement on this release. Until then, treat detection as **good but not complete**, and put everything you know about the client in your rules file.
112
+
113
+ ## Is it working?
114
+
115
+ - **Startup banner.** The proxy prints the bind address, the detector set (`mode`), where mask maps live, the engagement and which rules file it loaded. `custom rule none` means no rules file was found.
116
+ - **Every response carries headers:**
117
+ - `X-Maskerade-Mode`: the detectors that ran
118
+ - `X-Maskerade-Session`: the session, and `new` or `continued`
119
+ - `X-Maskerade-Rules`: how many of your rules are loaded
120
+ - `X-Maskerade-Unscanned`: request fields forwarded **without** inspection (see below)
121
+ - `X-Maskerade-Refused`: set when a request was refused instead of sent
122
+ - **Health check:** `curl http://127.0.0.1:8787/healthz`
123
+ - **Loopback only:** `netstat -ano | findstr 8787` (Windows) or `ss -ltnp | grep 8787` should show `127.0.0.1:8787` and nothing else.
124
+
125
+ ## Mask maps, sessions and retention
126
+
127
+ The mapping from placeholders to real values (the *mask map*) is stored per conversation, so the same value keeps the same placeholder across turns and the reply can be restored. **It is client data.** It lives in:
128
+
129
+ | OS | default location |
130
+ |---|---|
131
+ | Windows | `%LOCALAPPDATA%\maskerade` (deliberately not `Documents`, which OneDrive syncs) |
132
+ | Linux | `$XDG_STATE_HOME/maskerade`, or `~/.local/state/maskerade` |
133
+ | macOS | `~/Library/Application Support/maskerade` |
134
+
135
+ Set `MASKERADE_STATE_DIR` to put it elsewhere. The files are restricted to your user. On Linux and macOS the proxy refuses to start if it cannot do that; on Windows it prints a warning. It also warns if the location looks like a cloud-synced folder.
136
+
137
+ ```bash
138
+ maskerade sessions list # ids, labels, placeholder COUNTS; never values
139
+ maskerade sessions purge --older-than 30d
140
+ maskerade sessions purge --session eng-2026-014 # one engagement
141
+ maskerade sessions purge --all
142
+ ```
143
+
144
+ Sessions unused for 30 days are deleted when the proxy starts (`--retention-days` to change it).
145
+
146
+ ## Docker
147
+
148
+ ```bash
149
+ docker compose up -d # with docker-compose.yml from this repository
150
+ ```
151
+
152
+ The proxy refuses to listen anywhere but loopback unless given `--allow-remote`. Inside a container a loopback-only proxy is unreachable from the host, so **the image listens on all interfaces inside the container, and the port publish is what keeps it on your machine**:
153
+
154
+ ```bash
155
+ docker run -p 127.0.0.1:8787:8787 ... # correct: reachable from this machine only
156
+ docker run -p 8787:8787 ... # WRONG: anyone on your network can use it
157
+ ```
158
+
159
+ The proxy has no authentication, holds your mask maps and restores real values, so a wrong publish exposes client data to your whole network. The [compose file](https://github.com/adamectimotei/maskerade-proxy/blob/main/docker-compose.yml) gets this right and explains it. Also:
160
+
161
+ - Other containers on the **same Docker network** can reach the proxy. Don't attach it to networks shared with things you don't trust.
162
+ - Keep mask maps in a **named volume** (the compose file does). The proxy refuses a bind-mounted directory it cannot restrict to its own user.
163
+ - The first start downloads the 1.7 MB encoder into the volume. Later starts, including the NER image's, need no network beyond `api.anthropic.com`.
164
+ - The images are tested on Linux with Docker Engine. Docker Desktop on Windows and macOS is not tested yet.
165
+
166
+ ## What it does not do
167
+
168
+ Read this before you depend on it.
169
+
170
+ - **Only message content is inspected.** The system prompt, tool definitions and several other request fields are forwarded **as-is**, because masking them breaks the client. Every response names them in `X-Maskerade-Unscanned`. For Claude Code these fields include your **working directory, home directory, git remote and branch, and your account name**, so work from a neutrally named directory (`maskerade init` checks for this).
171
+ - **Images and documents are refused**, not forwarded: their bytes cannot be masked.
172
+ - **Detection is not complete.** A value no rule, pattern or model recognises goes through. The fast tier in particular misses free-text names that aren't in your rules.
173
+ - **It only proxies the Anthropic Messages API** (`/v1/messages`, `count_tokens`, `/v1/models`, and the OAuth token refresh). Any other path is refused.
174
+ - **It only covers traffic sent through it.** Your client's telemetry, update checks and other requests do not go through `ANTHROPIC_BASE_URL`. For Claude Code, `CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1` (which `init` sets) turns most of them off. With a non-Anthropic base URL, Claude Code also disables some features, such as MCP tool search and Remote Control.
175
+ - **It over-masks on purpose.** Harmless values are sometimes masked too, because missing a real one costs far more. For example, `?email%3Dname%40example.com` becomes `?[EMAIL_ADDRESS_1]`, losing the parameter name along with the address.
176
+ - **No authentication.** Anyone who can reach the port can use it. Keep it on loopback.
177
+
178
+ ## Command reference
179
+
180
+ ```
181
+ maskerade init --engagement NAME [--client NAME ...] [--domain DOMAIN ...]
182
+ maskerade proxy [--engagement NAME] [--tier fast|full] [--port 8787]
183
+ [--custom-rules FILE] [--state-dir DIR] [--retention-days 30]
184
+ [--no-system-note | --system-note FILE]
185
+ maskerade rules check FILE [--against SAMPLE]
186
+ maskerade sessions list | purge (--all | --older-than Nd | --session ID) [--yes]
187
+ maskerade --version
188
+ python -m maskerade.warm [--full] [--to DIR] [--check]
189
+ ```
190
+
191
+ `--help` on any subcommand has the details. For an offline machine, run `python -m maskerade.warm --full --to DIR` on a connected one, copy the folder over, and set the variables it prints.
192
+
193
+ ## Licence
194
+
195
+ Apache-2.0. See [LICENSE](https://github.com/adamectimotei/maskerade-proxy/blob/main/LICENSE).
196
+
197
+ The BPE encoder (`cl100k_base`) is not redistributed here; `maskerade.warm` downloads it from its publisher. The full tier's model, `fastino/gliner2-privacy-filter-PII-multi`, is Apache-2.0 and is included in the `-ner` Docker image.