open-pseudonym 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.
- open_pseudonym-0.1.0/LICENSE +202 -0
- open_pseudonym-0.1.0/NOTICE +5 -0
- open_pseudonym-0.1.0/PKG-INFO +73 -0
- open_pseudonym-0.1.0/README.md +25 -0
- open_pseudonym-0.1.0/pyproject.toml +49 -0
- open_pseudonym-0.1.0/setup.cfg +4 -0
- open_pseudonym-0.1.0/src/open_pseudonym/__init__.py +24 -0
- open_pseudonym-0.1.0/src/open_pseudonym/__main__.py +5 -0
- open_pseudonym-0.1.0/src/open_pseudonym/_data.py +34 -0
- open_pseudonym-0.1.0/src/open_pseudonym/browser.py +62 -0
- open_pseudonym-0.1.0/src/open_pseudonym/checks.py +104 -0
- open_pseudonym-0.1.0/src/open_pseudonym/cli.py +304 -0
- open_pseudonym-0.1.0/src/open_pseudonym/conformance.py +149 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/patterns.json +321 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/pools.json +1070 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/browse_and_fill.json +74 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/contacts.json +55 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/draft_reply.json +77 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/logs.json +69 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/money_math.json +71 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/schedule.json +74 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/secrets_only.json +43 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/strict.json +77 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/summarize.json +67 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/training_data.json +70 -0
- open_pseudonym-0.1.0/src/open_pseudonym/data/profiles/web_research.json +67 -0
- open_pseudonym-0.1.0/src/open_pseudonym/dates.py +112 -0
- open_pseudonym-0.1.0/src/open_pseudonym/detect.py +184 -0
- open_pseudonym-0.1.0/src/open_pseudonym/drbg.py +43 -0
- open_pseudonym-0.1.0/src/open_pseudonym/egress.py +266 -0
- open_pseudonym-0.1.0/src/open_pseudonym/fakes.py +397 -0
- open_pseudonym-0.1.0/src/open_pseudonym/fpe.py +104 -0
- open_pseudonym-0.1.0/src/open_pseudonym/handles.py +162 -0
- open_pseudonym-0.1.0/src/open_pseudonym/jcs.py +47 -0
- open_pseudonym-0.1.0/src/open_pseudonym/jws.py +110 -0
- open_pseudonym-0.1.0/src/open_pseudonym/mcp/__init__.py +169 -0
- open_pseudonym-0.1.0/src/open_pseudonym/ml.py +98 -0
- open_pseudonym-0.1.0/src/open_pseudonym/policy.py +235 -0
- open_pseudonym-0.1.0/src/open_pseudonym/proxy/__init__.py +5 -0
- open_pseudonym-0.1.0/src/open_pseudonym/proxy/app.py +509 -0
- open_pseudonym-0.1.0/src/open_pseudonym/proxy/sse.py +50 -0
- open_pseudonym-0.1.0/src/open_pseudonym/restore.py +238 -0
- open_pseudonym-0.1.0/src/open_pseudonym/session.py +733 -0
- open_pseudonym-0.1.0/src/open_pseudonym/types.py +50 -0
- open_pseudonym-0.1.0/src/open_pseudonym/vault.py +223 -0
- open_pseudonym-0.1.0/src/open_pseudonym.egg-info/PKG-INFO +73 -0
- open_pseudonym-0.1.0/src/open_pseudonym.egg-info/SOURCES.txt +61 -0
- open_pseudonym-0.1.0/src/open_pseudonym.egg-info/dependency_links.txt +1 -0
- open_pseudonym-0.1.0/src/open_pseudonym.egg-info/entry_points.txt +2 -0
- open_pseudonym-0.1.0/src/open_pseudonym.egg-info/requires.txt +37 -0
- open_pseudonym-0.1.0/src/open_pseudonym.egg-info/top_level.txt +1 -0
- open_pseudonym-0.1.0/tests/test_browser.py +93 -0
- open_pseudonym-0.1.0/tests/test_cli.py +39 -0
- open_pseudonym-0.1.0/tests/test_detect.py +91 -0
- open_pseudonym-0.1.0/tests/test_egress.py +158 -0
- open_pseudonym-0.1.0/tests/test_handles.py +167 -0
- open_pseudonym-0.1.0/tests/test_mask.py +216 -0
- open_pseudonym-0.1.0/tests/test_mcp.py +148 -0
- open_pseudonym-0.1.0/tests/test_ml.py +46 -0
- open_pseudonym-0.1.0/tests/test_policy_vault.py +105 -0
- open_pseudonym-0.1.0/tests/test_proxy.py +353 -0
- open_pseudonym-0.1.0/tests/test_restore.py +76 -0
- open_pseudonym-0.1.0/tests/test_sdk_clients.py +51 -0
|
@@ -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,73 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: open-pseudonym
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Open Pseudonym: keep personal data away from AI models without making them worse at the task. Task-aware stand-ins, local restore, secret handles and signed egress receipts.
|
|
5
|
+
Author: Ishan Srivastava
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/Ishan2036924/open-pseudonym
|
|
8
|
+
Project-URL: Specification, https://github.com/Ishan2036924/open-pseudonym/blob/main/spec/open-pseudonym.md
|
|
9
|
+
Keywords: pseudonymization,privacy,llm,pii,ai-agents,mcp,open-standard
|
|
10
|
+
Classifier: Development Status :: 3 - Alpha
|
|
11
|
+
Classifier: Intended Audience :: Developers
|
|
12
|
+
Classifier: Programming Language :: Python :: 3
|
|
13
|
+
Classifier: Topic :: Security
|
|
14
|
+
Classifier: Topic :: Software Development :: Libraries
|
|
15
|
+
Requires-Python: >=3.10
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
License-File: NOTICE
|
|
19
|
+
Requires-Dist: cryptography>=42
|
|
20
|
+
Provides-Extra: proxy
|
|
21
|
+
Requires-Dist: starlette>=0.40; extra == "proxy"
|
|
22
|
+
Requires-Dist: uvicorn>=0.30; extra == "proxy"
|
|
23
|
+
Requires-Dist: httpx>=0.27; extra == "proxy"
|
|
24
|
+
Provides-Extra: mcp
|
|
25
|
+
Requires-Dist: mcp<3,>=2.3; extra == "mcp"
|
|
26
|
+
Provides-Extra: browser
|
|
27
|
+
Requires-Dist: playwright>=1.50; extra == "browser"
|
|
28
|
+
Provides-Extra: openai
|
|
29
|
+
Requires-Dist: openai>=1.50; extra == "openai"
|
|
30
|
+
Provides-Extra: anthropic
|
|
31
|
+
Requires-Dist: anthropic>=0.40; extra == "anthropic"
|
|
32
|
+
Provides-Extra: gliner
|
|
33
|
+
Requires-Dist: gliner>=0.2; extra == "gliner"
|
|
34
|
+
Provides-Extra: spacy
|
|
35
|
+
Requires-Dist: spacy>=3.7; extra == "spacy"
|
|
36
|
+
Provides-Extra: all
|
|
37
|
+
Requires-Dist: starlette>=0.40; extra == "all"
|
|
38
|
+
Requires-Dist: uvicorn>=0.30; extra == "all"
|
|
39
|
+
Requires-Dist: httpx>=0.27; extra == "all"
|
|
40
|
+
Requires-Dist: mcp<3,>=2.3; extra == "all"
|
|
41
|
+
Requires-Dist: playwright>=1.50; extra == "all"
|
|
42
|
+
Requires-Dist: openai>=1.50; extra == "all"
|
|
43
|
+
Requires-Dist: anthropic>=0.40; extra == "all"
|
|
44
|
+
Provides-Extra: test
|
|
45
|
+
Requires-Dist: pytest>=8; extra == "test"
|
|
46
|
+
Requires-Dist: anyio>=4; extra == "test"
|
|
47
|
+
Dynamic: license-file
|
|
48
|
+
|
|
49
|
+
# open-pseudonym (Python)
|
|
50
|
+
|
|
51
|
+
Keep personal data away from AI models without making them worse at the task. Task-aware stand-ins, local restore,
|
|
52
|
+
secret handles that are filled in outside the model, and signed receipts for every request that leaves.
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
pip install open-pseudonym # core, needs only cryptography
|
|
56
|
+
pip install "open-pseudonym[proxy]" # local proxy for OpenAI and Anthropic style APIs
|
|
57
|
+
pip install "open-pseudonym[mcp]" # MCP middleware and gateway
|
|
58
|
+
pip install "open-pseudonym[browser]" # Playwright handle filler
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```python
|
|
62
|
+
from open_pseudonym import Session, Source
|
|
63
|
+
|
|
64
|
+
s = Session("draft_reply")
|
|
65
|
+
masked = s.mask("Hi Dana,\nyour Acme code is 482913.", Source(sender="no-reply@acme.com"))
|
|
66
|
+
print(masked.text) # Hi <a fake name>, ... {{OTP_1}}.
|
|
67
|
+
print(s.restore(masked.text, reveal_handles=True)) # exactly the original
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Try `opn demo`. The specification, guides and test vectors live at
|
|
71
|
+
<https://github.com/Ishan2036924/open-pseudonym>.
|
|
72
|
+
|
|
73
|
+
This is pseudonymisation, not anonymisation: what reaches the model is still personal data in law. Apache-2.0.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# open-pseudonym (Python)
|
|
2
|
+
|
|
3
|
+
Keep personal data away from AI models without making them worse at the task. Task-aware stand-ins, local restore,
|
|
4
|
+
secret handles that are filled in outside the model, and signed receipts for every request that leaves.
|
|
5
|
+
|
|
6
|
+
```bash
|
|
7
|
+
pip install open-pseudonym # core, needs only cryptography
|
|
8
|
+
pip install "open-pseudonym[proxy]" # local proxy for OpenAI and Anthropic style APIs
|
|
9
|
+
pip install "open-pseudonym[mcp]" # MCP middleware and gateway
|
|
10
|
+
pip install "open-pseudonym[browser]" # Playwright handle filler
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
```python
|
|
14
|
+
from open_pseudonym import Session, Source
|
|
15
|
+
|
|
16
|
+
s = Session("draft_reply")
|
|
17
|
+
masked = s.mask("Hi Dana,\nyour Acme code is 482913.", Source(sender="no-reply@acme.com"))
|
|
18
|
+
print(masked.text) # Hi <a fake name>, ... {{OTP_1}}.
|
|
19
|
+
print(s.restore(masked.text, reveal_handles=True)) # exactly the original
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
Try `opn demo`. The specification, guides and test vectors live at
|
|
23
|
+
<https://github.com/Ishan2036924/open-pseudonym>.
|
|
24
|
+
|
|
25
|
+
This is pseudonymisation, not anonymisation: what reaches the model is still personal data in law. Apache-2.0.
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=77"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "open-pseudonym"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
description = "Open Pseudonym: keep personal data away from AI models without making them worse at the task. Task-aware stand-ins, local restore, secret handles and signed egress receipts."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
license = "Apache-2.0"
|
|
11
|
+
authors = [{ name = "Ishan Srivastava" }]
|
|
12
|
+
requires-python = ">=3.10"
|
|
13
|
+
keywords = ["pseudonymization", "privacy", "llm", "pii", "ai-agents", "mcp", "open-standard"]
|
|
14
|
+
dependencies = ["cryptography>=42"]
|
|
15
|
+
classifiers = [
|
|
16
|
+
"Development Status :: 3 - Alpha",
|
|
17
|
+
"Intended Audience :: Developers",
|
|
18
|
+
"Programming Language :: Python :: 3",
|
|
19
|
+
"Topic :: Security",
|
|
20
|
+
"Topic :: Software Development :: Libraries",
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
[project.optional-dependencies]
|
|
24
|
+
proxy = ["starlette>=0.40", "uvicorn>=0.30", "httpx>=0.27"]
|
|
25
|
+
mcp = ["mcp>=2.3,<3"]
|
|
26
|
+
browser = ["playwright>=1.50"]
|
|
27
|
+
openai = ["openai>=1.50"]
|
|
28
|
+
anthropic = ["anthropic>=0.40"]
|
|
29
|
+
gliner = ["gliner>=0.2"]
|
|
30
|
+
spacy = ["spacy>=3.7"]
|
|
31
|
+
all = ["starlette>=0.40", "uvicorn>=0.30", "httpx>=0.27", "mcp>=2.3,<3", "playwright>=1.50", "openai>=1.50", "anthropic>=0.40"]
|
|
32
|
+
test = ["pytest>=8", "anyio>=4"]
|
|
33
|
+
|
|
34
|
+
[project.scripts]
|
|
35
|
+
opn = "open_pseudonym.cli:main"
|
|
36
|
+
|
|
37
|
+
[project.urls]
|
|
38
|
+
Homepage = "https://github.com/Ishan2036924/open-pseudonym"
|
|
39
|
+
Specification = "https://github.com/Ishan2036924/open-pseudonym/blob/main/spec/open-pseudonym.md"
|
|
40
|
+
|
|
41
|
+
[tool.setuptools.packages.find]
|
|
42
|
+
where = ["src"]
|
|
43
|
+
|
|
44
|
+
[tool.setuptools.package-data]
|
|
45
|
+
open_pseudonym = ["data/*.json", "data/profiles/*.json"]
|
|
46
|
+
|
|
47
|
+
[tool.pytest.ini_options]
|
|
48
|
+
pythonpath = ["src"]
|
|
49
|
+
testpaths = ["tests"]
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"""Open Pseudonym: keep personal data away from AI models without making them worse at the task.
|
|
2
|
+
|
|
3
|
+
The short version:
|
|
4
|
+
|
|
5
|
+
from open_pseudonym import Session, Source
|
|
6
|
+
s = Session("draft_reply")
|
|
7
|
+
masked = s.mask(text) # what the model may see
|
|
8
|
+
reply = s.restore(model_reply) # what the person reads
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from .egress import EgressLeak, EgressLog, Leak, verify_log
|
|
12
|
+
from .handles import HandleRefused, Sink, Source
|
|
13
|
+
from .jws import Signer
|
|
14
|
+
from .policy import LEVELS, Policy, PolicyError, Rule, load_level, load_profile, profile_names, suggest_profile
|
|
15
|
+
from .session import Masked, RefusedData, Replacement, Resolved, Session
|
|
16
|
+
from .vault import Vault, VaultError
|
|
17
|
+
|
|
18
|
+
__version__ = "0.1.0"
|
|
19
|
+
|
|
20
|
+
__all__ = [
|
|
21
|
+
"LEVELS", "EgressLeak", "EgressLog", "HandleRefused", "Leak", "Masked", "Policy", "PolicyError", "RefusedData",
|
|
22
|
+
"Replacement", "Resolved", "Rule", "Session", "Signer", "Sink", "Source", "Vault", "VaultError",
|
|
23
|
+
"load_level", "load_profile", "profile_names", "suggest_profile", "verify_log", "__version__",
|
|
24
|
+
]
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"""Loads the shared data files (fake-value pools, detection patterns, starter profiles).
|
|
2
|
+
|
|
3
|
+
The canonical copies live in the repository's top-level `data/` folder. `tools/sync_data.py` copies them into each
|
|
4
|
+
SDK so the installed packages carry them too; CI fails if the copies drift.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json
|
|
10
|
+
from functools import lru_cache
|
|
11
|
+
from pathlib import Path
|
|
12
|
+
|
|
13
|
+
DATA_DIR = Path(__file__).resolve().parent / "data"
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
@lru_cache(maxsize=None)
|
|
17
|
+
def pools() -> dict:
|
|
18
|
+
return json.loads((DATA_DIR / "pools.json").read_text(encoding="utf-8"))
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@lru_cache(maxsize=None)
|
|
22
|
+
def patterns() -> list[dict]:
|
|
23
|
+
return json.loads((DATA_DIR / "patterns.json").read_text(encoding="utf-8"))["patterns"]
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
def profile_names() -> list[str]:
|
|
27
|
+
return sorted(p.stem for p in (DATA_DIR / "profiles").glob("*.json"))
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def profile_doc(name: str) -> dict:
|
|
31
|
+
path = DATA_DIR / "profiles" / f"{name}.json"
|
|
32
|
+
if not path.is_file():
|
|
33
|
+
raise KeyError(f"no built-in profile called {name!r}; try one of {profile_names()}")
|
|
34
|
+
return json.loads(path.read_text(encoding="utf-8"))
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
"""Filling secret handles in a real browser (Playwright), only on the site they belong to.
|
|
2
|
+
|
|
3
|
+
filler = HandleFiller(session)
|
|
4
|
+
text = await filler.read(page) # what the model may see of this page
|
|
5
|
+
await filler.fill(page.locator("#code"), "{{OTP_1}}")
|
|
6
|
+
shot = await filler.screenshot(page) # filled fields are blacked out
|
|
7
|
+
|
|
8
|
+
The site check uses the URL of the frame that holds the field, read from the browser itself, so an injected
|
|
9
|
+
instruction cannot talk its way past it. After filling we check that the value is not showing anywhere in the page
|
|
10
|
+
text; if it is, the field is cleared and the fill is refused. Needs the [browser] extra.
|
|
11
|
+
"""
|
|
12
|
+
|
|
13
|
+
from __future__ import annotations
|
|
14
|
+
|
|
15
|
+
try:
|
|
16
|
+
from playwright.async_api import Locator, Page
|
|
17
|
+
except ImportError as e: # the optional dependency is not installed
|
|
18
|
+
raise ImportError('open_pseudonym.browser needs Playwright: pip install "open-pseudonym[browser]"') from e
|
|
19
|
+
|
|
20
|
+
from .handles import HandleRefused, Sink, Source
|
|
21
|
+
from .session import Session
|
|
22
|
+
|
|
23
|
+
TOOL = "browser_type"
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class HandleFiller:
|
|
27
|
+
def __init__(self, session: Session, tool: str = TOOL):
|
|
28
|
+
self.session = session
|
|
29
|
+
self.tool = tool
|
|
30
|
+
self._filled: list[Locator] = []
|
|
31
|
+
|
|
32
|
+
async def read(self, page: Page, source: Source | None = None) -> str:
|
|
33
|
+
"""The page's visible text, masked. Secrets found on the page get handles bound to the page's own site."""
|
|
34
|
+
text = await page.inner_text("body")
|
|
35
|
+
return self.session.mask(text, source or Source(site=page.url)).text
|
|
36
|
+
|
|
37
|
+
async def fill(self, field: Locator, handle: str) -> None:
|
|
38
|
+
"""Put the real value behind `handle` into `field`, if the field's frame is on an allowed site."""
|
|
39
|
+
frame_url = await field.evaluate("el => el.ownerDocument.location.href")
|
|
40
|
+
real = self.session.resolve_args({"value": handle}, Sink(tool=self.tool, site=frame_url)).args["value"]
|
|
41
|
+
await field.fill(real)
|
|
42
|
+
if await self._showing(field.page, real):
|
|
43
|
+
await field.fill("")
|
|
44
|
+
raise HandleRefused(handle, "the value became visible on the page")
|
|
45
|
+
self._filled.append(field)
|
|
46
|
+
|
|
47
|
+
@staticmethod
|
|
48
|
+
async def _showing(page: Page, real: str) -> bool:
|
|
49
|
+
for frame in page.frames:
|
|
50
|
+
try:
|
|
51
|
+
if real in await frame.inner_text("body"):
|
|
52
|
+
return True
|
|
53
|
+
except Exception: # a frame that went away or has no body cannot be showing anything
|
|
54
|
+
continue
|
|
55
|
+
return False
|
|
56
|
+
|
|
57
|
+
async def screenshot(self, page: Page, **kw) -> bytes:
|
|
58
|
+
"""A screenshot with every field we filled covered, so a vision model never sees the value."""
|
|
59
|
+
return await page.screenshot(mask=list(self._filled), **kw)
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
__all__ = ["HandleFiller", "HandleRefused"]
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"""Checksums and sanity checks that turn a pattern match into a confident detection.
|
|
2
|
+
|
|
3
|
+
A 16-digit run is only a card if the Luhn digit adds up; nine digits after "routing" are only a routing number if
|
|
4
|
+
the ABA weights do. These checks remove most false alarms (order numbers, tracking ids) for free.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
from ._data import pools
|
|
10
|
+
from .types import digits_of
|
|
11
|
+
|
|
12
|
+
# IBAN lengths per country (ISO 13616 registry). Unknown countries are rejected rather than guessed.
|
|
13
|
+
IBAN_LENGTHS = {
|
|
14
|
+
"AD": 24, "AE": 23, "AT": 20, "BE": 16, "BG": 22, "BH": 22, "BR": 29, "CH": 21, "CY": 28, "CZ": 24, "DE": 22,
|
|
15
|
+
"DK": 18, "EE": 20, "ES": 24, "FI": 18, "FO": 18, "FR": 27, "GB": 22, "GE": 22, "GI": 23, "GL": 18, "GR": 27,
|
|
16
|
+
"HR": 21, "HU": 28, "IE": 22, "IL": 23, "IS": 26, "IT": 27, "JO": 30, "KW": 30, "KZ": 20, "LB": 28, "LI": 21,
|
|
17
|
+
"LT": 20, "LU": 20, "LV": 21, "MC": 27, "MT": 31, "NL": 18, "NO": 15, "PK": 24, "PL": 28, "PS": 29, "PT": 25,
|
|
18
|
+
"QA": 29, "RO": 24, "RS": 22, "SA": 24, "SE": 24, "SI": 19, "SK": 24, "SM": 27, "TR": 26, "UA": 29, "VA": 22,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def luhn_ok(digits: str) -> bool:
|
|
23
|
+
total = 0
|
|
24
|
+
for i, ch in enumerate(reversed(digits)):
|
|
25
|
+
d = ord(ch) - 48
|
|
26
|
+
if i % 2 == 1:
|
|
27
|
+
d *= 2
|
|
28
|
+
if d > 9:
|
|
29
|
+
d -= 9
|
|
30
|
+
total += d
|
|
31
|
+
return total % 10 == 0
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def luhn_digit(partial: str) -> str:
|
|
35
|
+
"""The check digit that makes partial + digit pass Luhn."""
|
|
36
|
+
for d in "0123456789":
|
|
37
|
+
if luhn_ok(partial + d):
|
|
38
|
+
return d
|
|
39
|
+
raise AssertionError("unreachable")
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def card_ok(value: str) -> bool:
|
|
43
|
+
d = digits_of(value)
|
|
44
|
+
if not 13 <= len(d) <= 19 or not luhn_ok(d) or len(set(d)) == 1:
|
|
45
|
+
return False
|
|
46
|
+
if d[0] in "3456":
|
|
47
|
+
return True
|
|
48
|
+
return d[0] == "2" and 2221 <= int(d[:4]) <= 2720
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def iban_numeric(iban: str) -> int:
|
|
52
|
+
moved = iban[4:] + iban[:4]
|
|
53
|
+
return int("".join(str(int(ch, 36)) for ch in moved))
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def iban_ok(value: str) -> bool:
|
|
57
|
+
s = "".join(value.split()).upper()
|
|
58
|
+
if IBAN_LENGTHS.get(s[:2]) != len(s) or not s.isascii() or not s.isalnum():
|
|
59
|
+
return False
|
|
60
|
+
return iban_numeric(s) % 97 == 1
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def aba_sum(d: str) -> int:
|
|
64
|
+
return 3 * (int(d[0]) + int(d[3]) + int(d[6])) + 7 * (int(d[1]) + int(d[4]) + int(d[7])) + (
|
|
65
|
+
int(d[2]) + int(d[5]) + int(d[8])
|
|
66
|
+
)
|
|
67
|
+
|
|
68
|
+
|
|
69
|
+
def aba_ok(value: str) -> bool:
|
|
70
|
+
d = digits_of(value)
|
|
71
|
+
if len(d) != 9:
|
|
72
|
+
return False
|
|
73
|
+
prefix = int(d[:2])
|
|
74
|
+
if not (prefix <= 12 or 21 <= prefix <= 32 or 61 <= prefix <= 72 or prefix == 80):
|
|
75
|
+
return False
|
|
76
|
+
return aba_sum(d) % 10 == 0
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
def ssn_ok(value: str) -> bool:
|
|
80
|
+
d = digits_of(value)
|
|
81
|
+
if len(d) != 9:
|
|
82
|
+
return False
|
|
83
|
+
area, group, serial = d[:3], d[3:5], d[5:]
|
|
84
|
+
return area not in ("000", "666") and area[0] != "9" and group != "00" and serial != "0000"
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def phone_ok(value: str) -> bool:
|
|
88
|
+
return 10 <= len(digits_of(value)) <= 15
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
def name_ok(value: str) -> bool:
|
|
92
|
+
stop = _stopwords()
|
|
93
|
+
tokens = value.split()
|
|
94
|
+
return bool(tokens) and all(t.lower() not in stop and len(t) >= 2 for t in tokens)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
_STOP: frozenset[str] | None = None
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def _stopwords() -> frozenset[str]:
|
|
101
|
+
global _STOP
|
|
102
|
+
if _STOP is None:
|
|
103
|
+
_STOP = frozenset(w.lower() for w in pools()["name_stopwords"])
|
|
104
|
+
return _STOP
|