fieldshield 1.0.0
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.
- package/CHANGELOG.md +101 -0
- package/LICENSE +21 -0
- package/README.md +1045 -0
- package/THREAT_MODEL.md +360 -0
- package/dist/assets/fieldshield.css +1 -0
- package/dist/assets/fieldshield.worker.js +1 -0
- package/dist/components/FieldShieldInput.d.ts +330 -0
- package/dist/fieldshield.js +790 -0
- package/dist/fieldshield.umd.cjs +4 -0
- package/dist/hooks/useFieldShield.d.ts +157 -0
- package/dist/hooks/useSecurityLog.d.ts +139 -0
- package/dist/index.d.cts +23 -0
- package/dist/index.d.ts +23 -0
- package/dist/patterns.d.ts +105 -0
- package/dist/utils/collectSecureValue.d.ts +102 -0
- package/package.json +107 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to FieldShield are documented here.
|
|
4
|
+
|
|
5
|
+
This project follows [Semantic Versioning](https://semver.org/):
|
|
6
|
+
- **Patch** (`1.0.x`) — bug fixes, false positive/negative corrections to existing patterns
|
|
7
|
+
- **Minor** (`1.x.0`) — new patterns, new props, new features — backwards compatible
|
|
8
|
+
- **Major** (`x.0.0`) — breaking API changes
|
|
9
|
+
|
|
10
|
+
Pattern updates are **minor releases**, not patches. A new pattern could start flagging content that was previously clean. Review pattern changes before upgrading.
|
|
11
|
+
|
|
12
|
+
---
|
|
13
|
+
|
|
14
|
+
## [1.0.0] — 2026
|
|
15
|
+
|
|
16
|
+
Initial public release.
|
|
17
|
+
|
|
18
|
+
### Architecture
|
|
19
|
+
|
|
20
|
+
- Web Worker isolation — real input value (`internalTruth`) stored exclusively in a dedicated worker thread, never in the DOM
|
|
21
|
+
- DOM scrambling — `input.value` always contains scrambled `x` characters, never the real value
|
|
22
|
+
- MessageChannel point-to-point delivery for `getSecureValue()` — browser extensions monitoring `postMessage` cannot intercept the response
|
|
23
|
+
- Clipboard interception — copy and cut events write masked `█` characters to the clipboard, not the real value
|
|
24
|
+
- Paste interception — paste events are scanned before the browser inserts content; `onSensitivePaste` returning `false` blocks the paste entirely
|
|
25
|
+
- Worker initialization fallback — if the Worker constructor throws (e.g. strict CSP), the component automatically falls back to `a11yMode`
|
|
26
|
+
- Worker message payload validation — UPDATE messages with invalid payload shapes are silently discarded
|
|
27
|
+
|
|
28
|
+
### Props
|
|
29
|
+
|
|
30
|
+
- `label` — visible label text linked via `htmlFor`/`id`
|
|
31
|
+
- `type` — `"text"` or `"textarea"` with auto-grow support
|
|
32
|
+
- `placeholder` — forwarded to native element
|
|
33
|
+
- `a11yMode` — renders `type="password"` for WCAG 2.1 AA / Section 508 compliance; auto-activated on worker init failure
|
|
34
|
+
- `customPatterns` — additional patterns layered on top of built-in defaults; use with `OPT_IN_PATTERNS` for field-specific opt-in patterns
|
|
35
|
+
- `maxProcessLength` — blocks input exceeding the character limit (default `100_000`); blocking rather than truncating prevents blind spots
|
|
36
|
+
- `onMaxLengthExceeded` — called when input is blocked by `maxProcessLength`
|
|
37
|
+
- `onSensitiveCopyAttempt` — fired on copy/cut when sensitive patterns are present
|
|
38
|
+
- `onSensitivePaste` — fired on paste when sensitive patterns are detected; return `false` to block the paste
|
|
39
|
+
- `onWorkerError` — fired when the worker encounters a runtime error
|
|
40
|
+
- `onChange` — fires after each worker UPDATE with masked value and findings
|
|
41
|
+
- `disabled`, `required`, `maxLength`, `rows`, `inputMode`, `className`, `style`, `onFocus`, `onBlur`
|
|
42
|
+
|
|
43
|
+
### Ref methods
|
|
44
|
+
|
|
45
|
+
- `getSecureValue()` — retrieves real value from worker memory via private MessageChannel; rejects after 3 second timeout
|
|
46
|
+
- `purge()` — zeros `internalTruth` in worker memory
|
|
47
|
+
|
|
48
|
+
### Hooks and utilities
|
|
49
|
+
|
|
50
|
+
- `useFieldShield` — hook managing worker lifecycle, pattern detection, and secure value retrieval
|
|
51
|
+
- `useSecurityLog` — capped, auto-timestamped audit event log with `makeClipboardHandler`, `pushEvent`, `clearLog`
|
|
52
|
+
- `collectSecureValues` — parallel `getSecureValue()` across multiple fields via `Promise.allSettled`
|
|
53
|
+
- `purgeSecureValues` — simultaneous `purge()` across multiple fields
|
|
54
|
+
|
|
55
|
+
### Built-in patterns
|
|
56
|
+
|
|
57
|
+
**13 active by default** — enabled on every `FieldShieldInput` without configuration.
|
|
58
|
+
|
|
59
|
+
**PII (6):** `SSN`, `EMAIL`, `PHONE`, `CREDIT_CARD`, `DATE_OF_BIRTH`, `TAX_ID`
|
|
60
|
+
|
|
61
|
+
**Healthcare (1):** `UK_NIN`
|
|
62
|
+
|
|
63
|
+
**Credentials (6):** `AI_API_KEY`, `AWS_ACCESS_KEY`, `GITHUB_TOKEN`, `STRIPE_KEY`, `JWT`, `PRIVATE_KEY_BLOCK`
|
|
64
|
+
|
|
65
|
+
**Opt-in (5):** `IBAN`, `DEA_NUMBER`, `SWIFT_BIC`, `NPI_NUMBER`, `PASSPORT_NUMBER` — exported via `OPT_IN_PATTERNS`, not active by default. These patterns produce unacceptably high false positive rates in free-text and clinical note fields. Use via `customPatterns` only on fields where the specific data type is expected.
|
|
66
|
+
|
|
67
|
+
```tsx
|
|
68
|
+
import { OPT_IN_PATTERNS } from "fieldshield";
|
|
69
|
+
|
|
70
|
+
<FieldShieldInput
|
|
71
|
+
label="DEA Number"
|
|
72
|
+
customPatterns={[{ name: "DEA_NUMBER", regex: OPT_IN_PATTERNS.DEA_NUMBER }]}
|
|
73
|
+
/>
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
### Security
|
|
77
|
+
|
|
78
|
+
- No-network guarantee — worker contains zero `fetch()`, `XMLHttpRequest`, `WebSocket`, `EventSource`, or `sendBeacon()` calls
|
|
79
|
+
- CSP guidance — `worker-src 'self' blob:` recommended for regulated deployments
|
|
80
|
+
- `THREAT_MODEL.md` — full threat model with 9 mitigated threats, 9 unmitigated threats, environment assumptions, residual risk table, and compliance mapping
|
|
81
|
+
|
|
82
|
+
### Documentation
|
|
83
|
+
|
|
84
|
+
- `README.md` — full API documentation, framework compatibility (Vite, Webpack 4/5, Next.js, SSR), form library integration (RHF, Formik, Zod), CSP guidance, known limitations, compliance notes
|
|
85
|
+
- `THREAT_MODEL.md` — threat model for security engineers and compliance auditors
|
|
86
|
+
- `LICENSE` — MIT
|
|
87
|
+
|
|
88
|
+
### Test coverage
|
|
89
|
+
|
|
90
|
+
- Vitest unit tests — 454 tests across 7 modules
|
|
91
|
+
- Playwright e2e tests — 38 tests covering real clipboard, worker isolation, DOM protection, worker fallback, accessibility
|
|
92
|
+
|
|
93
|
+
### Known limitations
|
|
94
|
+
|
|
95
|
+
- `realValueRef` exists on the main thread while the user is actively typing — readable by debuggers and privileged extensions
|
|
96
|
+
- No `id` prop override — `useId()` generates stable IDs automatically
|
|
97
|
+
- `name` prop not supported — native form submission not supported; use `getSecureValue()` on submit
|
|
98
|
+
- `onCopy`/`onCut` props not forwarded — use `onSensitiveCopyAttempt` instead
|
|
99
|
+
- IME composition (CJK input) not supported — use `a11yMode` as fallback
|
|
100
|
+
- No cross-field PHI combination detection — planned for v2.0
|
|
101
|
+
- Names and addresses cannot be detected with regex — server-side NER required
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Anurag Nedunuri
|
|
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.
|