data-mask-policy 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.
- data_mask_policy-0.1.0/CHANGELOG.md +8 -0
- data_mask_policy-0.1.0/LICENSE +21 -0
- data_mask_policy-0.1.0/MANIFEST.in +3 -0
- data_mask_policy-0.1.0/PKG-INFO +557 -0
- data_mask_policy-0.1.0/README.md +534 -0
- data_mask_policy-0.1.0/pyproject.toml +41 -0
- data_mask_policy-0.1.0/python/data_mask_policy/__init__.py +923 -0
- data_mask_policy-0.1.0/python/data_mask_policy/py.typed +0 -0
- data_mask_policy-0.1.0/python/data_mask_policy.egg-info/PKG-INFO +557 -0
- data_mask_policy-0.1.0/python/data_mask_policy.egg-info/SOURCES.txt +13 -0
- data_mask_policy-0.1.0/python/data_mask_policy.egg-info/dependency_links.txt +1 -0
- data_mask_policy-0.1.0/python/data_mask_policy.egg-info/top_level.txt +1 -0
- data_mask_policy-0.1.0/setup.cfg +4 -0
- data_mask_policy-0.1.0/specification/policy-schema.json +537 -0
- data_mask_policy-0.1.0/specification/semantics.md +54 -0
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## 0.1.0
|
|
4
|
+
|
|
5
|
+
- Added native TypeScript and Python policy engines with zero runtime dependencies.
|
|
6
|
+
- Added shared policy validation, compiled reuse, conditional rules, strict projection, bounded traversal, and safe reports.
|
|
7
|
+
- Added scalar masking, regional presets, constants, removals, and trusted synchronous strategies.
|
|
8
|
+
- Added shared conformance fixtures, industry policies, and local integration examples.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Kotcherla Murali Krishna and contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,557 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: data-mask-policy
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Policy-driven data masking, redaction and sensitive field protection for structured data.
|
|
5
|
+
Author: Kotcherla Murali Krishna
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/mkkotcherla/data-mask-policy
|
|
8
|
+
Project-URL: Documentation, https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/api-python.md
|
|
9
|
+
Project-URL: Repository, https://github.com/mkkotcherla/data-mask-policy
|
|
10
|
+
Project-URL: Issues, https://github.com/mkkotcherla/data-mask-policy/issues
|
|
11
|
+
Project-URL: Changelog, https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/CHANGELOG.md
|
|
12
|
+
Keywords: data masking,redaction,PII,privacy,policy
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
18
|
+
Classifier: Operating System :: OS Independent
|
|
19
|
+
Requires-Python: <3.15,>=3.10
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# data-mask-policy
|
|
25
|
+
|
|
26
|
+
**data-mask-policy is a policy-driven library for masking PII and redacting structured data in Node.js, TypeScript, and Python.** Give it a record and a JSON policy, and it returns a sanitized copy. A rule can mask an email in every item of an array, redact a customer identifier, or remove an access token before the record leaves your application.
|
|
27
|
+
|
|
28
|
+
Use it at the point where an API response, structured log, data export, or AI tool payload is about to be shared. For example, a support API can keep a transaction reference and show only the last four digits of a card number. A policy with an explicit field allowlist also drops internal fields added later.
|
|
29
|
+
|
|
30
|
+
Define the policy once and reuse it across requests and services. Both implementations accept the same JSON policy format and run locally with zero runtime dependencies.
|
|
31
|
+
|
|
32
|
+
[Install](#install) · [Industry use cases](#industry-use-cases) · [JavaScript and TypeScript API](#javascript-and-typescript-api) · [Python API](#python-api) · [Documentation links](#documentation-links)
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
Install with your package manager.
|
|
37
|
+
|
|
38
|
+
```sh
|
|
39
|
+
npm install data-mask-policy
|
|
40
|
+
python -m pip install data-mask-policy
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
The JavaScript package supports Node.js 22, 24, and 26 with ESM, CommonJS, and TypeScript declarations. The Python package supports CPython 3.10–3.14. Versioned distributions and checksums are also available on the [GitHub release](https://github.com/mkkotcherla/data-mask-policy/releases/tag/v0.1.0).
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
If you downloaded a package from the GitHub release, install it from your download directory. [npm tarball](https://github.com/mkkotcherla/data-mask-policy/releases/download/v0.1.0/data-mask-policy-0.1.0.tgz) · [Python wheel](https://github.com/mkkotcherla/data-mask-policy/releases/download/v0.1.0/data_mask_policy-0.1.0-py3-none-any.whl)
|
|
47
|
+
|
|
48
|
+
```sh
|
|
49
|
+
npm install ./data-mask-policy-0.1.0.tgz
|
|
50
|
+
python -m pip install ./data_mask_policy-0.1.0-py3-none-any.whl
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Quick start
|
|
54
|
+
|
|
55
|
+
```js
|
|
56
|
+
import { createMasker, maskEmail } from 'data-mask-policy';
|
|
57
|
+
|
|
58
|
+
console.log(maskEmail('demo@example.test')); // d***@example.test
|
|
59
|
+
const masker = createMasker({
|
|
60
|
+
schemaVersion: 1,
|
|
61
|
+
defaultAction: 'remove',
|
|
62
|
+
allowPaths: ['orders[*].id', 'orders[*].email'],
|
|
63
|
+
rules: [{ id: 'contact', path: 'orders[*].email', strategy: 'email' }],
|
|
64
|
+
});
|
|
65
|
+
console.log(masker.apply({ orders: [{ id: 7, email: 'demo@example.test', internal: 'synthetic' }] }));
|
|
66
|
+
// { orders: [{ id: 7, email: 'd***@example.test' }] }
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
```python
|
|
70
|
+
from data_mask_policy import create_masker, mask_email
|
|
71
|
+
|
|
72
|
+
print(mask_email("demo@example.test")) # d***@example.test
|
|
73
|
+
masker = create_masker({
|
|
74
|
+
"schemaVersion": 1,
|
|
75
|
+
"defaultAction": "remove",
|
|
76
|
+
"allowPaths": ["orders[*].id", "orders[*].email"],
|
|
77
|
+
"rules": [{"id": "contact", "path": "orders[*].email", "strategy": "email"}],
|
|
78
|
+
})
|
|
79
|
+
print(masker.apply({"orders": [{"id": 7, "email": "demo@example.test", "internal": "synthetic"}]}))
|
|
80
|
+
# {'orders': [{'id': 7, 'email': 'd***@example.test'}]}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
CommonJS uses synchronous `require('data-mask-policy')`. TypeScript exports types for both module systems. Python ships a typed, pure-Python wheel.
|
|
84
|
+
|
|
85
|
+
## Industry use cases
|
|
86
|
+
|
|
87
|
+
The banking, healthcare, e-commerce, and SaaS sections below include copy-and-run snippets. The industry guide gives a Node.js and Python command for each of the 20 policies, with synthetic input and verified output.
|
|
88
|
+
|
|
89
|
+
[Read the full industry use case guide](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md) · [Open the runnable JSON fixtures](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/examples/industry.json)
|
|
90
|
+
|
|
91
|
+
### Fields you can mask by industry
|
|
92
|
+
|
|
93
|
+
These rows show the exact field names used by the runnable examples. In your own payload, set `path` to the field you want to protect. For nested data, you can use a path like `orders[*].email` to mask the email in every order.
|
|
94
|
+
|
|
95
|
+
| Industry | Field to protect | Strategy | Protected field in output | Field kept |
|
|
96
|
+
| --- | --- | --- | --- | --- |
|
|
97
|
+
| [Banking and financial services](#banking-and-financial-services) | `cardNumber` | `card` | `***1234` | `transactionRef` |
|
|
98
|
+
| [Insurance](#insurance) | `beneficiaryName` | `redact` | `[REDACTED]` | `claimRef` |
|
|
99
|
+
| [Healthcare](#healthcare) | `patientId` | `redact` | `[REDACTED]` | `appointmentStatus` |
|
|
100
|
+
| [E-commerce](#e-commerce) | `email` | `email` | `d***@example.test` | `orderId` |
|
|
101
|
+
| [Retail](#retail) | `loyaltyId` | `identifier` | `***0123` | `activity` |
|
|
102
|
+
| [Human resources](#human-resources) | `salary` | `redact` for roles outside authorized HR | `[REDACTED]` | `jobFamily` |
|
|
103
|
+
| [Recruitment](#recruitment) | `candidatePhone` | `remove` | Field omitted | `stage` |
|
|
104
|
+
| [Education](#education) | `studentId` | `identifier` | `***0123` | `enrollmentStatus` |
|
|
105
|
+
| [Travel](#travel) | `passport` | `passport` | `***001` | `bookingRef` |
|
|
106
|
+
| [Hospitality](#hospitality) | `guestEmail` | `remove` | Field omitted | `roomStatus` |
|
|
107
|
+
| [Government and public services](#government-and-public-services) | `citizenId` | `redact` | `[REDACTED]` | `status` |
|
|
108
|
+
| [Telecommunications](#telecommunications) | `subscriberRef` | `identifier` | `***0123` | `activation` |
|
|
109
|
+
| [Manufacturing](#manufacturing) | `contractPrice` | `replace` | `withheld` | `lineStatus` |
|
|
110
|
+
| [Logistics](#logistics) | `deliveryAddress` | `remove` | Field omitted | `shipmentStatus` |
|
|
111
|
+
| [Legal services](#legal-services) | `clientName` | `redact` | `[REDACTED]` | `matterStatus` |
|
|
112
|
+
| [Real estate](#real-estate) | `ownerContact` | `remove` | Field omitted | `listingStatus` |
|
|
113
|
+
| [SaaS](#saas) | `token` | `remove` | Field omitted | `incident` |
|
|
114
|
+
| [Cybersecurity](#cybersecurity) | `authorization` | `redact` | `[REDACTED]` | `event` |
|
|
115
|
+
| [Data analytics](#data-analytics) | `userIp` | `ip` | `***` | `eventType` |
|
|
116
|
+
| [AI agents](#ai-agents) | `customerEmail` | `remove` | Field omitted | `action` |
|
|
117
|
+
|
|
118
|
+
### Banking and financial services
|
|
119
|
+
|
|
120
|
+
A customer support receipt needs the transaction reference and the last four digits of the card. This policy permits those two fields and masks the card number. The internal processor note is dropped because the allowlist excludes it. The input below is synthetic.
|
|
121
|
+
|
|
122
|
+
#### Node.js
|
|
123
|
+
|
|
124
|
+
After installing the package, save this as `receipt.mjs` and run `node receipt.mjs`.
|
|
125
|
+
|
|
126
|
+
```js
|
|
127
|
+
import { createMasker } from 'data-mask-policy';
|
|
128
|
+
|
|
129
|
+
const receiptMasker = createMasker({
|
|
130
|
+
schemaVersion: 1,
|
|
131
|
+
defaultAction: 'remove',
|
|
132
|
+
allowPaths: ['transactionRef', 'cardNumber'],
|
|
133
|
+
rules: [{ id: 'mask-card', path: 'cardNumber', strategy: 'card', required: true }],
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
const receipt = {
|
|
137
|
+
transactionRef: 'TX-DEMO-1',
|
|
138
|
+
cardNumber: '0000000000001234',
|
|
139
|
+
processorNote: 'synthetic internal detail',
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
console.log(JSON.stringify(receiptMasker.apply(receipt)));
|
|
143
|
+
// {"transactionRef":"TX-DEMO-1","cardNumber":"***1234"}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
#### Python
|
|
147
|
+
|
|
148
|
+
Save this as `receipt.py` and run `python receipt.py` after installing the Python package.
|
|
149
|
+
|
|
150
|
+
```python
|
|
151
|
+
import json
|
|
152
|
+
|
|
153
|
+
from data_mask_policy import create_masker
|
|
154
|
+
|
|
155
|
+
receipt_masker = create_masker({
|
|
156
|
+
"schemaVersion": 1,
|
|
157
|
+
"defaultAction": "remove",
|
|
158
|
+
"allowPaths": ["transactionRef", "cardNumber"],
|
|
159
|
+
"rules": [{"id": "mask-card", "path": "cardNumber", "strategy": "card", "required": True}],
|
|
160
|
+
})
|
|
161
|
+
|
|
162
|
+
receipt = {
|
|
163
|
+
"transactionRef": "TX-DEMO-1",
|
|
164
|
+
"cardNumber": "0000000000001234",
|
|
165
|
+
"processorNote": "synthetic internal detail",
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
print(json.dumps(receipt_masker.apply(receipt), separators=(",", ":")))
|
|
169
|
+
# {"transactionRef":"TX-DEMO-1","cardNumber":"***1234"}
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
[View the banking and financial services policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#banking-and-financial-services--banking)
|
|
173
|
+
|
|
174
|
+
### Insurance
|
|
175
|
+
|
|
176
|
+
Share the claim reference with an external review queue and replace the beneficiary name with `[REDACTED]`. [View the insurance policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#insurance--insurance)
|
|
177
|
+
|
|
178
|
+
### Healthcare
|
|
179
|
+
|
|
180
|
+
Apply this policy before exporting appointment status. It redacts the patient ID and excludes clinical notes from the result.
|
|
181
|
+
|
|
182
|
+
```js
|
|
183
|
+
import { createMasker } from 'data-mask-policy';
|
|
184
|
+
|
|
185
|
+
const appointmentMasker = createMasker({
|
|
186
|
+
schemaVersion: 1,
|
|
187
|
+
defaultAction: 'remove',
|
|
188
|
+
allowPaths: ['appointmentStatus', 'patientId'],
|
|
189
|
+
rules: [{ id: 'redact-patient', path: 'patientId', strategy: 'redact' }],
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
const appointment = {
|
|
193
|
+
appointmentStatus: 'checked-in',
|
|
194
|
+
patientId: 'PAT-DEMO-7',
|
|
195
|
+
clinicalNotes: 'synthetic internal note',
|
|
196
|
+
};
|
|
197
|
+
console.log(JSON.stringify(appointmentMasker.apply(appointment)));
|
|
198
|
+
// {"appointmentStatus":"checked-in","patientId":"[REDACTED]"}
|
|
199
|
+
```
|
|
200
|
+
|
|
201
|
+
[View the healthcare policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#healthcare--healthcare)
|
|
202
|
+
|
|
203
|
+
### E-commerce
|
|
204
|
+
|
|
205
|
+
Use this policy on an order support response to keep the order ID and partially mask the customer email.
|
|
206
|
+
|
|
207
|
+
```python
|
|
208
|
+
import json
|
|
209
|
+
|
|
210
|
+
from data_mask_policy import create_masker
|
|
211
|
+
|
|
212
|
+
order_masker = create_masker({
|
|
213
|
+
"schemaVersion": 1,
|
|
214
|
+
"defaultAction": "remove",
|
|
215
|
+
"allowPaths": ["orderId", "email"],
|
|
216
|
+
"rules": [{"id": "mask-email", "path": "email", "strategy": "email"}],
|
|
217
|
+
})
|
|
218
|
+
|
|
219
|
+
order = {"orderId": "ORDER-DEMO", "email": "demo@example.test", "internalNote": "synthetic"}
|
|
220
|
+
print(json.dumps(order_masker.apply(order), separators=(",", ":")))
|
|
221
|
+
# {"orderId":"ORDER-DEMO","email":"d***@example.test"}
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
[View the e-commerce policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#e-commerce--ecommerce)
|
|
225
|
+
|
|
226
|
+
### Retail
|
|
227
|
+
|
|
228
|
+
A loyalty kiosk can show points activity and the final four characters of a loyalty ID. The policy uses `path` to select `loyaltyId`, `strategy` to apply identifier masking, and `options.visibleSuffix` to set how many characters to show. The strict allowlist also keeps `activity` and excludes any other fields.
|
|
229
|
+
|
|
230
|
+
```json
|
|
231
|
+
{
|
|
232
|
+
"schemaVersion": 1,
|
|
233
|
+
"defaultAction": "remove",
|
|
234
|
+
"allowPaths": [
|
|
235
|
+
"activity",
|
|
236
|
+
"loyaltyId"
|
|
237
|
+
],
|
|
238
|
+
"rules": [
|
|
239
|
+
{
|
|
240
|
+
"id": "mask-loyalty-id",
|
|
241
|
+
"path": "loyaltyId",
|
|
242
|
+
"strategy": "identifier",
|
|
243
|
+
"options": {
|
|
244
|
+
"visibleSuffix": 4,
|
|
245
|
+
"maskChar": "*"
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
]
|
|
249
|
+
}
|
|
250
|
+
```
|
|
251
|
+
|
|
252
|
+
With synthetic input `{"activity":"points-earned","loyaltyId":"LOYALTY-0123","newInternalField":"synthetic internal detail"}`, the result is `{"activity":"points-earned","loyaltyId":"***0123"}`.
|
|
253
|
+
|
|
254
|
+
Use the runnable Retail fixture from a checkout of this repository. [View the retail policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#retail--retail)
|
|
255
|
+
|
|
256
|
+
### Human resources
|
|
257
|
+
|
|
258
|
+
Keep job family in an employee view and redact salary when the authenticated role falls outside authorized HR. [View the human resources policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#human-resources--hr)
|
|
259
|
+
|
|
260
|
+
### Recruitment
|
|
261
|
+
|
|
262
|
+
Share a candidate's pipeline stage with the hiring panel and remove the candidate's phone number. [View the recruitment policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#recruitment--recruitment)
|
|
263
|
+
|
|
264
|
+
### Education
|
|
265
|
+
|
|
266
|
+
Send enrollment status to the program coordinator with a partial student reference. [View the education policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#education--education)
|
|
267
|
+
|
|
268
|
+
### Travel
|
|
269
|
+
|
|
270
|
+
Keep the booking reference for support and show only a short suffix of the passport number. [View the travel policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#travel--travel)
|
|
271
|
+
|
|
272
|
+
### Hospitality
|
|
273
|
+
|
|
274
|
+
Send room readiness to housekeeping and omit the guest email from that view. [View the hospitality policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#hospitality--hospitality)
|
|
275
|
+
|
|
276
|
+
### Government and public services
|
|
277
|
+
|
|
278
|
+
Show application stage to the service desk and redact citizen identifiers. [View the government and public services policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#government--government)
|
|
279
|
+
|
|
280
|
+
### Telecommunications
|
|
281
|
+
|
|
282
|
+
Show line activation status with a partially masked subscriber reference. [View the telecommunications policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#telecommunications--telecommunications)
|
|
283
|
+
|
|
284
|
+
### Manufacturing
|
|
285
|
+
|
|
286
|
+
Share production status with a vendor and replace the contract price with `withheld`. [View the manufacturing policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#manufacturing--manufacturing)
|
|
287
|
+
|
|
288
|
+
### Logistics
|
|
289
|
+
|
|
290
|
+
Send the shipment status to a warehouse display and omit the delivery address. [View the logistics policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#logistics--logistics)
|
|
291
|
+
|
|
292
|
+
### Legal services
|
|
293
|
+
|
|
294
|
+
Share matter status with billing and redact the client name. [View the legal services policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#legal-services--legal)
|
|
295
|
+
|
|
296
|
+
### Real estate
|
|
297
|
+
|
|
298
|
+
Export listing workflow status for reporting and remove the owner's contact field. [View the real estate policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#real-estate--real-estate)
|
|
299
|
+
|
|
300
|
+
### SaaS
|
|
301
|
+
|
|
302
|
+
Sanitize a tenant diagnostic record before sharing it with customer support. The policy keeps the incident ID and removes the access token.
|
|
303
|
+
|
|
304
|
+
```js
|
|
305
|
+
import { createMasker } from 'data-mask-policy';
|
|
306
|
+
|
|
307
|
+
const diagnosticMasker = createMasker({
|
|
308
|
+
schemaVersion: 1,
|
|
309
|
+
defaultAction: 'remove',
|
|
310
|
+
allowPaths: ['incident', 'token'],
|
|
311
|
+
rules: [{ id: 'strip-token', path: 'token', strategy: 'remove' }],
|
|
312
|
+
});
|
|
313
|
+
|
|
314
|
+
const diagnostic = { incident: 'INC-DEMO', token: 'synthetic-access-token' };
|
|
315
|
+
console.log(JSON.stringify(diagnosticMasker.apply(diagnostic)));
|
|
316
|
+
// {"incident":"INC-DEMO"}
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
[View the SaaS policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#saas--saas)
|
|
320
|
+
|
|
321
|
+
### Cybersecurity
|
|
322
|
+
|
|
323
|
+
Keep the authentication event name and redact the authorization header before writing the structured log. [View the cybersecurity policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#cybersecurity--cybersecurity)
|
|
324
|
+
|
|
325
|
+
### Data analytics
|
|
326
|
+
|
|
327
|
+
Keep the event type and fully mask the source IP address before exporting a row. [View the data analytics policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#data-analytics--data-analytics)
|
|
328
|
+
|
|
329
|
+
### AI agents
|
|
330
|
+
|
|
331
|
+
Keep the tool action and remove the customer email before sending the tool result into a model request. [View the AI agents policy example](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md#ai-agents--ai-agents)
|
|
332
|
+
|
|
333
|
+
## JavaScript and TypeScript API
|
|
334
|
+
|
|
335
|
+
Import `createMasker` from `data-mask-policy` in Node.js. TypeScript declarations cover the policy, input, outputs, and typed errors. Use `maskObject(data, policy)` for a one-off call, or reuse `createMasker(policy).apply(data)` in a request handler. CommonJS consumers can use `require('data-mask-policy')`. Use `applyWithReport` when you need the masked value and aggregate diagnostics.
|
|
336
|
+
|
|
337
|
+
[Open the JavaScript and TypeScript API reference](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/api-javascript.md)
|
|
338
|
+
|
|
339
|
+
```js
|
|
340
|
+
import { createMasker } from 'data-mask-policy';
|
|
341
|
+
|
|
342
|
+
const masker = createMasker({
|
|
343
|
+
schemaVersion: 1,
|
|
344
|
+
rules: [{ id: 'strip-token', path: 'token', strategy: 'remove' }],
|
|
345
|
+
});
|
|
346
|
+
const { data, report } = masker.applyWithReport({ id: 7, token: 'synthetic' });
|
|
347
|
+
console.log(data, report.removedFields); // { id: 7 } 1
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
## Python API
|
|
351
|
+
|
|
352
|
+
Import `create_masker` from `data_mask_policy`. Use `mask_object(data, policy)` for a one-off call, or reuse `create_masker(policy).apply(data, context=...)` in a service or export job. `apply_with_report` returns the sanitized value and aggregate diagnostics. The package ships Python type information.
|
|
353
|
+
|
|
354
|
+
[Open the Python API reference](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/api-python.md)
|
|
355
|
+
|
|
356
|
+
```python
|
|
357
|
+
from data_mask_policy import create_masker
|
|
358
|
+
|
|
359
|
+
masker = create_masker({
|
|
360
|
+
"schemaVersion": 1,
|
|
361
|
+
"rules": [{"id": "strip-token", "path": "token", "strategy": "remove"}],
|
|
362
|
+
})
|
|
363
|
+
result = masker.apply_with_report({"id": 7, "token": "synthetic"})
|
|
364
|
+
print(result["data"], result["report"]["removedFields"]) # {'id': 7} 1
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
## Policy reference
|
|
368
|
+
|
|
369
|
+
A policy declares `schemaVersion: 1` and a list of rules. Each rule names a path, such as `orders[*].email`, and a strategy. Preserve mode carries unmatched fields through. Set `defaultAction: "remove"` and use `allowPaths` to keep only explicitly approved output fields. Use required rules to fail when a field must be present.
|
|
370
|
+
|
|
371
|
+
[Read the policy reference](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/policy-reference.md)
|
|
372
|
+
|
|
373
|
+
### Context-aware masking
|
|
374
|
+
|
|
375
|
+
Use application-verified facts such as the role from an authenticated session. [Read the context and precedence rules](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/specification/semantics.md#context-and-precedence)
|
|
376
|
+
|
|
377
|
+
```js
|
|
378
|
+
import { createMasker } from 'data-mask-policy';
|
|
379
|
+
|
|
380
|
+
const payroll = createMasker({
|
|
381
|
+
schemaVersion: 1,
|
|
382
|
+
rules: [{
|
|
383
|
+
id: 'staff-salary',
|
|
384
|
+
path: 'salary',
|
|
385
|
+
strategy: 'redact',
|
|
386
|
+
required: true,
|
|
387
|
+
when: { field: 'role', operator: 'notEquals', value: 'authorized-hr' },
|
|
388
|
+
}],
|
|
389
|
+
});
|
|
390
|
+
console.log(payroll.apply({ salary: 120000 }, { context: { role: 'support' } }));
|
|
391
|
+
// { salary: '[REDACTED]' }
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
Comparisons fail closed if a required context attribute is missing. Python passes the same context with `apply(record, context=...)`.
|
|
395
|
+
|
|
396
|
+
## JSON Schema
|
|
397
|
+
|
|
398
|
+
Use the Draft 2020-12 schema in an editor or CI check to catch malformed policy documents. The runtime adds validation for rule overlap, path restrictions, registered strategies, and configured limits.
|
|
399
|
+
|
|
400
|
+
[Open the policy JSON Schema](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/specification/policy-schema.json)
|
|
401
|
+
|
|
402
|
+
## Shared semantics
|
|
403
|
+
|
|
404
|
+
A policy uses the same field-path grammar, conditions, strategy options, and precedence in both runtimes. Array indexes refer to the original input. Active rules that match the same target require distinct priorities, and the highest priority wins. Required matches, strict projection, and missing trusted context follow the same rules in JavaScript and Python.
|
|
405
|
+
|
|
406
|
+
[Read the shared policy semantics](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/specification/semantics.md)
|
|
407
|
+
|
|
408
|
+
## Masking strategies
|
|
409
|
+
|
|
410
|
+
Use `redact` to replace a value with a redaction marker, `remove` to drop a field, and `replace` to substitute a constant. Full, partial, prefix, and suffix masking control how much of a value stays visible. Email, phone, card, name, identifier, account, IP, and regional presets provide field-specific defaults.
|
|
411
|
+
|
|
412
|
+
[See the masking strategy options and defaults](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/masking-strategies.md)
|
|
413
|
+
|
|
414
|
+
| Masking option | What it controls |
|
|
415
|
+
| --- | --- |
|
|
416
|
+
| `visiblePrefix` and `visibleSuffix` | Characters to keep at the start and end for strategies that support visible characters, such as `identifier` and `partial`. |
|
|
417
|
+
| `maskChar` | The character that replaces hidden text. Defaults to `*`. |
|
|
418
|
+
| `maskLength` or `preserveLength` | A fixed mask length or one replacement character for each hidden character. |
|
|
419
|
+
| `replacement` | The constant to use with `replace`, or an optional text marker with `redact`. |
|
|
420
|
+
| `invalidInput` | For text strategies, redact an invalid value or raise a typed error. |
|
|
421
|
+
|
|
422
|
+
### Trusted custom strategies
|
|
423
|
+
|
|
424
|
+
[See custom strategies and typed errors](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/api-python.md#custom-strategy-and-errors).
|
|
425
|
+
|
|
426
|
+
```python
|
|
427
|
+
from data_mask_policy import create_masker
|
|
428
|
+
|
|
429
|
+
def public_reference(value, options):
|
|
430
|
+
if not isinstance(value, str) or len(value) <= 3:
|
|
431
|
+
return "[REDACTED]"
|
|
432
|
+
return options["prefix"] + "***" + value[-3:]
|
|
433
|
+
|
|
434
|
+
custom = create_masker({
|
|
435
|
+
"schemaVersion": 1,
|
|
436
|
+
"rules": [{"id": "reference", "path": "ref", "strategy": "public-ref", "options": {"prefix": "REF-"}}],
|
|
437
|
+
}, strategies={"public-ref": public_reference})
|
|
438
|
+
print(custom.apply({"ref": "DEMO0123"})) # {'ref': 'REF-***123'}
|
|
439
|
+
```
|
|
440
|
+
|
|
441
|
+
## Framework integrations
|
|
442
|
+
|
|
443
|
+
Compile the policy during startup and apply it just before sending an API response, logging an event, exporting a row, or submitting structured data to a model. The runnable examples cover Express, Fastify, NestJS, Next.js, GraphQL, and Pino on Node.js, plus FastAPI, Django, Flask, Pandas, and PySpark in Python. Use application-verified context for role-based rules.
|
|
444
|
+
|
|
445
|
+
[Open the framework integration guide](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/integrations.md)
|
|
446
|
+
|
|
447
|
+
### Apply a policy at an HTTP response boundary
|
|
448
|
+
|
|
449
|
+
1. List the fields the destination actually needs and choose a default action. Use strict projection for a public API, outbound event, or other fixed output contract.
|
|
450
|
+
2. Compile the policy once at startup. Pass trusted request context only when a rule needs it.
|
|
451
|
+
3. Apply the policy before serializing a response, writing a log, exporting a row, or sending structured data to an AI tool.
|
|
452
|
+
4. If masking fails, stop the response or export. Test the expected output with synthetic records, including a record with a new field and a record with missing context.
|
|
453
|
+
|
|
454
|
+
The following Node.js example adapts a compiled masker to an HTTP response. For an Express or Fastify app, use the same boundary before your framework writes the JSON body. [See the JavaScript framework examples](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/integrations.md#javascript)
|
|
455
|
+
|
|
456
|
+
```js
|
|
457
|
+
import { createMasker, MaskError } from 'data-mask-policy';
|
|
458
|
+
|
|
459
|
+
const outbound = createMasker({
|
|
460
|
+
schemaVersion: 1,
|
|
461
|
+
defaultAction: 'remove',
|
|
462
|
+
allowPaths: ['id', 'email'],
|
|
463
|
+
rules: [{ id: 'mask-email', path: 'email', strategy: 'email', required: true }],
|
|
464
|
+
});
|
|
465
|
+
|
|
466
|
+
function serializeCustomer(record) {
|
|
467
|
+
try {
|
|
468
|
+
const safe = outbound.apply(record);
|
|
469
|
+
return { statusCode: 200, body: JSON.stringify(safe) };
|
|
470
|
+
} catch (error) {
|
|
471
|
+
if (!(error instanceof MaskError)) throw error;
|
|
472
|
+
return { statusCode: 500, body: '{"error":"masking_failed"}' };
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
console.log(serializeCustomer({ id: 7, email: 'demo@example.test', token: 'synthetic' }));
|
|
477
|
+
// { statusCode: 200, body: '{"id":7,"email":"d***@example.test"}' }
|
|
478
|
+
```
|
|
479
|
+
|
|
480
|
+
## Performance measurements
|
|
481
|
+
|
|
482
|
+
The benchmark report records median and tail latency for single values, compiled policy reuse, strict projection, diagnostic reports, and batches. The compiled one-record benchmark measured a median of 31.5 µs on Node.js and 92.0 µs on CPython in the documented test environment. Use the benchmark scripts to measure your own payload shapes and policy sizes.
|
|
483
|
+
|
|
484
|
+
[See the benchmark results and how to reproduce them](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/performance.md)
|
|
485
|
+
|
|
486
|
+
## Troubleshooting
|
|
487
|
+
|
|
488
|
+
For `INVALID_CONTEXT`, check that the application supplies the expected trusted attributes. For `MISSING_REQUIRED_FIELD`, check the path against a synthetic copy of the expected record shape. If strict projection removes a field you expected, review the allowlist and matched-rule report. Return a controlled error when masking fails.
|
|
489
|
+
|
|
490
|
+
[Look up error codes and troubleshooting steps](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/troubleshooting.md)
|
|
491
|
+
|
|
492
|
+
## Architecture
|
|
493
|
+
|
|
494
|
+
The TypeScript and Python engines compile the same JSON policy format into reusable maskers. They resolve paths and trusted conditions, apply the configured transformations, and return a separate sanitized value. The shared fixtures compare output and error codes across the two engines.
|
|
495
|
+
|
|
496
|
+
[Read how the two policy engines are structured](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/architecture.md)
|
|
497
|
+
|
|
498
|
+
## Adoption guide
|
|
499
|
+
|
|
500
|
+
Start with one outbound flow, such as support responses or structured logs. Inventory its fields, define the output allowlist, and add synthetic fixtures for ordinary and elevated roles, missing fields, and newly added fields. Store the policy with the service and reuse the fixture suite wherever the policy runs.
|
|
501
|
+
|
|
502
|
+
[Read the adoption guide](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/adoption.md)
|
|
503
|
+
|
|
504
|
+
## Security boundaries
|
|
505
|
+
|
|
506
|
+
Apply masking before a payload reaches a logger, serializer, export, or external provider. Keep authorization in the host application and pass verified context to policy rules. Review custom strategies as application code and keep identifying data out of rule IDs and diagnostics. Partially masked values can still identify people.
|
|
507
|
+
|
|
508
|
+
[Review the security boundaries](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/security.md)
|
|
509
|
+
|
|
510
|
+
## Contributing
|
|
511
|
+
|
|
512
|
+
Use synthetic records in bug reports and tests. For policy behavior changes, add or update shared fixtures and run the documentation and conformance checks for both runtimes before opening a pull request.
|
|
513
|
+
|
|
514
|
+
[Read the contribution and test instructions](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/CONTRIBUTING.md)
|
|
515
|
+
|
|
516
|
+
## Code of Conduct
|
|
517
|
+
|
|
518
|
+
Treat contributors respectfully, give constructive technical feedback, and protect people's privacy. Raise conduct concerns privately with a maintainer and keep personal details out of public issues.
|
|
519
|
+
|
|
520
|
+
[Read the full Code of Conduct](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/CODE_OF_CONDUCT.md)
|
|
521
|
+
|
|
522
|
+
## Security reporting
|
|
523
|
+
|
|
524
|
+
Report vulnerabilities through GitHub's private vulnerability reporting form. Include the affected version, runtime, expected behavior, and a minimal synthetic reproduction. Keep credentials and customer data out of the report.
|
|
525
|
+
|
|
526
|
+
[Read the security reporting policy](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/SECURITY.md) · [Open a private vulnerability report](https://github.com/mkkotcherla/data-mask-policy/security/advisories/new)
|
|
527
|
+
|
|
528
|
+
## MIT license
|
|
529
|
+
|
|
530
|
+
The MIT license permits use, modification, and redistribution, including in commercial software. Preserve the copyright and permission notice when distributing the software.
|
|
531
|
+
|
|
532
|
+
[Read the MIT license](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/LICENSE)
|
|
533
|
+
|
|
534
|
+
## Author
|
|
535
|
+
|
|
536
|
+
Kotcherla Murali Krishna · [mkkotcherla](https://github.com/mkkotcherla)
|
|
537
|
+
|
|
538
|
+
## Documentation links
|
|
539
|
+
|
|
540
|
+
- [JavaScript and TypeScript API](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/api-javascript.md)
|
|
541
|
+
- [Python API](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/api-python.md)
|
|
542
|
+
- [Policy reference](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/policy-reference.md)
|
|
543
|
+
- [JSON Schema](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/specification/policy-schema.json)
|
|
544
|
+
- [Shared semantics](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/specification/semantics.md)
|
|
545
|
+
- [Masking strategies](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/masking-strategies.md)
|
|
546
|
+
- [Industry use cases](https://github.com/mkkotcherla/data-mask-policy/blob/main/docs/industry-use-cases.md)
|
|
547
|
+
- [Framework integrations](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/integrations.md)
|
|
548
|
+
- [Performance measurements](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/performance.md)
|
|
549
|
+
- [Troubleshooting](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/troubleshooting.md)
|
|
550
|
+
- [Architecture](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/architecture.md)
|
|
551
|
+
- [Adoption guide](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/adoption.md)
|
|
552
|
+
- [Security boundaries](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/docs/security.md)
|
|
553
|
+
- [Contributing](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/CONTRIBUTING.md)
|
|
554
|
+
- [Code of Conduct](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/CODE_OF_CONDUCT.md)
|
|
555
|
+
- [Security reporting](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/SECURITY.md)
|
|
556
|
+
- [MIT license](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/LICENSE)
|
|
557
|
+
- [Shared industry fixtures](https://github.com/mkkotcherla/data-mask-policy/blob/v0.1.0/examples/industry.json)
|