@neuralaxis/vibedoctor 0.1.2 → 0.2.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/README.md +215 -102
- package/dist/adapters/biome.d.ts +1 -1
- package/dist/adapters/biome.js +7 -4
- package/dist/adapters/coveragePy.js +3 -0
- package/dist/adapters/deptry.js +21 -2
- 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/knip.js +29 -4
- package/dist/adapters/lizard.d.ts +1 -1
- package/dist/adapters/lizard.js +51 -2
- package/dist/adapters/osvScanner.js +14 -2
- package/dist/adapters/presidio.js +3 -1
- package/dist/adapters/privacyDetector.d.ts +24 -1
- package/dist/adapters/privacyDetector.js +91 -7
- package/dist/adapters/ruff.d.ts +1 -1
- package/dist/adapters/ruff.js +4 -1
- package/dist/adapters/semgrep.d.ts +1 -1
- package/dist/adapters/semgrep.js +17 -3
- package/dist/adapters/shared.d.ts +7 -0
- package/dist/adapters/shared.js +22 -0
- package/dist/adapters/tsc.js +43 -18
- package/dist/adapters/vulture.d.ts +1 -1
- package/dist/adapters/vulture.js +25 -6
- package/dist/agentPack/templates/index.js +7 -4
- package/dist/agentPack/templates/skills.js +156 -44
- package/dist/cli/commands/agentPlan.js +9 -1
- package/dist/cli/commands/dpdp.d.ts +35 -0
- package/dist/cli/commands/dpdp.js +103 -0
- package/dist/cli/commands/init.js +12 -4
- package/dist/cli/commands/scan.d.ts +1 -1
- package/dist/cli/commands/scan.js +8 -1
- package/dist/cli/commands/setup.js +4 -2
- package/dist/cli/commands/tool.d.ts +4 -0
- package/dist/cli/commands/tool.js +11 -0
- package/dist/cli/index.js +96 -0
- package/dist/core/config.d.ts +27 -0
- package/dist/core/config.js +118 -5
- package/dist/core/engine.d.ts +32 -1
- package/dist/core/engine.js +195 -30
- package/dist/core/finding.d.ts +1 -1
- package/dist/core/finding.js +1 -0
- package/dist/core/projectDetector.d.ts +1 -1
- package/dist/core/projectDetector.js +29 -12
- package/dist/core/scanPlanner.js +10 -2
- package/dist/core/toolRunner.d.ts +1 -0
- package/dist/core/toolRunner.js +73 -11
- 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 +347 -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 +14 -0
- package/dist/dpdp/findings.js +99 -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 +31 -0
- package/dist/dpdp/scoring.js +211 -0
- package/dist/dpdp/types.d.ts +294 -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/mcp/tools/shared.js +8 -1
- package/dist/reporters/agent.js +8 -0
- package/dist/reporters/html.js +4 -2
- package/dist/reporters/json.js +8 -1
- package/dist/reporters/markdown.js +8 -1
- package/package.json +9 -2
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectSafeguardSignals = collectSafeguardSignals;
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
/**
|
|
6
|
+
* Safeguard / gap detectors with multi-line depth for logs, LLM prompts, and route auth.
|
|
7
|
+
*/
|
|
8
|
+
function collectSafeguardSignals(signals, file, content, lines) {
|
|
9
|
+
const globalAuth = (0, shared_1.fileHasGlobalAuth)(content);
|
|
10
|
+
if (/\b(localStorage|sessionStorage)\.(setItem|getItem)\b/.test(content) || /document\.cookie\s*=/.test(content)) {
|
|
11
|
+
if (shared_1.PII_KEYWORD.test(content)) {
|
|
12
|
+
const lineIndex = lines.findIndex((line) => /localStorage|sessionStorage|document\.cookie/.test(line));
|
|
13
|
+
(0, shared_1.pushSignal)(signals, {
|
|
14
|
+
kind: "safeguard_gap",
|
|
15
|
+
file,
|
|
16
|
+
line: lineIndex >= 0 ? lineIndex + 1 : undefined,
|
|
17
|
+
summary: "Browser storage used near personal-data keywords",
|
|
18
|
+
confidence: "medium",
|
|
19
|
+
tags: ["browser-storage"],
|
|
20
|
+
detectionMethod: "browser-storage-pattern",
|
|
21
|
+
relatedControls: ["DPDP-SEC-004"]
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
for (const [index, line] of lines.entries()) {
|
|
26
|
+
const lineNumber = index + 1;
|
|
27
|
+
const window = (0, shared_1.windowAround)(lines, index, 3, 4);
|
|
28
|
+
const deepWindow = (0, shared_1.windowAround)(lines, index, 8, 10);
|
|
29
|
+
// Multi-line logger: call opens here, PII args on following lines
|
|
30
|
+
if (/\b(console|logger|log)\.(log|info|warn|error|debug)\s*\(/i.test(line)) {
|
|
31
|
+
const logBlock = (0, shared_1.windowAround)(lines, index, 0, 6);
|
|
32
|
+
if (shared_1.PII_KEYWORD.test(logBlock) &&
|
|
33
|
+
!/\b(redact|mask|safe|anon|hide|hash|encrypt|obfuscate)\b/i.test(logBlock)) {
|
|
34
|
+
(0, shared_1.pushSignal)(signals, {
|
|
35
|
+
kind: "safeguard_gap",
|
|
36
|
+
file,
|
|
37
|
+
line: lineNumber,
|
|
38
|
+
summary: "Potential PII in logger call (multi-line)",
|
|
39
|
+
confidence: "medium",
|
|
40
|
+
tags: ["pii-in-logs"],
|
|
41
|
+
detectionMethod: "logger-multiline-pattern",
|
|
42
|
+
relatedControls: ["DPDP-SEC-001"]
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Multi-line LLM message construction
|
|
47
|
+
const llmAnchor = /\b(chat\.completions|completions\.create|messages\s*:\s*\[|embed(dings)?\(|pinecone|vectorStore|similaritySearch|OpenAI\b|anthropic|messages\.push)\b/i.test(line) || /\b(role:\s*['"]user['"]|content:\s*[`'"])/i.test(line);
|
|
48
|
+
if (llmAnchor && shared_1.PII_KEYWORD.test(deepWindow)) {
|
|
49
|
+
// Avoid pure embeddings of ticket ids without PD keywords already gated by PII_KEYWORD
|
|
50
|
+
(0, shared_1.pushSignal)(signals, {
|
|
51
|
+
kind: "safeguard_gap",
|
|
52
|
+
file,
|
|
53
|
+
line: lineNumber,
|
|
54
|
+
category: "llm_prompt_embedding",
|
|
55
|
+
summary: "Potential personal data in LLM prompt / embedding path",
|
|
56
|
+
confidence: "medium",
|
|
57
|
+
tags: ["pii-in-llm"],
|
|
58
|
+
detectionMethod: "llm-prompt-multiline-pattern",
|
|
59
|
+
relatedControls: ["DPDP-SEC-002"]
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
if (/\bhttps?:\/\/[^\s"'`]+/i.test(line) && /\bhttp:\/\//i.test(line) && shared_1.PII_KEYWORD.test(window)) {
|
|
63
|
+
(0, shared_1.pushSignal)(signals, {
|
|
64
|
+
kind: "safeguard_gap",
|
|
65
|
+
file,
|
|
66
|
+
line: lineNumber,
|
|
67
|
+
summary: "Cleartext HTTP URL near personal-data context",
|
|
68
|
+
confidence: "medium",
|
|
69
|
+
tags: ["insecure-http"],
|
|
70
|
+
detectionMethod: "http-url-pattern",
|
|
71
|
+
relatedControls: ["DPDP-SEC-005"]
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
if (/\b(req\.query|request\.args|searchParams|querystring)\b/i.test(line) &&
|
|
75
|
+
/\b(email|phone|aadhaar|pan|userId|user_id)\b/i.test(window)) {
|
|
76
|
+
(0, shared_1.pushSignal)(signals, {
|
|
77
|
+
kind: "safeguard_gap",
|
|
78
|
+
file,
|
|
79
|
+
line: lineNumber,
|
|
80
|
+
summary: "Personal data identifier read from URL/query string",
|
|
81
|
+
confidence: "medium",
|
|
82
|
+
tags: ["pii-in-urls"],
|
|
83
|
+
detectionMethod: "query-pii-pattern",
|
|
84
|
+
relatedControls: ["DPDP-SEC-003"]
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
if (/\bselect\s+\*|\bfindMany\s*\(\s*\)|\bfind\s*\(\s*\{\s*\}\s*\)|\.all\(\)/i.test(line) &&
|
|
88
|
+
/\b(user|customer|profile|member|patient)\b/i.test(window)) {
|
|
89
|
+
(0, shared_1.pushSignal)(signals, {
|
|
90
|
+
kind: "safeguard_gap",
|
|
91
|
+
file,
|
|
92
|
+
line: lineNumber,
|
|
93
|
+
summary: "Broad database selection on personal-data model",
|
|
94
|
+
confidence: "medium",
|
|
95
|
+
tags: ["broad-db-select"],
|
|
96
|
+
detectionMethod: "broad-select-pattern",
|
|
97
|
+
relatedControls: ["DPDP-MIN-002"]
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
if (/\b(\/debug|\/dump|debug_endpoint|dumpUsers|dump_users)\b/i.test(line) && shared_1.PII_KEYWORD.test(window)) {
|
|
101
|
+
(0, shared_1.pushSignal)(signals, {
|
|
102
|
+
kind: "safeguard_gap",
|
|
103
|
+
file,
|
|
104
|
+
line: lineNumber,
|
|
105
|
+
summary: "Debug/dump endpoint potentially exposing personal records",
|
|
106
|
+
confidence: "high",
|
|
107
|
+
tags: ["debug-exposure"],
|
|
108
|
+
detectionMethod: "debug-route-pattern",
|
|
109
|
+
relatedControls: ["DPDP-SEC-008"]
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
if (/\b(mask|redact)\w*\s*\([^)]*\)\s*\{[^}]{0,120}\}/i.test(line) ||
|
|
113
|
+
(/\b(mask|redact)\w*\s*=/.test(line) && /\bslice\s*\(\s*0\s*,\s*[1-3]\s*\)/.test(window))) {
|
|
114
|
+
(0, shared_1.pushSignal)(signals, {
|
|
115
|
+
kind: "safeguard_gap",
|
|
116
|
+
file,
|
|
117
|
+
line: lineNumber,
|
|
118
|
+
summary: "Potentially weak masking implementation",
|
|
119
|
+
confidence: "low",
|
|
120
|
+
tags: ["weak-masking"],
|
|
121
|
+
detectionMethod: "weak-mask-pattern",
|
|
122
|
+
relatedControls: ["DPDP-SEC-009"]
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
if (/\b(export|erase|deleteAccount|admin).*?(user|personal|customer)\b/i.test(line) ||
|
|
126
|
+
/\b(user|personal|customer).*?(export|erase|delete)\b/i.test(line)) {
|
|
127
|
+
if (!/\b(audit|auditLog|activity_log|security_log)\b/i.test(window)) {
|
|
128
|
+
(0, shared_1.pushSignal)(signals, {
|
|
129
|
+
kind: "safeguard_gap",
|
|
130
|
+
file,
|
|
131
|
+
line: lineNumber,
|
|
132
|
+
summary: "Sensitive personal-data operation without nearby audit signal",
|
|
133
|
+
confidence: "low",
|
|
134
|
+
tags: ["missing-audit"],
|
|
135
|
+
detectionMethod: "audit-gap-pattern",
|
|
136
|
+
relatedControls: ["DPDP-SEC-010"]
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
if (/\b(track|capture|identify|setUser|set_user|people\.set)\s*\(/i.test(line) &&
|
|
141
|
+
/\b(user|profile|customer|email)\b/i.test(window)) {
|
|
142
|
+
(0, shared_1.pushSignal)(signals, {
|
|
143
|
+
kind: "safeguard_gap",
|
|
144
|
+
file,
|
|
145
|
+
line: lineNumber,
|
|
146
|
+
summary: "Possible whole-user object sent to third-party SDK",
|
|
147
|
+
confidence: "medium",
|
|
148
|
+
tags: ["third-party-user-object"],
|
|
149
|
+
detectionMethod: "third-party-user-pattern",
|
|
150
|
+
relatedControls: ["DPDP-THIRD-001"]
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
// Express/Fastify-style routes: path may be on the same line or the next few lines
|
|
154
|
+
const sameLineRoute = /\b(app|router|route)\.(get|post|put|patch|delete)\s*\(\s*['"`]([^'"`]+)['"`]/i.exec(line) ||
|
|
155
|
+
/@(app|router)\.(get|post|put|patch|delete)\s*\(\s*['"`]([^'"`]+)['"`]/i.exec(line);
|
|
156
|
+
let routePath = sameLineRoute?.[3];
|
|
157
|
+
if (!routePath &&
|
|
158
|
+
/\b(app|router|route)\.(get|post|put|patch|delete)\s*\(\s*$/i.test(line)) {
|
|
159
|
+
const lookahead = lines.slice(index, Math.min(lines.length, index + 5)).join("\n");
|
|
160
|
+
const multi = lookahead.match(/\b(app|router|route)\.(get|post|put|patch|delete)\s*\(\s*['"`]([^'"`]+)['"`]/i);
|
|
161
|
+
routePath = multi?.[3];
|
|
162
|
+
}
|
|
163
|
+
if (!routePath) {
|
|
164
|
+
routePath = routeMatchFallback(line);
|
|
165
|
+
}
|
|
166
|
+
if (routePath && /user|profile|customer|account|personal|export/i.test(routePath)) {
|
|
167
|
+
const routeWindow = (0, shared_1.windowAround)(lines, index, 6, 6);
|
|
168
|
+
if (!(0, shared_1.lineHasAuth)(line, routeWindow) && !globalAuth) {
|
|
169
|
+
(0, shared_1.pushSignal)(signals, {
|
|
170
|
+
kind: "safeguard_gap",
|
|
171
|
+
file,
|
|
172
|
+
line: lineNumber,
|
|
173
|
+
summary: `Personal-data route without nearby auth signal: ${routePath}`,
|
|
174
|
+
confidence: "low",
|
|
175
|
+
tags: ["missing-route-auth"],
|
|
176
|
+
detectionMethod: "route-auth-multiline-heuristic",
|
|
177
|
+
relatedControls: ["DPDP-SEC-006"]
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function routeMatchFallback(line) {
|
|
184
|
+
const match = line.match(/['"`]([^'"`]*(?:user|profile|customer|account|personal|export)[^'"`]*)['"`]/i);
|
|
185
|
+
return match?.[1];
|
|
186
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { TechnicalSignalBag } from "../types";
|
|
2
|
+
/**
|
|
3
|
+
* Structured schema extraction for Prisma models and SQL CREATE TABLE.
|
|
4
|
+
* Emits store signals plus per-field evidence when personal-data columns are named.
|
|
5
|
+
*/
|
|
6
|
+
export declare function collectSchemaSignals(signals: TechnicalSignalBag[], file: string, content: string): void;
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.collectSchemaSignals = collectSchemaSignals;
|
|
4
|
+
const shared_1 = require("./shared");
|
|
5
|
+
const PII_FIELD = /\b(email|phone|aadhaar|pan|password|address|dob|date_of_birth|passport|ssn|mobile|first_name|last_name)\b/i;
|
|
6
|
+
const RETENTION_FIELD = /\b(deletedAt|deleted_at|expiresAt|expires_at|ttl|retain_until|retention)\b/i;
|
|
7
|
+
/**
|
|
8
|
+
* Structured schema extraction for Prisma models and SQL CREATE TABLE.
|
|
9
|
+
* Emits store signals plus per-field evidence when personal-data columns are named.
|
|
10
|
+
*/
|
|
11
|
+
function collectSchemaSignals(signals, file, content) {
|
|
12
|
+
const isSchemaFile = file.endsWith(".prisma") ||
|
|
13
|
+
file.endsWith(".sql") ||
|
|
14
|
+
/models?\.py$|schema\.(ts|js|py)$/i.test(file);
|
|
15
|
+
if (!isSchemaFile && !/\bmodel\s+\w+\s*\{/.test(content) && !/\bCREATE\s+TABLE\b/i.test(content)) {
|
|
16
|
+
return;
|
|
17
|
+
}
|
|
18
|
+
let foundPii = false;
|
|
19
|
+
let foundRetention = false;
|
|
20
|
+
// Prisma models
|
|
21
|
+
for (const block of content.matchAll(/model\s+(\w+)\s*\{([^}]*)\}/g)) {
|
|
22
|
+
const modelName = block[1];
|
|
23
|
+
const body = block[2] ?? "";
|
|
24
|
+
const modelStart = content.slice(0, block.index ?? 0).split(/\r?\n/).length;
|
|
25
|
+
for (const fieldLine of body.split(/\r?\n/)) {
|
|
26
|
+
const trimmed = fieldLine.trim();
|
|
27
|
+
if (!trimmed || trimmed.startsWith("//") || trimmed.startsWith("@@")) {
|
|
28
|
+
continue;
|
|
29
|
+
}
|
|
30
|
+
const fieldMatch = trimmed.match(/^(\w+)\s+/);
|
|
31
|
+
if (!fieldMatch) {
|
|
32
|
+
continue;
|
|
33
|
+
}
|
|
34
|
+
const fieldName = fieldMatch[1];
|
|
35
|
+
if (PII_FIELD.test(fieldName) || PII_FIELD.test(trimmed)) {
|
|
36
|
+
foundPii = true;
|
|
37
|
+
(0, shared_1.pushSignal)(signals, {
|
|
38
|
+
kind: "field",
|
|
39
|
+
file,
|
|
40
|
+
line: modelStart,
|
|
41
|
+
field: `${modelName}.${fieldName}`,
|
|
42
|
+
summary: `Personal-data field in Prisma model ${modelName}.${fieldName}`,
|
|
43
|
+
confidence: "high",
|
|
44
|
+
tags: ["pii-store", "schema", "prisma-field", fieldName.toLowerCase()],
|
|
45
|
+
detectionMethod: "prisma-field-extract",
|
|
46
|
+
relatedControls: ["DPDP-APP-001", "DPDP-RET-001", "DPDP-ERA-002"]
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
if (RETENTION_FIELD.test(fieldName) || RETENTION_FIELD.test(trimmed)) {
|
|
50
|
+
foundRetention = true;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
// SQL CREATE TABLE
|
|
55
|
+
for (const block of content.matchAll(/CREATE\s+TABLE\s+(?:IF\s+NOT\s+EXISTS\s+)?["'`]?(\w+)["'`]?\s*\(([\s\S]*?)\)\s*;/gi)) {
|
|
56
|
+
const tableName = block[1];
|
|
57
|
+
const body = block[2] ?? "";
|
|
58
|
+
const tableStart = content.slice(0, block.index ?? 0).split(/\r?\n/).length;
|
|
59
|
+
for (const colLine of body.split(/,\s*\n|,\s*(?=\w)/)) {
|
|
60
|
+
const colMatch = colLine.trim().match(/^["'`]?(\w+)["'`]?/);
|
|
61
|
+
if (!colMatch) {
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const colName = colMatch[1];
|
|
65
|
+
if (PII_FIELD.test(colName)) {
|
|
66
|
+
foundPii = true;
|
|
67
|
+
(0, shared_1.pushSignal)(signals, {
|
|
68
|
+
kind: "field",
|
|
69
|
+
file,
|
|
70
|
+
line: tableStart,
|
|
71
|
+
field: `${tableName}.${colName}`,
|
|
72
|
+
summary: `Personal-data column in SQL table ${tableName}.${colName}`,
|
|
73
|
+
confidence: "high",
|
|
74
|
+
tags: ["pii-store", "schema", "sql-column", colName.toLowerCase()],
|
|
75
|
+
detectionMethod: "sql-column-extract",
|
|
76
|
+
relatedControls: ["DPDP-APP-001", "DPDP-RET-001", "DPDP-ERA-002"]
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
if (RETENTION_FIELD.test(colName)) {
|
|
80
|
+
foundRetention = true;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
// Fallback for ORM/schema files without Prisma/SQL blocks
|
|
85
|
+
if (!foundPii && PII_FIELD.test(content) && isSchemaFile) {
|
|
86
|
+
foundPii = true;
|
|
87
|
+
(0, shared_1.pushSignal)(signals, {
|
|
88
|
+
kind: "storage",
|
|
89
|
+
file,
|
|
90
|
+
summary: "Personal-data fields present in schema/model",
|
|
91
|
+
confidence: "high",
|
|
92
|
+
tags: ["pii-store", "schema"],
|
|
93
|
+
detectionMethod: "schema-scan",
|
|
94
|
+
relatedControls: ["DPDP-APP-001", "DPDP-RET-001", "DPDP-ERA-002"]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
if (foundPii) {
|
|
98
|
+
// Aggregate store signal when field-level signals were emitted
|
|
99
|
+
if (!signals.some((s) => s.file === file && s.kind === "storage" && s.tags.includes("schema"))) {
|
|
100
|
+
(0, shared_1.pushSignal)(signals, {
|
|
101
|
+
kind: "storage",
|
|
102
|
+
file,
|
|
103
|
+
summary: "Personal-data fields present in schema/model",
|
|
104
|
+
confidence: "high",
|
|
105
|
+
tags: ["pii-store", "schema"],
|
|
106
|
+
detectionMethod: "schema-scan",
|
|
107
|
+
relatedControls: ["DPDP-APP-001", "DPDP-RET-001", "DPDP-ERA-002"]
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
if (foundPii && (foundRetention || RETENTION_FIELD.test(content))) {
|
|
112
|
+
(0, shared_1.pushSignal)(signals, {
|
|
113
|
+
kind: "retention",
|
|
114
|
+
file,
|
|
115
|
+
summary: "Retention/TTL/soft-delete field observed in schema",
|
|
116
|
+
confidence: "high",
|
|
117
|
+
tags: ["retention-present"],
|
|
118
|
+
detectionMethod: "schema-retention",
|
|
119
|
+
relatedControls: ["DPDP-RET-001"]
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { TechnicalSignalBag } from "../types";
|
|
2
|
+
export declare function pushSignal(signals: TechnicalSignalBag[], partial: Omit<TechnicalSignalBag, "id"> & {
|
|
3
|
+
id?: string;
|
|
4
|
+
}): void;
|
|
5
|
+
export declare function readFileSafe(root: string, file: string, maxBytes: number): Promise<string | undefined>;
|
|
6
|
+
export declare function lineHasAuth(line: string, nearby: string): boolean;
|
|
7
|
+
/** Wider multi-line window for depth-sensitive detectors. */
|
|
8
|
+
export declare function windowAround(lines: string[], index: number, before?: number, after?: number): string;
|
|
9
|
+
export declare function fileHasGlobalAuth(content: string): boolean;
|
|
10
|
+
export declare const PII_KEYWORD: RegExp;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.PII_KEYWORD = void 0;
|
|
7
|
+
exports.pushSignal = pushSignal;
|
|
8
|
+
exports.readFileSafe = readFileSafe;
|
|
9
|
+
exports.lineHasAuth = lineHasAuth;
|
|
10
|
+
exports.windowAround = windowAround;
|
|
11
|
+
exports.fileHasGlobalAuth = fileHasGlobalAuth;
|
|
12
|
+
const node_fs_1 = require("node:fs");
|
|
13
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
14
|
+
const evidence_1 = require("../evidence");
|
|
15
|
+
function pushSignal(signals, partial) {
|
|
16
|
+
const id = partial.id ??
|
|
17
|
+
(0, evidence_1.stableEvidenceId)([partial.kind, partial.file, partial.line, partial.summary, partial.detectionMethod]);
|
|
18
|
+
signals.push({ ...partial, id });
|
|
19
|
+
}
|
|
20
|
+
async function readFileSafe(root, file, maxBytes) {
|
|
21
|
+
const absolute = node_path_1.default.join(root, file);
|
|
22
|
+
const stat = await node_fs_1.promises.stat(absolute).catch(() => undefined);
|
|
23
|
+
if (!stat || stat.size > maxBytes) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
const content = await node_fs_1.promises.readFile(absolute, "utf8").catch(() => undefined);
|
|
27
|
+
if (!content || content.includes("\0")) {
|
|
28
|
+
return undefined;
|
|
29
|
+
}
|
|
30
|
+
return content;
|
|
31
|
+
}
|
|
32
|
+
function lineHasAuth(line, nearby) {
|
|
33
|
+
// Avoid bare "middleware" — comments and non-auth middleware caused false negatives.
|
|
34
|
+
return /\b(authenticate|requireAuth|isAuthenticated|passport\.authenticate|jwt|authorize|permission|guard|Depends\(|HTTPBearer|login_required|require_auth)\b/i.test(`${line}\n${nearby}`) || /\b(auth|session)\b/i.test(`${line}\n${nearby}`) && /\b(middleware|handler|guard|check)\b/i.test(`${line}\n${nearby}`);
|
|
35
|
+
}
|
|
36
|
+
/** Wider multi-line window for depth-sensitive detectors. */
|
|
37
|
+
function windowAround(lines, index, before = 5, after = 8) {
|
|
38
|
+
return lines.slice(Math.max(0, index - before), Math.min(lines.length, index + after + 1)).join("\n");
|
|
39
|
+
}
|
|
40
|
+
function fileHasGlobalAuth(content) {
|
|
41
|
+
return /\b(app\.use\s*\(\s*requireAuth|app\.use\s*\(\s*auth|router\.use\s*\(\s*requireAuth|authenticate\s*\(|passport\.authenticate)\b/i.test(content);
|
|
42
|
+
}
|
|
43
|
+
exports.PII_KEYWORD = /\b(email|phone|aadhaar|pan|password|address|dob|date_of_birth|passport|user|customer|profile|patient|member)\b/i;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { VibeDoctorConfig } from "../core/config";
|
|
2
|
+
import type { DeclaredAssertion, DpdpContext } from "./types";
|
|
3
|
+
export type OrgTriState = "true" | "false" | "unknown";
|
|
4
|
+
export declare const DEFAULT_DPDP_CONTEXT: DpdpContext;
|
|
5
|
+
/**
|
|
6
|
+
* Apply organisation fields only when the overlay value is not `"unknown"`.
|
|
7
|
+
* Used for vibedoctor.yml defaults so explicit context.yml can still win.
|
|
8
|
+
*/
|
|
9
|
+
export declare function applyNonUnknownOrg(base: DpdpContext["organization"], overlay: Partial<DpdpContext["organization"]>): DpdpContext["organization"];
|
|
10
|
+
/**
|
|
11
|
+
* Load optional `.vibedoctor/dpdp/context.yml` (or configured path).
|
|
12
|
+
* Does not apply vibedoctor.yml organisation defaults — use {@link resolveDpdpContext}.
|
|
13
|
+
*/
|
|
14
|
+
export declare function loadDpdpContext(root: string, relativePath: string): Promise<DpdpContext>;
|
|
15
|
+
/**
|
|
16
|
+
* Resolve organisational context for a DPDP scan.
|
|
17
|
+
*
|
|
18
|
+
* Merge order:
|
|
19
|
+
* 1. Defaults (`unknown`)
|
|
20
|
+
* 2. `checks.dpdp.organization` from vibedoctor.yml (non-`unknown` fields only)
|
|
21
|
+
* 3. context.yml when present — full overlay for org fields (including explicit `unknown`)
|
|
22
|
+
*
|
|
23
|
+
* vibedoctor.yml is convenience defaults; the context file is the authoritative workspace declaration when present.
|
|
24
|
+
*/
|
|
25
|
+
export declare function resolveDpdpContext(root: string, config: VibeDoctorConfig): Promise<DpdpContext>;
|
|
26
|
+
export declare function loadDeclaredEvidence(root: string, relativePath: string): Promise<DeclaredAssertion[]>;
|
|
27
|
+
export declare function renderDefaultContextYaml(): string;
|
|
28
|
+
export declare function renderDefaultEvidenceYaml(): string;
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.DEFAULT_DPDP_CONTEXT = void 0;
|
|
7
|
+
exports.applyNonUnknownOrg = applyNonUnknownOrg;
|
|
8
|
+
exports.loadDpdpContext = loadDpdpContext;
|
|
9
|
+
exports.resolveDpdpContext = resolveDpdpContext;
|
|
10
|
+
exports.loadDeclaredEvidence = loadDeclaredEvidence;
|
|
11
|
+
exports.renderDefaultContextYaml = renderDefaultContextYaml;
|
|
12
|
+
exports.renderDefaultEvidenceYaml = renderDefaultEvidenceYaml;
|
|
13
|
+
const node_fs_1 = require("node:fs");
|
|
14
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
+
const yaml_1 = __importDefault(require("yaml"));
|
|
16
|
+
const paths_1 = require("../core/paths");
|
|
17
|
+
exports.DEFAULT_DPDP_CONTEXT = {
|
|
18
|
+
version: 1,
|
|
19
|
+
organization: {
|
|
20
|
+
processesPersonalData: "unknown",
|
|
21
|
+
isSignificantDataFiduciary: "unknown",
|
|
22
|
+
processesChildrenData: "unknown",
|
|
23
|
+
hasCrossBorderTransfer: "unknown"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
function asTriState(value) {
|
|
27
|
+
if (value === true || value === "true" || value === "yes") {
|
|
28
|
+
return "true";
|
|
29
|
+
}
|
|
30
|
+
if (value === false || value === "false" || value === "no") {
|
|
31
|
+
return "false";
|
|
32
|
+
}
|
|
33
|
+
return "unknown";
|
|
34
|
+
}
|
|
35
|
+
function orgFromConfig(config) {
|
|
36
|
+
const org = config.checks.dpdp.organization;
|
|
37
|
+
return {
|
|
38
|
+
processesPersonalData: org.processesPersonalData,
|
|
39
|
+
isSignificantDataFiduciary: org.isSignificantDataFiduciary,
|
|
40
|
+
processesChildrenData: org.processesChildrenData,
|
|
41
|
+
hasCrossBorderTransfer: org.hasCrossBorderTransfer
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Apply organisation fields only when the overlay value is not `"unknown"`.
|
|
46
|
+
* Used for vibedoctor.yml defaults so explicit context.yml can still win.
|
|
47
|
+
*/
|
|
48
|
+
function applyNonUnknownOrg(base, overlay) {
|
|
49
|
+
return {
|
|
50
|
+
processesPersonalData: overlay.processesPersonalData && overlay.processesPersonalData !== "unknown"
|
|
51
|
+
? overlay.processesPersonalData
|
|
52
|
+
: base.processesPersonalData,
|
|
53
|
+
isSignificantDataFiduciary: overlay.isSignificantDataFiduciary && overlay.isSignificantDataFiduciary !== "unknown"
|
|
54
|
+
? overlay.isSignificantDataFiduciary
|
|
55
|
+
: base.isSignificantDataFiduciary,
|
|
56
|
+
processesChildrenData: overlay.processesChildrenData && overlay.processesChildrenData !== "unknown"
|
|
57
|
+
? overlay.processesChildrenData
|
|
58
|
+
: base.processesChildrenData,
|
|
59
|
+
hasCrossBorderTransfer: overlay.hasCrossBorderTransfer && overlay.hasCrossBorderTransfer !== "unknown"
|
|
60
|
+
? overlay.hasCrossBorderTransfer
|
|
61
|
+
: base.hasCrossBorderTransfer,
|
|
62
|
+
industry: overlay.industry ?? base.industry,
|
|
63
|
+
notes: overlay.notes ?? base.notes
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Load optional `.vibedoctor/dpdp/context.yml` (or configured path).
|
|
68
|
+
* Does not apply vibedoctor.yml organisation defaults — use {@link resolveDpdpContext}.
|
|
69
|
+
*/
|
|
70
|
+
async function loadDpdpContext(root, relativePath) {
|
|
71
|
+
const absolute = node_path_1.default.isAbsolute(relativePath) ? relativePath : node_path_1.default.join(root, relativePath);
|
|
72
|
+
if (!(await (0, paths_1.pathExists)(absolute))) {
|
|
73
|
+
return { ...exports.DEFAULT_DPDP_CONTEXT, organization: { ...exports.DEFAULT_DPDP_CONTEXT.organization } };
|
|
74
|
+
}
|
|
75
|
+
const raw = yaml_1.default.parse(await node_fs_1.promises.readFile(absolute, "utf8"));
|
|
76
|
+
const org = (raw.organization ?? raw.org ?? {});
|
|
77
|
+
return {
|
|
78
|
+
version: typeof raw.version === "number" ? raw.version : 1,
|
|
79
|
+
organization: {
|
|
80
|
+
processesPersonalData: asTriState(org.processesPersonalData ?? org.processes_personal_data),
|
|
81
|
+
isSignificantDataFiduciary: asTriState(org.isSignificantDataFiduciary ?? org.is_significant_data_fiduciary),
|
|
82
|
+
processesChildrenData: asTriState(org.processesChildrenData ?? org.processes_children_data),
|
|
83
|
+
hasCrossBorderTransfer: asTriState(org.hasCrossBorderTransfer ?? org.has_cross_border_transfer),
|
|
84
|
+
industry: typeof org.industry === "string" ? org.industry : undefined,
|
|
85
|
+
notes: typeof org.notes === "string" ? org.notes : undefined
|
|
86
|
+
},
|
|
87
|
+
purposes: Array.isArray(raw.purposes) ? raw.purposes.map(String) : undefined,
|
|
88
|
+
processors: Array.isArray(raw.processors) ? raw.processors.map(String) : undefined,
|
|
89
|
+
policies: Array.isArray(raw.policies)
|
|
90
|
+
? raw.policies.map((policy) => ({
|
|
91
|
+
name: String(policy.name ?? "policy"),
|
|
92
|
+
path: policy.path ? String(policy.path) : undefined,
|
|
93
|
+
version: policy.version ? String(policy.version) : undefined
|
|
94
|
+
}))
|
|
95
|
+
: undefined
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Resolve organisational context for a DPDP scan.
|
|
100
|
+
*
|
|
101
|
+
* Merge order:
|
|
102
|
+
* 1. Defaults (`unknown`)
|
|
103
|
+
* 2. `checks.dpdp.organization` from vibedoctor.yml (non-`unknown` fields only)
|
|
104
|
+
* 3. context.yml when present — full overlay for org fields (including explicit `unknown`)
|
|
105
|
+
*
|
|
106
|
+
* vibedoctor.yml is convenience defaults; the context file is the authoritative workspace declaration when present.
|
|
107
|
+
*/
|
|
108
|
+
async function resolveDpdpContext(root, config) {
|
|
109
|
+
const fromFile = await loadDpdpContext(root, config.checks.dpdp.contextFile);
|
|
110
|
+
const contextPath = node_path_1.default.isAbsolute(config.checks.dpdp.contextFile)
|
|
111
|
+
? config.checks.dpdp.contextFile
|
|
112
|
+
: node_path_1.default.join(root, config.checks.dpdp.contextFile);
|
|
113
|
+
const hasContextFile = await (0, paths_1.pathExists)(contextPath);
|
|
114
|
+
let organization = { ...exports.DEFAULT_DPDP_CONTEXT.organization };
|
|
115
|
+
organization = applyNonUnknownOrg(organization, orgFromConfig(config));
|
|
116
|
+
if (hasContextFile) {
|
|
117
|
+
// Context file wins for all org keys it supplies (parsed values always set).
|
|
118
|
+
organization = {
|
|
119
|
+
...organization,
|
|
120
|
+
...fromFile.organization
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
return {
|
|
124
|
+
version: fromFile.version,
|
|
125
|
+
organization,
|
|
126
|
+
purposes: fromFile.purposes,
|
|
127
|
+
processors: fromFile.processors,
|
|
128
|
+
policies: fromFile.policies
|
|
129
|
+
};
|
|
130
|
+
}
|
|
131
|
+
async function loadDeclaredEvidence(root, relativePath) {
|
|
132
|
+
const absolute = node_path_1.default.isAbsolute(relativePath) ? relativePath : node_path_1.default.join(root, relativePath);
|
|
133
|
+
if (!(await (0, paths_1.pathExists)(absolute))) {
|
|
134
|
+
return [];
|
|
135
|
+
}
|
|
136
|
+
const raw = yaml_1.default.parse(await node_fs_1.promises.readFile(absolute, "utf8"));
|
|
137
|
+
const assertions = (raw.assertions ?? raw.evidence ?? []);
|
|
138
|
+
if (!Array.isArray(assertions)) {
|
|
139
|
+
return [];
|
|
140
|
+
}
|
|
141
|
+
return assertions
|
|
142
|
+
.map((item, index) => {
|
|
143
|
+
const id = String(item.id ?? `declared-${index + 1}`);
|
|
144
|
+
const statement = String(item.statement ?? item.claim ?? "").trim();
|
|
145
|
+
if (!statement) {
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
const status = String(item.verificationStatus ?? item.verification_status ?? "unverified");
|
|
149
|
+
return {
|
|
150
|
+
id,
|
|
151
|
+
statement,
|
|
152
|
+
source: String(item.source ?? "declared"),
|
|
153
|
+
suppliedRole: String(item.suppliedRole ?? item.supplied_role ?? "unknown"),
|
|
154
|
+
date: String(item.date ?? new Date().toISOString().slice(0, 10)),
|
|
155
|
+
relatedControls: Array.isArray(item.relatedControls ?? item.related_controls)
|
|
156
|
+
? (item.relatedControls ?? item.related_controls).map(String)
|
|
157
|
+
: [],
|
|
158
|
+
verificationStatus: (["unverified", "partially_corroborated", "contradicted", "supported_by_signal"].includes(status)
|
|
159
|
+
? status
|
|
160
|
+
: "unverified")
|
|
161
|
+
};
|
|
162
|
+
})
|
|
163
|
+
.filter((item) => Boolean(item));
|
|
164
|
+
}
|
|
165
|
+
function renderDefaultContextYaml() {
|
|
166
|
+
return `# DPDP organisational context (optional)
|
|
167
|
+
# Defaults are "unknown". Do not treat these answers as deterministic verification.
|
|
168
|
+
# Merge order: defaults → vibedoctor.yml checks.dpdp.organization (non-unknown) → this file (authoritative when present).
|
|
169
|
+
version: 1
|
|
170
|
+
organization:
|
|
171
|
+
processes_personal_data: unknown
|
|
172
|
+
is_significant_data_fiduciary: unknown
|
|
173
|
+
processes_children_data: unknown
|
|
174
|
+
has_cross_border_transfer: unknown
|
|
175
|
+
# industry: fintech
|
|
176
|
+
# notes: ""
|
|
177
|
+
# purposes: []
|
|
178
|
+
# processors: []
|
|
179
|
+
# policies: []
|
|
180
|
+
`;
|
|
181
|
+
}
|
|
182
|
+
function renderDefaultEvidenceYaml() {
|
|
183
|
+
return `# Declared evidence for DPDP technical readiness (optional)
|
|
184
|
+
# Assertions are NEVER deterministic verification.
|
|
185
|
+
version: 1
|
|
186
|
+
assertions: []
|
|
187
|
+
# - id: ASSERT-001
|
|
188
|
+
# statement: "Written processor contracts exist for all analytics vendors."
|
|
189
|
+
# source: "legal/contracts-register.md"
|
|
190
|
+
# supplied_role: "legal"
|
|
191
|
+
# date: "2026-01-15"
|
|
192
|
+
# related_controls: ["DPDP-PROC-002"]
|
|
193
|
+
# verification_status: unverified
|
|
194
|
+
`;
|
|
195
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { ControlResult, EvidenceItem, PersonalDataMap, PersonalDataMapGraph, TechnicalSignalBag } from "./types";
|
|
2
|
+
/**
|
|
3
|
+
* Build a lightweight evidence graph from map aggregates + evidence ledger.
|
|
4
|
+
* Labels are classified/masked only — never raw PII.
|
|
5
|
+
*/
|
|
6
|
+
export declare function buildDataMapGraph(categories: PersonalDataMap["categories"], collectionPoints: PersonalDataMap["collectionPoints"], stores: PersonalDataMap["stores"], externalRecipients: PersonalDataMap["externalRecipients"], lifecycleSignals: PersonalDataMap["lifecycleSignals"], safeguardGaps: PersonalDataMap["safeguardGaps"], relatedControls: string[], evidence: EvidenceItem[]): PersonalDataMapGraph;
|
|
7
|
+
export declare function buildPersonalDataMap(signals: TechnicalSignalBag[], evidence: EvidenceItem[], controls: ControlResult[], generatedAt: string): PersonalDataMap;
|