@neuralaxis/vibedoctor 0.1.3 → 0.2.1
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/README.md +298 -115
- package/dist/adapters/biome.js +135 -21
- package/dist/adapters/dpdp.d.ts +6 -0
- package/dist/adapters/dpdp.js +34 -0
- package/dist/adapters/index.d.ts +1 -0
- package/dist/adapters/index.js +3 -1
- package/dist/adapters/osvScanner.js +136 -17
- package/dist/adapters/presidio.js +6 -2
- package/dist/adapters/privacyDetector.d.ts +24 -1
- package/dist/adapters/privacyDetector.js +86 -2
- package/dist/adapters/shared.d.ts +6 -0
- package/dist/agentPack/templates/skills.js +159 -53
- package/dist/cli/commands/dpdp.d.ts +35 -0
- package/dist/cli/commands/dpdp.js +103 -0
- package/dist/cli/commands/init.js +105 -50
- package/dist/cli/commands/privacyReview.js +3 -4
- package/dist/cli/commands/scan.js +4 -1
- package/dist/cli/commands/setup.d.ts +13 -17
- package/dist/cli/commands/setup.js +138 -200
- package/dist/cli/index.js +84 -0
- package/dist/core/capability.d.ts +92 -0
- package/dist/core/capability.js +122 -0
- package/dist/core/config.d.ts +57 -0
- package/dist/core/config.js +194 -7
- package/dist/core/credentialHeuristics.d.ts +28 -0
- package/dist/core/credentialHeuristics.js +179 -0
- package/dist/core/engine.d.ts +21 -0
- package/dist/core/engine.js +484 -84
- package/dist/core/executable.d.ts +18 -0
- package/dist/core/executable.js +137 -0
- package/dist/core/fileRole.d.ts +24 -0
- package/dist/core/fileRole.js +125 -0
- package/dist/core/finding.d.ts +125 -1
- package/dist/core/finding.js +63 -5
- package/dist/core/findingNormalizer.d.ts +33 -0
- package/dist/core/findingNormalizer.js +171 -0
- package/dist/core/projectDetector.d.ts +13 -0
- package/dist/core/projectDetector.js +100 -15
- package/dist/core/relevance.d.ts +87 -0
- package/dist/core/relevance.js +367 -0
- package/dist/core/scanPlanner.d.ts +12 -0
- package/dist/core/scanPlanner.js +61 -29
- package/dist/core/semverLite.d.ts +27 -0
- package/dist/core/semverLite.js +163 -0
- package/dist/core/suppressions.d.ts +96 -0
- package/dist/core/suppressions.js +302 -0
- package/dist/core/toolRegistry.d.ts +58 -0
- package/dist/core/toolRegistry.js +247 -0
- package/dist/core/toolRunner.d.ts +23 -2
- package/dist/core/toolRunner.js +61 -93
- package/dist/core/toolVerification.d.ts +87 -0
- package/dist/core/toolVerification.js +370 -0
- package/dist/dpdp/artifacts.d.ts +11 -0
- package/dist/dpdp/artifacts.js +120 -0
- package/dist/dpdp/catalogue.d.ts +14 -0
- package/dist/dpdp/catalogue.js +661 -0
- package/dist/dpdp/collectors/confidence.d.ts +9 -0
- package/dist/dpdp/collectors/confidence.js +25 -0
- package/dist/dpdp/collectors/dependencies.d.ts +7 -0
- package/dist/dpdp/collectors/dependencies.js +63 -0
- package/dist/dpdp/collectors/index.d.ts +24 -0
- package/dist/dpdp/collectors/index.js +71 -0
- package/dist/dpdp/collectors/lifecycle.d.ts +2 -0
- package/dist/dpdp/collectors/lifecycle.js +202 -0
- package/dist/dpdp/collectors/optionalScanners.d.ts +14 -0
- package/dist/dpdp/collectors/optionalScanners.js +437 -0
- package/dist/dpdp/collectors/privacyBridge.d.ts +13 -0
- package/dist/dpdp/collectors/privacyBridge.js +152 -0
- package/dist/dpdp/collectors/safeguards.d.ts +5 -0
- package/dist/dpdp/collectors/safeguards.js +186 -0
- package/dist/dpdp/collectors/schema.d.ts +6 -0
- package/dist/dpdp/collectors/schema.js +122 -0
- package/dist/dpdp/collectors/shared.d.ts +10 -0
- package/dist/dpdp/collectors/shared.js +43 -0
- package/dist/dpdp/context.d.ts +28 -0
- package/dist/dpdp/context.js +195 -0
- package/dist/dpdp/dataMap.d.ts +7 -0
- package/dist/dpdp/dataMap.js +339 -0
- package/dist/dpdp/evaluators.d.ts +20 -0
- package/dist/dpdp/evaluators.js +522 -0
- package/dist/dpdp/evidence.d.ts +11 -0
- package/dist/dpdp/evidence.js +123 -0
- package/dist/dpdp/findings.d.ts +44 -0
- package/dist/dpdp/findings.js +286 -0
- package/dist/dpdp/gates.d.ts +14 -0
- package/dist/dpdp/gates.js +47 -0
- package/dist/dpdp/index.d.ts +16 -0
- package/dist/dpdp/index.js +32 -0
- package/dist/dpdp/legalSources.d.ts +10 -0
- package/dist/dpdp/legalSources.js +104 -0
- package/dist/dpdp/paths.d.ts +25 -0
- package/dist/dpdp/paths.js +85 -0
- package/dist/dpdp/report.d.ts +6 -0
- package/dist/dpdp/report.js +222 -0
- package/dist/dpdp/reviewQueue.d.ts +3 -0
- package/dist/dpdp/reviewQueue.js +88 -0
- package/dist/dpdp/scan.d.ts +26 -0
- package/dist/dpdp/scan.js +310 -0
- package/dist/dpdp/scoring.d.ts +41 -0
- package/dist/dpdp/scoring.js +237 -0
- package/dist/dpdp/types.d.ts +312 -0
- package/dist/dpdp/types.js +86 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/mcp/tools/dpdp.d.ts +11 -0
- package/dist/mcp/tools/dpdp.js +151 -0
- package/dist/mcp/tools/index.js +3 -1
- package/dist/reporters/html.js +57 -13
- package/dist/reporters/json.js +12 -1
- package/dist/reporters/markdown.js +46 -4
- package/dist/reporters/sarif.js +54 -5
- package/package.json +4 -1
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isHardcodedLiteralSignal = isHardcodedLiteralSignal;
|
|
4
|
+
exports.evaluateAllControls = evaluateAllControls;
|
|
5
|
+
exports.attachDeclaredEvidenceIds = attachDeclaredEvidenceIds;
|
|
6
|
+
exports.controlVerificationClass = controlVerificationClass;
|
|
7
|
+
const catalogue_1 = require("./catalogue");
|
|
8
|
+
function hasTag(signals, tag) {
|
|
9
|
+
return signals.filter((signal) => signal.tags.includes(tag));
|
|
10
|
+
}
|
|
11
|
+
function hasKind(signals, kind) {
|
|
12
|
+
return signals.filter((signal) => signal.kind === kind);
|
|
13
|
+
}
|
|
14
|
+
function personalDataPresent(signals) {
|
|
15
|
+
return (signals.some((signal) => signal.category && signal.category !== "unknown") ||
|
|
16
|
+
hasTag(signals, "privacy-detector").length > 0 ||
|
|
17
|
+
hasTag(signals, "pii-store").length > 0 ||
|
|
18
|
+
hasKind(signals, "collection").length > 0 ||
|
|
19
|
+
hasKind(signals, "storage").length > 0);
|
|
20
|
+
}
|
|
21
|
+
function confidenceFromSignals(matches) {
|
|
22
|
+
if (matches.some((item) => item.confidence === "high")) {
|
|
23
|
+
return "high";
|
|
24
|
+
}
|
|
25
|
+
if (matches.some((item) => item.confidence === "medium")) {
|
|
26
|
+
return "medium";
|
|
27
|
+
}
|
|
28
|
+
return matches.length > 0 ? "low" : "low";
|
|
29
|
+
}
|
|
30
|
+
function resultFor(control, status, matches, explanation, options = {}) {
|
|
31
|
+
const applicable = options.applicable ?? true;
|
|
32
|
+
let severity = control.severityRules.defaultSeverity;
|
|
33
|
+
if (status === "VIOLATED") {
|
|
34
|
+
severity = options.severity ?? control.severityRules.violatedSeverity;
|
|
35
|
+
}
|
|
36
|
+
else if (status === "PARTIAL") {
|
|
37
|
+
severity = options.severity ?? control.severityRules.partialSeverity ?? control.severityRules.defaultSeverity;
|
|
38
|
+
}
|
|
39
|
+
else if (status === "VERIFIED") {
|
|
40
|
+
severity = "info";
|
|
41
|
+
}
|
|
42
|
+
return {
|
|
43
|
+
controlId: control.id,
|
|
44
|
+
title: control.title,
|
|
45
|
+
domain: control.domain,
|
|
46
|
+
status,
|
|
47
|
+
verificationClass: control.verificationClass,
|
|
48
|
+
confidence: matches.length > 0 ? confidenceFromSignals(matches) : status === "NEEDS_CONTEXT" ? "low" : "medium",
|
|
49
|
+
severity,
|
|
50
|
+
evidenceIds: matches.map((item) => item.id),
|
|
51
|
+
explanation,
|
|
52
|
+
limitations: control.limitations,
|
|
53
|
+
remediation: status === "VERIFIED" || status === "NOT_APPLICABLE" ? undefined : options.remediation ?? control.remediation,
|
|
54
|
+
humanReviewQuestion: status === "NEEDS_CONTEXT" || status === "PARTIAL" || control.verificationClass === "HUMAN_REVIEW"
|
|
55
|
+
? options.question ?? control.humanReviewQuestions[0]
|
|
56
|
+
: options.question,
|
|
57
|
+
isNew: true,
|
|
58
|
+
applicable
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function notApplicable(control, reason) {
|
|
62
|
+
return resultFor(control, "NOT_APPLICABLE", [], reason, { applicable: false });
|
|
63
|
+
}
|
|
64
|
+
function needsContext(control, reason, matches = []) {
|
|
65
|
+
return resultFor(control, "NEEDS_CONTEXT", matches, reason);
|
|
66
|
+
}
|
|
67
|
+
function evaluateInventory(control, ctx) {
|
|
68
|
+
const matches = [
|
|
69
|
+
...hasTag(ctx.signals, "privacy-detector"),
|
|
70
|
+
...hasKind(ctx.signals, "storage"),
|
|
71
|
+
...hasKind(ctx.signals, "collection"),
|
|
72
|
+
...hasKind(ctx.signals, "external")
|
|
73
|
+
];
|
|
74
|
+
if (matches.length === 0) {
|
|
75
|
+
if (ctx.context.organization.processesPersonalData === "true") {
|
|
76
|
+
return resultFor(control, "PARTIAL", [], "Organisation declares personal-data processing but code inventory found no signals.");
|
|
77
|
+
}
|
|
78
|
+
if (ctx.context.organization.processesPersonalData === "false") {
|
|
79
|
+
return resultFor(control, "NOT_OBSERVED", [], "No personal-data signals observed; organisation declares no personal-data processing.");
|
|
80
|
+
}
|
|
81
|
+
return resultFor(control, "NOT_OBSERVED", [], "No personal-data processing signals observed in scanned paths.");
|
|
82
|
+
}
|
|
83
|
+
return resultFor(control, "VERIFIED", matches, `Observed ${matches.length} personal-data inventory signal(s).`);
|
|
84
|
+
}
|
|
85
|
+
function evaluateConsentCapture(control, ctx) {
|
|
86
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
87
|
+
return notApplicable(control, "No personal-data signals; consent capture not applicable from code.");
|
|
88
|
+
}
|
|
89
|
+
const matches = hasTag(ctx.signals, "consent-capture");
|
|
90
|
+
if (matches.length === 0) {
|
|
91
|
+
return resultFor(control, "NOT_OBSERVED", [], "Personal data appears present but no consent capture implementation signal was found.");
|
|
92
|
+
}
|
|
93
|
+
return resultFor(control, "PARTIAL", matches, "Consent capture signals found; legal adequacy of consent requires human review.");
|
|
94
|
+
}
|
|
95
|
+
function evaluateConsentMetadata(control, ctx) {
|
|
96
|
+
const consent = hasTag(ctx.signals, "consent-capture");
|
|
97
|
+
if (consent.length === 0) {
|
|
98
|
+
return notApplicable(control, "No consent capture signals to evaluate metadata against.");
|
|
99
|
+
}
|
|
100
|
+
const meta = hasTag(ctx.signals, "consent-metadata");
|
|
101
|
+
if (meta.length === 0) {
|
|
102
|
+
return resultFor(control, "VIOLATED", consent, "Consent capture exists but consent timestamp/purpose/notice metadata was not observed.");
|
|
103
|
+
}
|
|
104
|
+
const hasTs = meta.some((item) => item.tags.includes("has-timestamp"));
|
|
105
|
+
const hasPurpose = meta.some((item) => item.tags.includes("has-purpose"));
|
|
106
|
+
const hasNotice = meta.some((item) => item.tags.includes("has-notice"));
|
|
107
|
+
if (hasTs && hasPurpose && hasNotice) {
|
|
108
|
+
return resultFor(control, "VERIFIED", meta, "Consent metadata signals include timestamp, purpose, and notice version.");
|
|
109
|
+
}
|
|
110
|
+
if (hasTs || hasPurpose || hasNotice) {
|
|
111
|
+
return resultFor(control, "PARTIAL", meta, `Consent metadata incomplete (timestamp=${hasTs}, purpose=${hasPurpose}, notice=${hasNotice}).`);
|
|
112
|
+
}
|
|
113
|
+
return resultFor(control, "VIOLATED", meta, "Consent-related fields found without complete metadata markers.");
|
|
114
|
+
}
|
|
115
|
+
function evaluateWithdrawal(control, ctx) {
|
|
116
|
+
if (!personalDataPresent(ctx.signals) && hasTag(ctx.signals, "consent-capture").length === 0) {
|
|
117
|
+
return notApplicable(control, "No personal-data or consent signals observed.");
|
|
118
|
+
}
|
|
119
|
+
const matches = hasTag(ctx.signals, "consent-withdrawal");
|
|
120
|
+
if (matches.length === 0) {
|
|
121
|
+
if (hasTag(ctx.signals, "consent-capture").length > 0) {
|
|
122
|
+
return resultFor(control, "VIOLATED", hasTag(ctx.signals, "consent-capture"), "Consent capture observed without withdrawal path signals.");
|
|
123
|
+
}
|
|
124
|
+
return resultFor(control, "NOT_OBSERVED", [], "No consent withdrawal implementation signal observed.");
|
|
125
|
+
}
|
|
126
|
+
return resultFor(control, "PARTIAL", matches, "Withdrawal signals observed; ease-of-use and processor propagation need human review.");
|
|
127
|
+
}
|
|
128
|
+
function evaluateNotice(control, ctx) {
|
|
129
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
130
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
131
|
+
}
|
|
132
|
+
const matches = hasTag(ctx.signals, "notice-signal");
|
|
133
|
+
if (matches.length === 0) {
|
|
134
|
+
return resultFor(control, "NOT_OBSERVED", [], "No privacy notice / notice_version technical signals observed.");
|
|
135
|
+
}
|
|
136
|
+
return resultFor(control, "PARTIAL", matches, "Notice technical signals present; content adequacy is human-reviewed.");
|
|
137
|
+
}
|
|
138
|
+
function evaluatePurpose(control, ctx) {
|
|
139
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
140
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
141
|
+
}
|
|
142
|
+
const matches = hasTag(ctx.signals, "purpose-binding");
|
|
143
|
+
if (matches.length === 0) {
|
|
144
|
+
return resultFor(control, "NOT_OBSERVED", [], "No purpose identifier binding signals observed.");
|
|
145
|
+
}
|
|
146
|
+
return resultFor(control, "PARTIAL", matches, "Purpose identifiers observed; purpose limitation enforcement needs review.");
|
|
147
|
+
}
|
|
148
|
+
function evaluateBinaryGap(control, ctx, tag, violatedMessage, cleanMessage) {
|
|
149
|
+
if (!personalDataPresent(ctx.signals) && tag !== "hardcoded") {
|
|
150
|
+
// still evaluate hardcoded pii and some safeguards from privacy findings alone
|
|
151
|
+
}
|
|
152
|
+
const matches = hasTag(ctx.signals, tag);
|
|
153
|
+
if (matches.length > 0) {
|
|
154
|
+
return resultFor(control, "VIOLATED", matches, violatedMessage);
|
|
155
|
+
}
|
|
156
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
157
|
+
return notApplicable(control, "No personal-data signals; control not applicable from scanned code.");
|
|
158
|
+
}
|
|
159
|
+
return resultFor(control, "NOT_OBSERVED", [], cleanMessage);
|
|
160
|
+
}
|
|
161
|
+
function evaluatePiiInLogs(control, ctx) {
|
|
162
|
+
return evaluateBinaryGap(control, ctx, "pii-in-logs", "Unsanitized personal-data logging signals detected.", "No unsanitized PII-in-logs signals observed (not a proof of absence).");
|
|
163
|
+
}
|
|
164
|
+
function evaluatePiiInLlm(control, ctx) {
|
|
165
|
+
const matches = hasTag(ctx.signals, "pii-in-llm");
|
|
166
|
+
if (matches.length > 0) {
|
|
167
|
+
return resultFor(control, "VIOLATED", matches, "Personal data appears in LLM prompt/embedding paths.");
|
|
168
|
+
}
|
|
169
|
+
const llmPresent = ctx.signals.some((signal) => signal.tags.includes("llm") || /llm provider/i.test(signal.summary));
|
|
170
|
+
if (!llmPresent) {
|
|
171
|
+
return notApplicable(control, "No LLM provider signals observed.");
|
|
172
|
+
}
|
|
173
|
+
return resultFor(control, "NOT_OBSERVED", [], "LLM integrations present; no direct PII-in-prompt signals observed.");
|
|
174
|
+
}
|
|
175
|
+
function evaluateApiOverfetch(control, ctx) {
|
|
176
|
+
return evaluateBinaryGap(control, ctx, "api-overfetch", "API handlers appear to serialise whole user/customer entities.", "No API over-fetch patterns observed.");
|
|
177
|
+
}
|
|
178
|
+
function evaluateBroadSelect(control, ctx) {
|
|
179
|
+
return evaluateBinaryGap(control, ctx, "broad-db-select", "Broad database selection patterns on personal-data models detected.", "No broad personal-data select patterns observed.");
|
|
180
|
+
}
|
|
181
|
+
function evaluateBrowserStorage(control, ctx) {
|
|
182
|
+
return evaluateBinaryGap(control, ctx, "browser-storage", "Browser storage used near personal-data keywords.", "No browser-storage personal-data signals observed.");
|
|
183
|
+
}
|
|
184
|
+
function evaluateInsecureHttp(control, ctx) {
|
|
185
|
+
return evaluateBinaryGap(control, ctx, "insecure-http", "Cleartext HTTP URLs observed near personal-data context.", "No cleartext HTTP personal-data transport signals observed.");
|
|
186
|
+
}
|
|
187
|
+
function evaluatePiiInUrls(control, ctx) {
|
|
188
|
+
return evaluateBinaryGap(control, ctx, "pii-in-urls", "Personal data identifiers appear in URL/query handling.", "No query-string personal-data signals observed.");
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Only value-literal (or seed/fixture path) detections count as hardcoded production PII.
|
|
192
|
+
* Field-name / schema metadata alone must not flip this control to VIOLATED.
|
|
193
|
+
*/
|
|
194
|
+
function isHardcodedLiteralSignal(signal) {
|
|
195
|
+
if (signal.tags.includes("field-metadata") && !signal.tags.includes("value-literal")) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
if (signal.tags.includes("value-literal")) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
if (/-regex|luhn|checksum/i.test(signal.detectionMethod)) {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
// Seed/fixture path with high-confidence privacy hit still needs a value-style pattern
|
|
205
|
+
if (signal.tags.includes("fixture-path") && /regex|value|literal/i.test(signal.detectionMethod)) {
|
|
206
|
+
return true;
|
|
207
|
+
}
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
function evaluateHardcodedPii(control, ctx) {
|
|
211
|
+
const categories = new Set(["aadhaar", "pan", "passport", "financial_payment", "email", "phone"]);
|
|
212
|
+
const matches = ctx.signals.filter((signal) => signal.provenance === "privacy-detector" &&
|
|
213
|
+
signal.category &&
|
|
214
|
+
categories.has(signal.category) &&
|
|
215
|
+
isHardcodedLiteralSignal(signal) &&
|
|
216
|
+
(signal.confidence === "high" || signal.certainty === "confirmed"));
|
|
217
|
+
if (matches.length > 0) {
|
|
218
|
+
return resultFor(control, "VIOLATED", matches, "High-confidence personal data values (literals) appear embedded in source or fixtures.");
|
|
219
|
+
}
|
|
220
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
221
|
+
return notApplicable(control, "No personal-data signals; hardcoded value check not applicable.");
|
|
222
|
+
}
|
|
223
|
+
return resultFor(control, "NOT_OBSERVED", [], "No high-confidence hardcoded personal-data value literals observed (field/schema names alone do not count).");
|
|
224
|
+
}
|
|
225
|
+
function evaluateDebugExposure(control, ctx) {
|
|
226
|
+
return evaluateBinaryGap(control, ctx, "debug-exposure", "Debug/dump endpoints may expose personal records.", "No debug personal-data exposure signals observed.");
|
|
227
|
+
}
|
|
228
|
+
function evaluateWeakMasking(control, ctx) {
|
|
229
|
+
const matches = hasTag(ctx.signals, "weak-masking");
|
|
230
|
+
if (matches.length > 0) {
|
|
231
|
+
return resultFor(control, "PARTIAL", matches, "Potentially weak masking helpers detected.");
|
|
232
|
+
}
|
|
233
|
+
return resultFor(control, "NOT_OBSERVED", [], "No weak masking patterns observed.");
|
|
234
|
+
}
|
|
235
|
+
function evaluateRouteAuth(control, ctx) {
|
|
236
|
+
const matches = hasTag(ctx.signals, "missing-route-auth");
|
|
237
|
+
if (matches.length > 0) {
|
|
238
|
+
return resultFor(control, "PARTIAL", matches, "Personal-data routes without nearby authentication signals.");
|
|
239
|
+
}
|
|
240
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
241
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
242
|
+
}
|
|
243
|
+
return resultFor(control, "NOT_OBSERVED", [], "No missing-auth route signals observed; global guards may still apply.");
|
|
244
|
+
}
|
|
245
|
+
function evaluateAudit(control, ctx) {
|
|
246
|
+
const matches = hasTag(ctx.signals, "missing-audit");
|
|
247
|
+
if (matches.length > 0) {
|
|
248
|
+
return resultFor(control, "PARTIAL", matches, "Sensitive operations without nearby audit signals.");
|
|
249
|
+
}
|
|
250
|
+
return resultFor(control, "NOT_OBSERVED", [], "No missing-audit signals observed.");
|
|
251
|
+
}
|
|
252
|
+
function evaluateRetention(control, ctx) {
|
|
253
|
+
const stores = hasTag(ctx.signals, "pii-store");
|
|
254
|
+
if (stores.length === 0 && !personalDataPresent(ctx.signals)) {
|
|
255
|
+
return notApplicable(control, "No personal-data stores observed.");
|
|
256
|
+
}
|
|
257
|
+
const retention = hasTag(ctx.signals, "retention-present");
|
|
258
|
+
const missing = hasTag(ctx.signals, "missing-retention");
|
|
259
|
+
if (missing.length > 0 && retention.length === 0) {
|
|
260
|
+
return resultFor(control, "VIOLATED", missing, "Personal-data stores without retention/TTL/soft-delete fields.");
|
|
261
|
+
}
|
|
262
|
+
if (retention.length > 0 && missing.length > 0) {
|
|
263
|
+
return resultFor(control, "PARTIAL", [...retention, ...missing], "Some stores have retention signals; others do not.");
|
|
264
|
+
}
|
|
265
|
+
if (retention.length > 0) {
|
|
266
|
+
return resultFor(control, "PARTIAL", retention, "Retention/TTL signals present; policy alignment needs human review.");
|
|
267
|
+
}
|
|
268
|
+
if (stores.length > 0) {
|
|
269
|
+
return resultFor(control, "VIOLATED", stores, "Personal-data storage observed without retention mechanism signals.");
|
|
270
|
+
}
|
|
271
|
+
return resultFor(control, "NOT_OBSERVED", [], "No retention mechanism evaluation inputs found.");
|
|
272
|
+
}
|
|
273
|
+
function evaluateErasure(control, ctx) {
|
|
274
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
275
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
276
|
+
}
|
|
277
|
+
const matches = hasTag(ctx.signals, "erasure-path");
|
|
278
|
+
if (matches.length === 0) {
|
|
279
|
+
return resultFor(control, "VIOLATED", hasTag(ctx.signals, "pii-store"), "Personal data appears stored without erasure/account-deletion path signals.");
|
|
280
|
+
}
|
|
281
|
+
return resultFor(control, "PARTIAL", matches, "Erasure path signals found; backup/processor cascade needs review.");
|
|
282
|
+
}
|
|
283
|
+
function evaluateStorageWithoutDeletion(control, ctx) {
|
|
284
|
+
const stores = [...hasTag(ctx.signals, "pii-store"), ...hasKind(ctx.signals, "storage")];
|
|
285
|
+
const deletions = hasTag(ctx.signals, "erasure-path");
|
|
286
|
+
const retention = hasTag(ctx.signals, "retention-present");
|
|
287
|
+
if (stores.length === 0) {
|
|
288
|
+
return notApplicable(control, "No personal-data stores observed.");
|
|
289
|
+
}
|
|
290
|
+
if (deletions.length === 0 && retention.length === 0) {
|
|
291
|
+
return resultFor(control, "VIOLATED", stores, "Personal-data storage without visible deletion or TTL path.");
|
|
292
|
+
}
|
|
293
|
+
if (deletions.length === 0) {
|
|
294
|
+
return resultFor(control, "PARTIAL", [...stores, ...retention], "Retention fields present but no deletion path signals.");
|
|
295
|
+
}
|
|
296
|
+
return resultFor(control, "PARTIAL", [...stores, ...deletions], "Stores and deletion signals both present; completeness needs review.");
|
|
297
|
+
}
|
|
298
|
+
function evaluateAccessExport(control, ctx) {
|
|
299
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
300
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
301
|
+
}
|
|
302
|
+
const matches = hasTag(ctx.signals, "access-export");
|
|
303
|
+
if (matches.length === 0) {
|
|
304
|
+
return resultFor(control, "NOT_OBSERVED", [], "No data access/export endpoint signals observed.");
|
|
305
|
+
}
|
|
306
|
+
return resultFor(control, "PARTIAL", matches, "Access/export signals found; package completeness needs review.");
|
|
307
|
+
}
|
|
308
|
+
function evaluateCorrection(control, ctx) {
|
|
309
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
310
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
311
|
+
}
|
|
312
|
+
const matches = hasTag(ctx.signals, "correction-path");
|
|
313
|
+
if (matches.length === 0) {
|
|
314
|
+
return resultFor(control, "NOT_OBSERVED", [], "No correction/update path signals observed.");
|
|
315
|
+
}
|
|
316
|
+
return resultFor(control, "PARTIAL", matches, "Correction/update signals found; processor propagation needs review.");
|
|
317
|
+
}
|
|
318
|
+
function evaluateGrievance(control, ctx) {
|
|
319
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
320
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
321
|
+
}
|
|
322
|
+
const matches = hasTag(ctx.signals, "grievance");
|
|
323
|
+
if (matches.length === 0) {
|
|
324
|
+
return resultFor(control, "NOT_OBSERVED", [], "No grievance/privacy-contact technical signals observed.");
|
|
325
|
+
}
|
|
326
|
+
return resultFor(control, "PARTIAL", matches, "Grievance/contact signals found; operational SLAs need human review.");
|
|
327
|
+
}
|
|
328
|
+
function evaluateNomination(control, ctx) {
|
|
329
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
330
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
331
|
+
}
|
|
332
|
+
const matches = hasTag(ctx.signals, "nomination");
|
|
333
|
+
if (matches.length === 0) {
|
|
334
|
+
return resultFor(control, "NOT_OBSERVED", [], "No nomination implementation signals observed.");
|
|
335
|
+
}
|
|
336
|
+
return resultFor(control, "PARTIAL", matches, "Nomination signals found; legal applicability needs confirmation.");
|
|
337
|
+
}
|
|
338
|
+
function evaluateChildren(control, ctx) {
|
|
339
|
+
const orgChildren = ctx.context.organization.processesChildrenData;
|
|
340
|
+
const matches = hasTag(ctx.signals, "childrens-data");
|
|
341
|
+
if (orgChildren === "false" && matches.length === 0) {
|
|
342
|
+
return notApplicable(control, "Organisation declares no children's data processing and no signals observed.");
|
|
343
|
+
}
|
|
344
|
+
if (matches.length === 0) {
|
|
345
|
+
if (orgChildren === "true") {
|
|
346
|
+
return resultFor(control, "PARTIAL", [], "Organisation declares children's data processing but no age-gate signals observed.");
|
|
347
|
+
}
|
|
348
|
+
return resultFor(control, "NOT_OBSERVED", [], "No children's data signals observed.");
|
|
349
|
+
}
|
|
350
|
+
return resultFor(control, "PARTIAL", matches, "Children's data / age signals observed; verification strength needs review.");
|
|
351
|
+
}
|
|
352
|
+
function evaluateGuardian(control, ctx) {
|
|
353
|
+
const childSignals = hasTag(ctx.signals, "childrens-data");
|
|
354
|
+
const guardian = hasTag(ctx.signals, "guardian-consent");
|
|
355
|
+
if (childSignals.length === 0 && ctx.context.organization.processesChildrenData !== "true") {
|
|
356
|
+
return notApplicable(control, "No children's data processing signals.");
|
|
357
|
+
}
|
|
358
|
+
if (guardian.length === 0) {
|
|
359
|
+
return resultFor(control, "VIOLATED", childSignals, "Children's data signals present without guardian/parental consent implementation signals.");
|
|
360
|
+
}
|
|
361
|
+
return resultFor(control, "PARTIAL", guardian, "Guardian consent signals found; identity verification needs human review.");
|
|
362
|
+
}
|
|
363
|
+
function evaluateProcessors(control, ctx) {
|
|
364
|
+
const matches = hasKind(ctx.signals, "external");
|
|
365
|
+
if (matches.length === 0) {
|
|
366
|
+
return resultFor(control, "NOT_OBSERVED", [], "No external processor SDK/manifest signals observed.");
|
|
367
|
+
}
|
|
368
|
+
return resultFor(control, "VERIFIED", matches, `Observed ${matches.length} external recipient/processor technical signal(s).`);
|
|
369
|
+
}
|
|
370
|
+
function evaluateCrossBorder(control, ctx) {
|
|
371
|
+
const matches = hasTag(ctx.signals, "cross-border");
|
|
372
|
+
const external = hasKind(ctx.signals, "external");
|
|
373
|
+
if (ctx.context.organization.hasCrossBorderTransfer === "false" && matches.length === 0) {
|
|
374
|
+
return notApplicable(control, "Organisation declares no cross-border transfer and no region signals observed.");
|
|
375
|
+
}
|
|
376
|
+
if (matches.length > 0) {
|
|
377
|
+
return resultFor(control, "PARTIAL", matches, "Cross-border/region configuration signals observed.");
|
|
378
|
+
}
|
|
379
|
+
if (external.length > 0) {
|
|
380
|
+
return resultFor(control, "PARTIAL", external, "External services present; transfer geography not fully determined from code.");
|
|
381
|
+
}
|
|
382
|
+
return resultFor(control, "NOT_OBSERVED", [], "No cross-border technical signals observed.");
|
|
383
|
+
}
|
|
384
|
+
function evaluateBreach(control, ctx) {
|
|
385
|
+
if (!personalDataPresent(ctx.signals)) {
|
|
386
|
+
return notApplicable(control, "No personal-data signals observed.");
|
|
387
|
+
}
|
|
388
|
+
const matches = hasTag(ctx.signals, "breach-preparedness");
|
|
389
|
+
if (matches.length === 0) {
|
|
390
|
+
return resultFor(control, "NOT_OBSERVED", [], "No breach/incident technical signals observed.");
|
|
391
|
+
}
|
|
392
|
+
return resultFor(control, "PARTIAL", matches, "Breach-related signals found; operational readiness needs human review.");
|
|
393
|
+
}
|
|
394
|
+
function evaluateRightsTracking(control, ctx) {
|
|
395
|
+
const rights = [...hasTag(ctx.signals, "access-export"), ...hasTag(ctx.signals, "correction-path"), ...hasTag(ctx.signals, "erasure-path")];
|
|
396
|
+
if (rights.length === 0) {
|
|
397
|
+
return notApplicable(control, "No rights endpoints observed to evaluate tracking against.");
|
|
398
|
+
}
|
|
399
|
+
const tracking = hasTag(ctx.signals, "rights-tracking");
|
|
400
|
+
if (tracking.length === 0) {
|
|
401
|
+
return resultFor(control, "PARTIAL", rights, "Rights endpoints found without request tracking signals.");
|
|
402
|
+
}
|
|
403
|
+
return resultFor(control, "PARTIAL", [...rights, ...tracking], "Rights tracking signals present; identity proofing needs review.");
|
|
404
|
+
}
|
|
405
|
+
function evaluateUnprotectedExport(control, ctx) {
|
|
406
|
+
const matches = hasTag(ctx.signals, "unprotected-export");
|
|
407
|
+
if (matches.length > 0) {
|
|
408
|
+
return resultFor(control, "VIOLATED", matches, "Export/access endpoints without nearby authentication signals.");
|
|
409
|
+
}
|
|
410
|
+
if (hasTag(ctx.signals, "access-export").length === 0) {
|
|
411
|
+
return notApplicable(control, "No export endpoints observed.");
|
|
412
|
+
}
|
|
413
|
+
return resultFor(control, "NOT_OBSERVED", [], "Export endpoints present; no missing-auth export signals observed.");
|
|
414
|
+
}
|
|
415
|
+
function evaluateThirdPartyUserObject(control, ctx) {
|
|
416
|
+
return evaluateBinaryGap(control, ctx, "third-party-user-object", "Whole user/profile objects may be sent to third-party SDKs.", "No whole-user third-party shipment patterns observed.");
|
|
417
|
+
}
|
|
418
|
+
function evaluateSdf(control, ctx) {
|
|
419
|
+
if (ctx.context.organization.isSignificantDataFiduciary === "false") {
|
|
420
|
+
return notApplicable(control, "Organisation declares it is not a Significant Data Fiduciary.");
|
|
421
|
+
}
|
|
422
|
+
const dpo = hasTag(ctx.signals, "grievance").filter((item) => /dpo|data protection officer/i.test(item.summary));
|
|
423
|
+
if (ctx.context.organization.isSignificantDataFiduciary === "true") {
|
|
424
|
+
if (dpo.length === 0) {
|
|
425
|
+
return resultFor(control, "PARTIAL", [], "SDF declared; limited technical DPO/audit signals observed.");
|
|
426
|
+
}
|
|
427
|
+
return resultFor(control, "PARTIAL", dpo, "SDF declared with some technical signals; audits/DPIA need human evidence.");
|
|
428
|
+
}
|
|
429
|
+
return needsContext(control, "Significant Data Fiduciary status is unknown; cannot verify Section 10 technical obligations from code alone.");
|
|
430
|
+
}
|
|
431
|
+
function evaluateHumanReview(control, ctx) {
|
|
432
|
+
const relatedDeclared = ctx.declared.filter((item) => item.relatedControls.includes(control.id));
|
|
433
|
+
if (relatedDeclared.length > 0) {
|
|
434
|
+
return resultFor(control, "NEEDS_CONTEXT", [], `Declared evidence present (${relatedDeclared.map((item) => item.id).join(", ")}) but not deterministic verification.`, { question: control.humanReviewQuestions[0] });
|
|
435
|
+
}
|
|
436
|
+
return needsContext(control, control.humanReviewQuestions[0] ?? "Human/organisational review required.");
|
|
437
|
+
}
|
|
438
|
+
function evaluateDeclaredEvidence(control, ctx) {
|
|
439
|
+
const related = ctx.declared.filter((item) => item.relatedControls.includes(control.id) || control.id === "DPDP-PROC-002");
|
|
440
|
+
const processors = hasKind(ctx.signals, "external");
|
|
441
|
+
if (control.id === "DPDP-PROC-002") {
|
|
442
|
+
if (processors.length === 0) {
|
|
443
|
+
return notApplicable(control, "No processors observed.");
|
|
444
|
+
}
|
|
445
|
+
if (related.length === 0) {
|
|
446
|
+
return resultFor(control, "NEEDS_CONTEXT", processors, "External processors observed; processor contracts are not established from code (declared evidence required).");
|
|
447
|
+
}
|
|
448
|
+
return resultFor(control, "PARTIAL", processors, "Declared processor-contract assertions exist; they are not deterministic verification.", { question: control.humanReviewQuestions[0] });
|
|
449
|
+
}
|
|
450
|
+
return evaluateHumanReview(control, ctx);
|
|
451
|
+
}
|
|
452
|
+
const EVALUATORS = {
|
|
453
|
+
"inventory-personal-data": evaluateInventory,
|
|
454
|
+
"notice-signals": evaluateNotice,
|
|
455
|
+
"consent-capture": evaluateConsentCapture,
|
|
456
|
+
"consent-metadata": evaluateConsentMetadata,
|
|
457
|
+
"consent-withdrawal": evaluateWithdrawal,
|
|
458
|
+
"purpose-binding": evaluatePurpose,
|
|
459
|
+
"api-overfetch": evaluateApiOverfetch,
|
|
460
|
+
"broad-db-select": evaluateBroadSelect,
|
|
461
|
+
"correction-path": evaluateCorrection,
|
|
462
|
+
"pii-in-logs": evaluatePiiInLogs,
|
|
463
|
+
"pii-in-llm": evaluatePiiInLlm,
|
|
464
|
+
"pii-in-urls": evaluatePiiInUrls,
|
|
465
|
+
"browser-storage-pii": evaluateBrowserStorage,
|
|
466
|
+
"insecure-http": evaluateInsecureHttp,
|
|
467
|
+
"route-auth": evaluateRouteAuth,
|
|
468
|
+
"hardcoded-pii": evaluateHardcodedPii,
|
|
469
|
+
"debug-exposure": evaluateDebugExposure,
|
|
470
|
+
"weak-masking": evaluateWeakMasking,
|
|
471
|
+
"audit-signals": evaluateAudit,
|
|
472
|
+
"breach-preparedness": evaluateBreach,
|
|
473
|
+
"retention-mechanism": evaluateRetention,
|
|
474
|
+
"erasure-path": evaluateErasure,
|
|
475
|
+
"storage-without-deletion": evaluateStorageWithoutDeletion,
|
|
476
|
+
"access-export": evaluateAccessExport,
|
|
477
|
+
"grievance-handling": evaluateGrievance,
|
|
478
|
+
"nomination-signal": evaluateNomination,
|
|
479
|
+
"childrens-data": evaluateChildren,
|
|
480
|
+
"guardian-consent": evaluateGuardian,
|
|
481
|
+
"external-processors": evaluateProcessors,
|
|
482
|
+
"cross-border-signals": evaluateCrossBorder,
|
|
483
|
+
"sdf-signals": evaluateSdf,
|
|
484
|
+
"rights-request-tracking": evaluateRightsTracking,
|
|
485
|
+
"unprotected-export": evaluateUnprotectedExport,
|
|
486
|
+
"third-party-user-object": evaluateThirdPartyUserObject
|
|
487
|
+
};
|
|
488
|
+
function evaluateAllControls(ctx) {
|
|
489
|
+
return catalogue_1.DPDP_CONTROLS.map((control) => {
|
|
490
|
+
try {
|
|
491
|
+
if (control.evaluatorId && EVALUATORS[control.evaluatorId]) {
|
|
492
|
+
return EVALUATORS[control.evaluatorId](control, ctx);
|
|
493
|
+
}
|
|
494
|
+
if (control.verificationClass === "DECLARED_EVIDENCE") {
|
|
495
|
+
return evaluateDeclaredEvidence(control, ctx);
|
|
496
|
+
}
|
|
497
|
+
if (control.verificationClass === "HUMAN_REVIEW") {
|
|
498
|
+
return evaluateHumanReview(control, ctx);
|
|
499
|
+
}
|
|
500
|
+
return needsContext(control, "No deterministic evaluator registered for this control.");
|
|
501
|
+
}
|
|
502
|
+
catch (error) {
|
|
503
|
+
return resultFor(control, "ERROR", [], `Evaluator error: ${error instanceof Error ? error.message : String(error)}`);
|
|
504
|
+
}
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
function attachDeclaredEvidenceIds(results, declared) {
|
|
508
|
+
return results.map((result) => {
|
|
509
|
+
const related = declared.filter((item) => item.relatedControls.includes(result.controlId));
|
|
510
|
+
if (related.length === 0) {
|
|
511
|
+
return result;
|
|
512
|
+
}
|
|
513
|
+
return {
|
|
514
|
+
...result,
|
|
515
|
+
evidenceIds: [...result.evidenceIds, ...related.map((item) => `declared:${item.id}`)],
|
|
516
|
+
explanation: `${result.explanation} Declared assertions: ${related.map((item) => item.id).join(", ")} (not deterministic).`
|
|
517
|
+
};
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
function controlVerificationClass(controlId) {
|
|
521
|
+
return (0, catalogue_1.getControlById)(controlId)?.verificationClass;
|
|
522
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { EvidenceItem, TechnicalSignalBag } from "./types";
|
|
2
|
+
export declare function stableEvidenceId(parts: Array<string | number | undefined>): string;
|
|
3
|
+
export declare function evidenceFromSignal(signal: TechnicalSignalBag, relatedControls?: string[]): EvidenceItem;
|
|
4
|
+
/**
|
|
5
|
+
* Ensure no raw PII-like tokens leak into serialized evidence.
|
|
6
|
+
* Always fail-closed for regulated identifiers and common contact PII,
|
|
7
|
+
* even when `checks.dpdp.maskExamples` is false.
|
|
8
|
+
*/
|
|
9
|
+
export declare function sanitizeEvidenceForOutput(item: EvidenceItem): EvidenceItem;
|
|
10
|
+
/** Fail-closed redaction for artifact/report output. */
|
|
11
|
+
export declare function redactLikelyPii(value: string): string;
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stableEvidenceId = stableEvidenceId;
|
|
4
|
+
exports.evidenceFromSignal = evidenceFromSignal;
|
|
5
|
+
exports.sanitizeEvidenceForOutput = sanitizeEvidenceForOutput;
|
|
6
|
+
exports.redactLikelyPii = redactLikelyPii;
|
|
7
|
+
const node_crypto_1 = require("node:crypto");
|
|
8
|
+
function stableEvidenceId(parts) {
|
|
9
|
+
const payload = parts.map((part) => String(part ?? "")).join("|");
|
|
10
|
+
return `ev-${(0, node_crypto_1.createHash)("sha1").update(payload).digest("hex").slice(0, 16)}`;
|
|
11
|
+
}
|
|
12
|
+
function evidenceFromSignal(signal, relatedControls = signal.relatedControls ?? []) {
|
|
13
|
+
return {
|
|
14
|
+
id: signal.id.startsWith("ev-") ? signal.id : stableEvidenceId([signal.kind, signal.file, signal.line, signal.summary]),
|
|
15
|
+
kind: mapSignalKind(signal.kind),
|
|
16
|
+
dataCategory: signal.category,
|
|
17
|
+
file: signal.file,
|
|
18
|
+
line: signal.line,
|
|
19
|
+
symbol: signal.symbol,
|
|
20
|
+
field: signal.field,
|
|
21
|
+
detectionMethod: signal.detectionMethod,
|
|
22
|
+
confidence: signal.confidence,
|
|
23
|
+
confidenceScore: signal.confidenceScore,
|
|
24
|
+
provenance: signal.provenance ?? "deterministic",
|
|
25
|
+
relatedControls,
|
|
26
|
+
certainty: signal.certainty ?? defaultCertainty(signal),
|
|
27
|
+
summary: signal.summary,
|
|
28
|
+
snippet: signal.snippet,
|
|
29
|
+
tags: signal.tags
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function defaultCertainty(signal) {
|
|
33
|
+
if (signal.provenance === "declared") {
|
|
34
|
+
return "declared";
|
|
35
|
+
}
|
|
36
|
+
if (signal.confidence === "high") {
|
|
37
|
+
return "confirmed";
|
|
38
|
+
}
|
|
39
|
+
return "inferred";
|
|
40
|
+
}
|
|
41
|
+
function mapSignalKind(kind) {
|
|
42
|
+
switch (kind) {
|
|
43
|
+
case "category":
|
|
44
|
+
case "personal_data_category":
|
|
45
|
+
return "personal_data_category";
|
|
46
|
+
case "field":
|
|
47
|
+
case "column":
|
|
48
|
+
case "field_or_column":
|
|
49
|
+
return "field_or_column";
|
|
50
|
+
case "collection":
|
|
51
|
+
case "collection_source":
|
|
52
|
+
return "collection_source";
|
|
53
|
+
case "storage":
|
|
54
|
+
case "storage_location":
|
|
55
|
+
return "storage_location";
|
|
56
|
+
case "log":
|
|
57
|
+
case "telemetry":
|
|
58
|
+
case "log_or_telemetry":
|
|
59
|
+
return "log_or_telemetry";
|
|
60
|
+
case "external":
|
|
61
|
+
case "external_recipient":
|
|
62
|
+
return "external_recipient";
|
|
63
|
+
case "retention":
|
|
64
|
+
case "retention_mechanism":
|
|
65
|
+
return "retention_mechanism";
|
|
66
|
+
case "deletion":
|
|
67
|
+
case "deletion_path":
|
|
68
|
+
return "deletion_path";
|
|
69
|
+
case "rights":
|
|
70
|
+
case "rights_endpoint":
|
|
71
|
+
return "rights_endpoint";
|
|
72
|
+
case "consent":
|
|
73
|
+
case "consent_signal":
|
|
74
|
+
return "consent_signal";
|
|
75
|
+
case "safeguard_gap":
|
|
76
|
+
return "safeguard_gap";
|
|
77
|
+
case "protection":
|
|
78
|
+
case "protection_control":
|
|
79
|
+
return "protection_control";
|
|
80
|
+
case "declared":
|
|
81
|
+
case "declared_assertion":
|
|
82
|
+
return "declared_assertion";
|
|
83
|
+
case "skip":
|
|
84
|
+
case "capability":
|
|
85
|
+
return "skip_or_capability";
|
|
86
|
+
default:
|
|
87
|
+
return "processing_operation";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Ensure no raw PII-like tokens leak into serialized evidence.
|
|
92
|
+
* Always fail-closed for regulated identifiers and common contact PII,
|
|
93
|
+
* even when `checks.dpdp.maskExamples` is false.
|
|
94
|
+
*/
|
|
95
|
+
function sanitizeEvidenceForOutput(item) {
|
|
96
|
+
return {
|
|
97
|
+
...item,
|
|
98
|
+
summary: redactLikelyPii(item.summary),
|
|
99
|
+
snippet: item.snippet ? redactLikelyPii(item.snippet) : undefined
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
/** Fail-closed redaction for artifact/report output. */
|
|
103
|
+
function redactLikelyPii(value) {
|
|
104
|
+
let text = value;
|
|
105
|
+
// Redact labelled literals first so names, addresses and identifiers that do
|
|
106
|
+
// not have a universally reliable standalone shape never reach artifacts.
|
|
107
|
+
text = text.replace(/\b(name|full_?name|first_?name|last_?name|address|passport|voter_?id|driv(?:ing|er)_?licen[cs]e|date_?of_?birth|dob|medical|health|biometric|api_?key|password|secret|token)\b(\s*[:=]\s*)["'`]([^"'`\r\n]+)["'`]/gi, (_match, label, separator) => `${label}${separator}"[redacted]"`);
|
|
108
|
+
text = text.replace(/\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,}\b/gi, "[email]");
|
|
109
|
+
text = text.replace(/\b[A-Z]{5}[0-9]{4}[A-Z]\b/gi, "[pan]");
|
|
110
|
+
text = text.replace(/\b[2-9]\d{3}[\s-]?\d{4}[\s-]?\d{4}\b/g, "[aadhaar]");
|
|
111
|
+
text = text.replace(/\b[A-Z][0-9]{7}\b/gi, "[passport]");
|
|
112
|
+
text = text.replace(/\b[A-Z]{3}[0-9]{7}\b/gi, "[voter-id]");
|
|
113
|
+
text = text.replace(/\b[A-Z]{2}[ -]?[0-9]{2}[ -]?[0-9A-Z]{7,13}\b/gi, "[driving-licence]");
|
|
114
|
+
text = text.replace(/\b(?:\d[ -]?){13,19}\b/g, "[card]");
|
|
115
|
+
text = text.replace(/\b(?:\d{1,3}\.){3}\d{1,3}\b/g, "[ip-address]");
|
|
116
|
+
text = text.replace(/\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\b/g, "[jwt]");
|
|
117
|
+
text = text.replace(/\bBearer\s+[A-Za-z0-9._~+\/-]+=*\b/gi, "Bearer [token]");
|
|
118
|
+
text = text.replace(/(?:\+\d{1,3}[-.\s]?)?(?:\(?\d{3,5}\)?[-.\s]?){2,}\d{3,4}/g, (match) => {
|
|
119
|
+
const digits = match.replace(/\D/g, "");
|
|
120
|
+
return digits.length >= 10 && digits.length <= 14 ? "[phone]" : match;
|
|
121
|
+
});
|
|
122
|
+
return text.slice(0, 2_000);
|
|
123
|
+
}
|