canarywire 0.1.0a1__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 (125) hide show
  1. canarywire-0.1.0a1/.gitignore +37 -0
  2. canarywire-0.1.0a1/CHANGELOG.md +41 -0
  3. canarywire-0.1.0a1/LICENSE +202 -0
  4. canarywire-0.1.0a1/PKG-INFO +134 -0
  5. canarywire-0.1.0a1/README.md +97 -0
  6. canarywire-0.1.0a1/docs/guide/canaries-and-templates.md +193 -0
  7. canarywire-0.1.0a1/docs/guide/canarywire.yaml +106 -0
  8. canarywire-0.1.0a1/docs/guide/ci.md +71 -0
  9. canarywire-0.1.0a1/docs/guide/configuration.md +55 -0
  10. canarywire-0.1.0a1/docs/guide/faults.md +58 -0
  11. canarywire-0.1.0a1/docs/guide/report.md +204 -0
  12. canarywire-0.1.0a1/pyproject.toml +150 -0
  13. canarywire-0.1.0a1/src/canarywire/__init__.py +3 -0
  14. canarywire-0.1.0a1/src/canarywire/__main__.py +5 -0
  15. canarywire-0.1.0a1/src/canarywire/canaries.py +15 -0
  16. canarywire-0.1.0a1/src/canarywire/capture/__init__.py +0 -0
  17. canarywire-0.1.0a1/src/canarywire/capture/app.py +344 -0
  18. canarywire-0.1.0a1/src/canarywire/capture/daemon.py +197 -0
  19. canarywire-0.1.0a1/src/canarywire/capture/recorder.py +24 -0
  20. canarywire-0.1.0a1/src/canarywire/capture/relay.py +99 -0
  21. canarywire-0.1.0a1/src/canarywire/cli.py +188 -0
  22. canarywire-0.1.0a1/src/canarywire/config.py +592 -0
  23. canarywire-0.1.0a1/src/canarywire/loopback.py +19 -0
  24. canarywire-0.1.0a1/src/canarywire/py.typed +0 -0
  25. canarywire-0.1.0a1/src/canarywire/report/__init__.py +222 -0
  26. canarywire-0.1.0a1/src/canarywire/report/context.py +46 -0
  27. canarywire-0.1.0a1/src/canarywire/report/findings.py +146 -0
  28. canarywire-0.1.0a1/src/canarywire/report/mustache.py +259 -0
  29. canarywire-0.1.0a1/src/canarywire/report/outputs.py +122 -0
  30. canarywire-0.1.0a1/src/canarywire/report/samples.py +216 -0
  31. canarywire-0.1.0a1/src/canarywire/report/templates/junit.xml.mustache +31 -0
  32. canarywire-0.1.0a1/src/canarywire/report/templates/markdown.md.mustache +72 -0
  33. canarywire-0.1.0a1/src/canarywire/report/view.py +293 -0
  34. canarywire-0.1.0a1/src/canarywire/rpc.py +191 -0
  35. canarywire-0.1.0a1/src/canarywire/runner/__init__.py +0 -0
  36. canarywire-0.1.0a1/src/canarywire/runner/attacks.py +385 -0
  37. canarywire-0.1.0a1/src/canarywire/runner/catalog.py +385 -0
  38. canarywire-0.1.0a1/src/canarywire/runner/consistency.py +75 -0
  39. canarywire-0.1.0a1/src/canarywire/runner/fault.py +274 -0
  40. canarywire-0.1.0a1/src/canarywire/runner/fragmentation.py +296 -0
  41. canarywire-0.1.0a1/src/canarywire/runner/hooks.py +73 -0
  42. canarywire-0.1.0a1/src/canarywire/runner/jsonpath.py +97 -0
  43. canarywire-0.1.0a1/src/canarywire/runner/messages.py +83 -0
  44. canarywire-0.1.0a1/src/canarywire/runner/neutral.py +155 -0
  45. canarywire-0.1.0a1/src/canarywire/runner/prepare.py +284 -0
  46. canarywire-0.1.0a1/src/canarywire/runner/protocols/__init__.py +40 -0
  47. canarywire-0.1.0a1/src/canarywire/runner/protocols/anthropic.py +218 -0
  48. canarywire-0.1.0a1/src/canarywire/runner/protocols/openai.py +186 -0
  49. canarywire-0.1.0a1/src/canarywire/runner/restore.py +134 -0
  50. canarywire-0.1.0a1/src/canarywire/runner/runner.py +236 -0
  51. canarywire-0.1.0a1/src/canarywire/runner/scan.py +181 -0
  52. canarywire-0.1.0a1/src/canarywire/runner/session.py +151 -0
  53. canarywire-0.1.0a1/src/canarywire/runner/splits.py +96 -0
  54. canarywire-0.1.0a1/src/canarywire/templates/__init__.py +0 -0
  55. canarywire-0.1.0a1/src/canarywire/templates/default.yaml +13 -0
  56. canarywire-0.1.0a1/src/canarywire/templates/multi-turn.yaml +16 -0
  57. canarywire-0.1.0a1/src/canarywire/templates/tool-calls.yaml +34 -0
  58. canarywire-0.1.0a1/src/canarywire/values/__init__.py +0 -0
  59. canarywire-0.1.0a1/src/canarywire/values/builtins.py +202 -0
  60. canarywire-0.1.0a1/src/canarywire/values/checksums.py +91 -0
  61. canarywire-0.1.0a1/src/canarywire/values/errors.py +5 -0
  62. canarywire-0.1.0a1/src/canarywire/values/formats.py +34 -0
  63. canarywire-0.1.0a1/src/canarywire/values/regex.py +300 -0
  64. canarywire-0.1.0a1/src/canarywire/values/types.py +269 -0
  65. canarywire-0.1.0a1/tests/capture/test_app.py +344 -0
  66. canarywire-0.1.0a1/tests/capture/test_daemon.py +270 -0
  67. canarywire-0.1.0a1/tests/capture/test_recorder.py +12 -0
  68. canarywire-0.1.0a1/tests/capture/test_relay.py +30 -0
  69. canarywire-0.1.0a1/tests/e2e/conftest.py +42 -0
  70. canarywire-0.1.0a1/tests/e2e/gateways/refgw.py +504 -0
  71. canarywire-0.1.0a1/tests/e2e/harness.py +368 -0
  72. canarywire-0.1.0a1/tests/e2e/stubs/echo_upstream.py +190 -0
  73. canarywire-0.1.0a1/tests/e2e/test_bugs.py +156 -0
  74. canarywire-0.1.0a1/tests/e2e/test_faults.py +151 -0
  75. canarywire-0.1.0a1/tests/e2e/test_harness.py +129 -0
  76. canarywire-0.1.0a1/tests/e2e/test_protocols.py +195 -0
  77. canarywire-0.1.0a1/tests/e2e/test_refgw.py +479 -0
  78. canarywire-0.1.0a1/tests/e2e/test_reports.py +40 -0
  79. canarywire-0.1.0a1/tests/e2e/test_skeleton.py +181 -0
  80. canarywire-0.1.0a1/tests/e2e/test_tool_calls_multi_turn.py +105 -0
  81. canarywire-0.1.0a1/tests/report/golden/failing.md +62 -0
  82. canarywire-0.1.0a1/tests/report/golden/failing.xml +35 -0
  83. canarywire-0.1.0a1/tests/report/golden/passing.md +23 -0
  84. canarywire-0.1.0a1/tests/report/golden/passing.xml +7 -0
  85. canarywire-0.1.0a1/tests/report/golden/untrusted.md +31 -0
  86. canarywire-0.1.0a1/tests/report/test_context.py +36 -0
  87. canarywire-0.1.0a1/tests/report/test_findings.py +197 -0
  88. canarywire-0.1.0a1/tests/report/test_mustache.py +154 -0
  89. canarywire-0.1.0a1/tests/report/test_outputs.py +82 -0
  90. canarywire-0.1.0a1/tests/report/test_samples.py +93 -0
  91. canarywire-0.1.0a1/tests/report/test_templates.py +67 -0
  92. canarywire-0.1.0a1/tests/report/test_view.py +124 -0
  93. canarywire-0.1.0a1/tests/runner/test_adapters.py +327 -0
  94. canarywire-0.1.0a1/tests/runner/test_anthropic_protocol.py +46 -0
  95. canarywire-0.1.0a1/tests/runner/test_attacks.py +759 -0
  96. canarywire-0.1.0a1/tests/runner/test_catalog.py +540 -0
  97. canarywire-0.1.0a1/tests/runner/test_consistency.py +79 -0
  98. canarywire-0.1.0a1/tests/runner/test_fault.py +532 -0
  99. canarywire-0.1.0a1/tests/runner/test_fragmentation.py +579 -0
  100. canarywire-0.1.0a1/tests/runner/test_hooks.py +78 -0
  101. canarywire-0.1.0a1/tests/runner/test_jsonpath.py +64 -0
  102. canarywire-0.1.0a1/tests/runner/test_messages.py +57 -0
  103. canarywire-0.1.0a1/tests/runner/test_neutral.py +321 -0
  104. canarywire-0.1.0a1/tests/runner/test_openai_protocol.py +98 -0
  105. canarywire-0.1.0a1/tests/runner/test_prepare.py +490 -0
  106. canarywire-0.1.0a1/tests/runner/test_restore.py +126 -0
  107. canarywire-0.1.0a1/tests/runner/test_runner.py +318 -0
  108. canarywire-0.1.0a1/tests/runner/test_scan.py +249 -0
  109. canarywire-0.1.0a1/tests/runner/test_session.py +169 -0
  110. canarywire-0.1.0a1/tests/runner/test_splits.py +131 -0
  111. canarywire-0.1.0a1/tests/support/broken_import_module.py +3 -0
  112. canarywire-0.1.0a1/tests/support/fast_streams.py +52 -0
  113. canarywire-0.1.0a1/tests/support/live.py +105 -0
  114. canarywire-0.1.0a1/tests/support/mustache_spec.json +1134 -0
  115. canarywire-0.1.0a1/tests/support/sample_generators.py +33 -0
  116. canarywire-0.1.0a1/tests/test_cli.py +435 -0
  117. canarywire-0.1.0a1/tests/test_config.py +612 -0
  118. canarywire-0.1.0a1/tests/test_config_reference.py +168 -0
  119. canarywire-0.1.0a1/tests/test_loopback.py +18 -0
  120. canarywire-0.1.0a1/tests/test_report.py +376 -0
  121. canarywire-0.1.0a1/tests/test_rpc.py +248 -0
  122. canarywire-0.1.0a1/tests/values/test_builtins.py +141 -0
  123. canarywire-0.1.0a1/tests/values/test_checksums.py +52 -0
  124. canarywire-0.1.0a1/tests/values/test_regex.py +80 -0
  125. canarywire-0.1.0a1/tests/values/test_types.py +221 -0
@@ -0,0 +1,37 @@
1
+ # Python
2
+ __pycache__/
3
+ *.py[cod]
4
+ *.egg-info/
5
+ build/
6
+ dist/
7
+
8
+ # Environments
9
+ .venv/
10
+ .env
11
+
12
+ # Tooling caches
13
+ .ruff_cache/
14
+ .mypy_cache/
15
+ .pytest_cache/
16
+ .coverage
17
+ .coverage.*
18
+ htmlcov/
19
+ coverage.xml
20
+
21
+ # canarywire run output
22
+ out/
23
+ .canarywire/
24
+
25
+ # Editors / OS
26
+ .idea/
27
+ .vscode/
28
+ .DS_Store
29
+
30
+ # Local agent workspaces
31
+ .superpowers/
32
+ .claude/
33
+
34
+ # Internal design docs (kept locally, not published)
35
+ docs/specs/
36
+ docs/plans/
37
+ docs/roadmap.md
@@ -0,0 +1,41 @@
1
+ # Changelog
2
+
3
+ All notable changes to canarywire. The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/);
4
+ versions follow [Semantic Versioning](https://semver.org/). Before 1.0, a minor version may break
5
+ the config file, the `report.json` format or exit-code rules; each such change is listed here.
6
+
7
+ ## [0.1.0a1] - 2026-09-27
8
+
9
+ First public release, an alpha.
10
+
11
+ ### Added
12
+
13
+ - `canarywire serve [--detach]`, `run` and `stop`; exit codes `0` (the invariant held), `1`
14
+ (fail) and `2` (untrusted).
15
+ - Capture server: a fake upstream that records every request to `.canarywire/capture.jsonl` and
16
+ relays it to the runner. Credential headers (`authorization`, `x-api-key`, …) are redacted
17
+ in the record.
18
+ - Generators: `baseline`, `fragmentation` (placeholders split across SSE events) and `fault`
19
+ (your `before`/`after` commands break the environment; the gateway must refuse).
20
+ - Protocols: OpenAI Chat Completions and Anthropic Messages, streaming and non-streaming;
21
+ `target.routes` for several paths; `target.duty: mask-only` for gateways that never restore.
22
+ - Canaries: built-in types (email, phone, IBAN, card, national ID, …), custom types, seeded and
23
+ replayable with `--seed`.
24
+ - Templates: built-in `default`, `tool-calls` and `multi-turn`, plus your own.
25
+ - Verdicts: leak (URL, headers, body, JSON keys, JSON inside strings), unrestored/altered,
26
+ inconsistent placeholders, mangled request text; a negative control and a no-traffic rule
27
+ guard against passes that tested nothing.
28
+ - Reports: `report.json` (version 4) with grouped findings, `report.md`, JUnit (`--junit`), and
29
+ custom Mustache outputs.
30
+ - Worked examples against real gateways: `examples/litellm-presidio`, `examples/pasteguard`,
31
+ `examples/kiji`.
32
+
33
+ ### Known limitations
34
+
35
+ - Gateways that refuse requests containing PII (block mode) can't pass: a refusal outside a
36
+ fault is `untrusted`.
37
+ - Leaks are exact matches; a value forwarded transformed (re-cased, re-spaced, encoded) is not
38
+ detected.
39
+ - POSIX only.
40
+
41
+ [0.1.0a1]: https://github.com/pitkonst/canarywire/releases/tag/v0.1.0a1
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ https://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
+ https://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,134 @@
1
+ Metadata-Version: 2.5
2
+ Name: canarywire
3
+ Version: 0.1.0a1
4
+ Summary: A regression test for your PII gateway's trust boundary.
5
+ Project-URL: Homepage, https://github.com/pitkonst/canarywire
6
+ Project-URL: Documentation, https://github.com/pitkonst/canarywire/tree/main/docs/guide
7
+ Project-URL: Source, https://github.com/pitkonst/canarywire
8
+ Project-URL: Issues, https://github.com/pitkonst/canarywire/issues
9
+ Project-URL: Changelog, https://github.com/pitkonst/canarywire/blob/main/CHANGELOG.md
10
+ Author-email: Petr Konstantinov <pit.here@gmail.com>
11
+ License-Expression: Apache-2.0
12
+ License-File: LICENSE
13
+ Keywords: anthropic,gateway,llm,openai,pii,security,testing
14
+ Classifier: Development Status :: 3 - Alpha
15
+ Classifier: Environment :: Console
16
+ Classifier: Intended Audience :: Developers
17
+ Classifier: Operating System :: MacOS
18
+ Classifier: Operating System :: POSIX :: Linux
19
+ Classifier: Programming Language :: Python :: 3
20
+ Classifier: Programming Language :: Python :: 3 :: Only
21
+ Classifier: Programming Language :: Python :: 3.10
22
+ Classifier: Programming Language :: Python :: 3.11
23
+ Classifier: Programming Language :: Python :: 3.12
24
+ Classifier: Programming Language :: Python :: 3.13
25
+ Classifier: Programming Language :: Python :: 3.14
26
+ Classifier: Topic :: Security
27
+ Classifier: Topic :: Software Development :: Testing
28
+ Classifier: Typing :: Typed
29
+ Requires-Python: >=3.10
30
+ Requires-Dist: anyio>=4.15.1
31
+ Requires-Dist: httpx>=0.28.1
32
+ Requires-Dist: pyyaml>=6.0.3
33
+ Requires-Dist: starlette>=1.7.0
34
+ Requires-Dist: uvicorn>=0.53.0
35
+ Requires-Dist: websockets>=16.1.1
36
+ Description-Content-Type: text/markdown
37
+
38
+ # canarywire
39
+
40
+ **A regression test for your PII gateway's trust boundary.**
41
+ Black-box, self-hosted, and it runs in CI. It works with any gateway that speaks the OpenAI or Anthropic API: public, commercial, or one your team wrote.
42
+
43
+ ## Quick start
44
+
45
+ ```bash
46
+ pip install canarywire
47
+ canarywire serve --detach --listen 127.0.0.1:8765 # 1. fake upstream that records everything
48
+ your-gateway --upstream http://127.0.0.1:8765 --listen 127.0.0.1:4000 # 2. your gateway, pointed at it
49
+ canarywire run --target http://127.0.0.1:4000 # 3. attack the gateway, check the boundary
50
+ canarywire stop
51
+ ```
52
+
53
+ You start your gateway the way you always do, only with a different upstream. Exit code `0` means the boundary held. The report is in `out/report.json` and `out/report.md`.
54
+
55
+ A gateway that also serves Anthropic Messages, or uses other paths, needs a config file:
56
+
57
+ ```yaml
58
+ # canarywire.yaml → canarywire run --config canarywire.yaml
59
+ target:
60
+ base_url: http://127.0.0.1:4000
61
+ routes:
62
+ - {protocol: openai-chat, path: /v1/chat/completions}
63
+ - {protocol: anthropic-messages, path: /v1/messages}
64
+ ```
65
+
66
+ See [docs/guide/canarywire.yaml](https://github.com/pitkonst/canarywire/blob/main/docs/guide/canarywire.yaml) for every option with its default.
67
+
68
+ ## Why
69
+
70
+ Most teams test PII masking with unit tests on the masking function. The function can be correct while the system as a whole leaks. Bugs like these pass function-level tests, and have been reported against widely used open-source gateways:
71
+
72
+ - a placeholder split across two SSE events is never restored;
73
+ - the detector goes down, and the gateway forwards the request **unmasked** instead of refusing it;
74
+ - placeholders are restored in message text, but not in tool-call arguments;
75
+ - two people get the same placeholder in one conversation, and the wrong name comes back.
76
+
77
+ canarywire checks what actually crossed the boundary.
78
+
79
+ ## The invariant
80
+
81
+ 1. **Absolute.** No canary value ever reaches the upstream, in any attack, whatever the outcome.
82
+ 2. **Conditional.** If the request succeeded, every canary that the template echoes back reaches the client restored, in the right place.
83
+
84
+ A refused request is an acceptable outcome once the gateway has shown it works: under a fault, or
85
+ in a fragmentation case after the unsplit stream came back restored. A silent pass-through never
86
+ is. In `baseline` a refusal verifies nothing, so the run is `untrusted`: gateways that block
87
+ requests containing PII instead of masking them aren't supported yet.
88
+
89
+ ## How it works
90
+
91
+ - `canarywire serve` runs a **capture server**, and you point your gateway's upstream at it.
92
+ - `canarywire run` generates **canaries**: synthetic values in the formats you declare sensitive. It sends them through the gateway, inside requests built from **templates**.
93
+ - The capture hands every upstream request to the runner, which:
94
+ - checks it for canaries;
95
+ - answers with a scripted response that echoes the gateway's placeholders;
96
+ - then checks that the original values reached the client, in the right positions.
97
+
98
+ | Generator | What it tries |
99
+ | --- | --- |
100
+ | `baseline` | each template once: masked upstream, restored to the client, consistent placeholders |
101
+ | `fragmentation` | placeholders split across SSE events at every character offset |
102
+ | `fault` | your commands break the environment (e.g. stop the analyzer); the gateway must refuse |
103
+
104
+ The built-in templates cover plain messages (`default`), tool calls (`tool-calls`) and multi-turn conversations (`multi-turn`). You can add your own canary types, such as customer IDs or contract numbers, and your own templates. For gateways that only anonymize on the way in, set `target.duty: mask-only`.
105
+
106
+ | Exit code | Meaning |
107
+ | --- | --- |
108
+ | `0` | the invariant held |
109
+ | `1` | a leak, a value not restored (or altered under `mask-only`), inconsistent placeholders, or a request mangled around a canary |
110
+ | `2` | the run can't be trusted (capture unreachable, negative control not caught, config error, …) |
111
+
112
+ ## Documentation
113
+
114
+ - [Configuration](https://github.com/pitkonst/canarywire/blob/main/docs/guide/configuration.md): target, routes, duty, generators, seed, timeouts.
115
+ - [Canaries and templates](https://github.com/pitkonst/canarywire/blob/main/docs/guide/canaries-and-templates.md): built-in and custom types, the template format, protocols.
116
+ - [Faults](https://github.com/pitkonst/canarywire/blob/main/docs/guide/faults.md): breaking the environment and the fail-closed verdicts.
117
+ - [Report](https://github.com/pitkonst/canarywire/blob/main/docs/guide/report.md): `report.json`, findings, templated outputs (Markdown, JUnit, your own), exit codes.
118
+ - [CI](https://github.com/pitkonst/canarywire/blob/main/docs/guide/ci.md): GitHub Actions and GitLab CI examples.
119
+
120
+ ## What this is not
121
+
122
+ - **Not a gateway.** canarywire masks nothing and ships no proxy.
123
+ - **Not a detection-recall benchmark.** It proves the gateway handles the formats you declared, not how well a detector finds names in arbitrary text.
124
+ - **Not a quality benchmark.** How masking affects answer quality is a separate study.
125
+ - **Not proof of absence.** A format you didn't declare is a format that wasn't tested.
126
+ - **Not a fuzzy matcher.** A leak is the exact canary value in the upstream request (URL, headers,
127
+ body, JSON inside strings). A gateway that forwards a value transformed, e.g. re-cased,
128
+ re-spaced or base64-encoded, isn't caught.
129
+ - **Not a view of other channels.** Only what reaches the capture is checked. Values the gateway
130
+ sends elsewhere (an external detection API, logs, telemetry) aren't seen.
131
+
132
+ ## License
133
+
134
+ Apache-2.0
@@ -0,0 +1,97 @@
1
+ # canarywire
2
+
3
+ **A regression test for your PII gateway's trust boundary.**
4
+ Black-box, self-hosted, and it runs in CI. It works with any gateway that speaks the OpenAI or Anthropic API: public, commercial, or one your team wrote.
5
+
6
+ ## Quick start
7
+
8
+ ```bash
9
+ pip install canarywire
10
+ canarywire serve --detach --listen 127.0.0.1:8765 # 1. fake upstream that records everything
11
+ your-gateway --upstream http://127.0.0.1:8765 --listen 127.0.0.1:4000 # 2. your gateway, pointed at it
12
+ canarywire run --target http://127.0.0.1:4000 # 3. attack the gateway, check the boundary
13
+ canarywire stop
14
+ ```
15
+
16
+ You start your gateway the way you always do, only with a different upstream. Exit code `0` means the boundary held. The report is in `out/report.json` and `out/report.md`.
17
+
18
+ A gateway that also serves Anthropic Messages, or uses other paths, needs a config file:
19
+
20
+ ```yaml
21
+ # canarywire.yaml → canarywire run --config canarywire.yaml
22
+ target:
23
+ base_url: http://127.0.0.1:4000
24
+ routes:
25
+ - {protocol: openai-chat, path: /v1/chat/completions}
26
+ - {protocol: anthropic-messages, path: /v1/messages}
27
+ ```
28
+
29
+ See [docs/guide/canarywire.yaml](https://github.com/pitkonst/canarywire/blob/main/docs/guide/canarywire.yaml) for every option with its default.
30
+
31
+ ## Why
32
+
33
+ Most teams test PII masking with unit tests on the masking function. The function can be correct while the system as a whole leaks. Bugs like these pass function-level tests, and have been reported against widely used open-source gateways:
34
+
35
+ - a placeholder split across two SSE events is never restored;
36
+ - the detector goes down, and the gateway forwards the request **unmasked** instead of refusing it;
37
+ - placeholders are restored in message text, but not in tool-call arguments;
38
+ - two people get the same placeholder in one conversation, and the wrong name comes back.
39
+
40
+ canarywire checks what actually crossed the boundary.
41
+
42
+ ## The invariant
43
+
44
+ 1. **Absolute.** No canary value ever reaches the upstream, in any attack, whatever the outcome.
45
+ 2. **Conditional.** If the request succeeded, every canary that the template echoes back reaches the client restored, in the right place.
46
+
47
+ A refused request is an acceptable outcome once the gateway has shown it works: under a fault, or
48
+ in a fragmentation case after the unsplit stream came back restored. A silent pass-through never
49
+ is. In `baseline` a refusal verifies nothing, so the run is `untrusted`: gateways that block
50
+ requests containing PII instead of masking them aren't supported yet.
51
+
52
+ ## How it works
53
+
54
+ - `canarywire serve` runs a **capture server**, and you point your gateway's upstream at it.
55
+ - `canarywire run` generates **canaries**: synthetic values in the formats you declare sensitive. It sends them through the gateway, inside requests built from **templates**.
56
+ - The capture hands every upstream request to the runner, which:
57
+ - checks it for canaries;
58
+ - answers with a scripted response that echoes the gateway's placeholders;
59
+ - then checks that the original values reached the client, in the right positions.
60
+
61
+ | Generator | What it tries |
62
+ | --- | --- |
63
+ | `baseline` | each template once: masked upstream, restored to the client, consistent placeholders |
64
+ | `fragmentation` | placeholders split across SSE events at every character offset |
65
+ | `fault` | your commands break the environment (e.g. stop the analyzer); the gateway must refuse |
66
+
67
+ The built-in templates cover plain messages (`default`), tool calls (`tool-calls`) and multi-turn conversations (`multi-turn`). You can add your own canary types, such as customer IDs or contract numbers, and your own templates. For gateways that only anonymize on the way in, set `target.duty: mask-only`.
68
+
69
+ | Exit code | Meaning |
70
+ | --- | --- |
71
+ | `0` | the invariant held |
72
+ | `1` | a leak, a value not restored (or altered under `mask-only`), inconsistent placeholders, or a request mangled around a canary |
73
+ | `2` | the run can't be trusted (capture unreachable, negative control not caught, config error, …) |
74
+
75
+ ## Documentation
76
+
77
+ - [Configuration](https://github.com/pitkonst/canarywire/blob/main/docs/guide/configuration.md): target, routes, duty, generators, seed, timeouts.
78
+ - [Canaries and templates](https://github.com/pitkonst/canarywire/blob/main/docs/guide/canaries-and-templates.md): built-in and custom types, the template format, protocols.
79
+ - [Faults](https://github.com/pitkonst/canarywire/blob/main/docs/guide/faults.md): breaking the environment and the fail-closed verdicts.
80
+ - [Report](https://github.com/pitkonst/canarywire/blob/main/docs/guide/report.md): `report.json`, findings, templated outputs (Markdown, JUnit, your own), exit codes.
81
+ - [CI](https://github.com/pitkonst/canarywire/blob/main/docs/guide/ci.md): GitHub Actions and GitLab CI examples.
82
+
83
+ ## What this is not
84
+
85
+ - **Not a gateway.** canarywire masks nothing and ships no proxy.
86
+ - **Not a detection-recall benchmark.** It proves the gateway handles the formats you declared, not how well a detector finds names in arbitrary text.
87
+ - **Not a quality benchmark.** How masking affects answer quality is a separate study.
88
+ - **Not proof of absence.** A format you didn't declare is a format that wasn't tested.
89
+ - **Not a fuzzy matcher.** A leak is the exact canary value in the upstream request (URL, headers,
90
+ body, JSON inside strings). A gateway that forwards a value transformed, e.g. re-cased,
91
+ re-spaced or base64-encoded, isn't caught.
92
+ - **Not a view of other channels.** Only what reaches the capture is checked. Values the gateway
93
+ sends elsewhere (an external detection API, logs, telemetry) aren't seen.
94
+
95
+ ## License
96
+
97
+ Apache-2.0