guardrail-compliance 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/dist/audit/emitter.d.ts +97 -0
- package/dist/audit/emitter.d.ts.map +1 -0
- package/dist/audit/emitter.js +197 -0
- package/dist/audit/events.d.ts +304 -0
- package/dist/audit/events.d.ts.map +1 -0
- package/dist/audit/events.js +267 -0
- package/dist/audit/index.d.ts +11 -0
- package/dist/audit/index.d.ts.map +1 -0
- package/dist/audit/index.js +51 -0
- package/dist/audit/storage.d.ts +93 -0
- package/dist/audit/storage.d.ts.map +1 -0
- package/dist/audit/storage.js +337 -0
- package/dist/automation/__tests__/compliance-scheduler.test.d.ts +2 -0
- package/dist/automation/__tests__/compliance-scheduler.test.d.ts.map +1 -0
- package/dist/automation/__tests__/compliance-scheduler.test.js +140 -0
- package/dist/automation/audit-logger.d.ts +129 -0
- package/dist/automation/audit-logger.d.ts.map +1 -0
- package/dist/automation/audit-logger.js +473 -0
- package/dist/automation/compliance-scheduler-fixed.d.ts +1 -0
- package/dist/automation/compliance-scheduler-fixed.d.ts.map +1 -0
- package/dist/automation/compliance-scheduler-fixed.js +1 -0
- package/dist/automation/compliance-scheduler.d.ts +83 -0
- package/dist/automation/compliance-scheduler.d.ts.map +1 -0
- package/dist/automation/compliance-scheduler.js +414 -0
- package/dist/automation/dashboard.d.ts +194 -0
- package/dist/automation/dashboard.d.ts.map +1 -0
- package/dist/automation/dashboard.js +768 -0
- package/dist/automation/email-service.d.ts +69 -0
- package/dist/automation/email-service.d.ts.map +1 -0
- package/dist/automation/email-service.js +218 -0
- package/dist/automation/evidence-collector.d.ts +140 -0
- package/dist/automation/evidence-collector.d.ts.map +1 -0
- package/dist/automation/evidence-collector.js +682 -0
- package/dist/automation/index.d.ts +8 -0
- package/dist/automation/index.d.ts.map +1 -0
- package/dist/automation/index.js +24 -0
- package/dist/automation/pdf-exporter.d.ts +90 -0
- package/dist/automation/pdf-exporter.d.ts.map +1 -0
- package/dist/automation/pdf-exporter.js +381 -0
- package/dist/automation/reporting-engine.d.ts +116 -0
- package/dist/automation/reporting-engine.d.ts.map +1 -0
- package/dist/automation/reporting-engine.js +329 -0
- package/dist/container/index.d.ts +4 -0
- package/dist/container/index.d.ts.map +1 -0
- package/dist/container/index.js +19 -0
- package/dist/container/kubernetes.d.ts +94 -0
- package/dist/container/kubernetes.d.ts.map +1 -0
- package/dist/container/kubernetes.js +268 -0
- package/dist/container/rules.d.ts +27 -0
- package/dist/container/rules.d.ts.map +1 -0
- package/dist/container/rules.js +216 -0
- package/dist/container/scanner.d.ts +50 -0
- package/dist/container/scanner.d.ts.map +1 -0
- package/dist/container/scanner.js +143 -0
- package/dist/frameworks/engine.d.ts +108 -0
- package/dist/frameworks/engine.d.ts.map +1 -0
- package/dist/frameworks/engine.js +206 -0
- package/dist/frameworks/gdpr.d.ts +6 -0
- package/dist/frameworks/gdpr.d.ts.map +1 -0
- package/dist/frameworks/gdpr.js +198 -0
- package/dist/frameworks/hipaa.d.ts +6 -0
- package/dist/frameworks/hipaa.d.ts.map +1 -0
- package/dist/frameworks/hipaa.js +183 -0
- package/dist/frameworks/index.d.ts +8 -0
- package/dist/frameworks/index.d.ts.map +1 -0
- package/dist/frameworks/index.js +30 -0
- package/dist/frameworks/iso27001.d.ts +63 -0
- package/dist/frameworks/iso27001.d.ts.map +1 -0
- package/dist/frameworks/iso27001.js +331 -0
- package/dist/frameworks/nist.d.ts +62 -0
- package/dist/frameworks/nist.d.ts.map +1 -0
- package/dist/frameworks/nist.js +424 -0
- package/dist/frameworks/pci.d.ts +6 -0
- package/dist/frameworks/pci.d.ts.map +1 -0
- package/dist/frameworks/pci.js +201 -0
- package/dist/frameworks/soc2.d.ts +7 -0
- package/dist/frameworks/soc2.d.ts.map +1 -0
- package/dist/frameworks/soc2.js +248 -0
- package/dist/iac/drift-detector.d.ts +64 -0
- package/dist/iac/drift-detector.d.ts.map +1 -0
- package/dist/iac/drift-detector.js +134 -0
- package/dist/iac/index.d.ts +4 -0
- package/dist/iac/index.d.ts.map +1 -0
- package/dist/iac/index.js +19 -0
- package/dist/iac/rules.d.ts +17 -0
- package/dist/iac/rules.d.ts.map +1 -0
- package/dist/iac/rules.js +385 -0
- package/dist/iac/scanner.d.ts +104 -0
- package/dist/iac/scanner.d.ts.map +1 -0
- package/dist/iac/scanner.js +343 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +28 -0
- package/dist/pii/data-flow.d.ts +58 -0
- package/dist/pii/data-flow.d.ts.map +1 -0
- package/dist/pii/data-flow.js +154 -0
- package/dist/pii/detector.d.ts +60 -0
- package/dist/pii/detector.d.ts.map +1 -0
- package/dist/pii/detector.js +267 -0
- package/dist/pii/index.d.ts +4 -0
- package/dist/pii/index.d.ts.map +1 -0
- package/dist/pii/index.js +19 -0
- package/dist/pii/patterns.d.ts +36 -0
- package/dist/pii/patterns.d.ts.map +1 -0
- package/dist/pii/patterns.js +108 -0
- package/dist/policy/index.d.ts +5 -0
- package/dist/policy/index.d.ts.map +1 -0
- package/dist/policy/index.js +20 -0
- package/dist/policy/opa-engine.d.ts +121 -0
- package/dist/policy/opa-engine.d.ts.map +1 -0
- package/dist/policy/opa-engine.js +423 -0
- package/package.json +31 -0
- package/src/audit/emitter.ts +383 -0
- package/src/audit/events.ts +351 -0
- package/src/audit/index.ts +35 -0
- package/src/audit/storage.ts +394 -0
- package/src/automation/__tests__/compliance-scheduler.test.ts +183 -0
- package/src/automation/audit-logger.ts +629 -0
- package/src/automation/compliance-scheduler-fixed.ts +0 -0
- package/src/automation/compliance-scheduler.ts +516 -0
- package/src/automation/dashboard.ts +947 -0
- package/src/automation/email-service.ts +230 -0
- package/src/automation/evidence-collector.ts +866 -0
- package/src/automation/index.ts +8 -0
- package/src/automation/pdf-exporter.ts +434 -0
- package/src/automation/reporting-engine.ts +462 -0
- package/src/container/index.ts +3 -0
- package/src/container/kubernetes.ts +379 -0
- package/src/container/rules.ts +244 -0
- package/src/container/scanner.ts +202 -0
- package/src/frameworks/engine.ts +298 -0
- package/src/frameworks/gdpr.ts +204 -0
- package/src/frameworks/hipaa.ts +209 -0
- package/src/frameworks/index.ts +23 -0
- package/src/frameworks/iso27001.ts +398 -0
- package/src/frameworks/nist.ts +518 -0
- package/src/frameworks/pci.ts +226 -0
- package/src/frameworks/soc2.ts +281 -0
- package/src/iac/drift-detector.ts +197 -0
- package/src/iac/index.ts +3 -0
- package/src/iac/rules.ts +420 -0
- package/src/iac/scanner.ts +445 -0
- package/src/index.ts +17 -0
- package/src/pii/data-flow.ts +216 -0
- package/src/pii/detector.ts +327 -0
- package/src/pii/index.ts +3 -0
- package/src/pii/patterns.ts +128 -0
- package/src/policy/index.ts +5 -0
- package/src/policy/opa-engine.ts +504 -0
|
@@ -0,0 +1,423 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Policy as Code Engine (OPA/Rego Integration)
|
|
4
|
+
*
|
|
5
|
+
* Enables custom security policies using Open Policy Agent and Rego language
|
|
6
|
+
* Supports:
|
|
7
|
+
* - Custom policy definitions
|
|
8
|
+
* - Policy evaluation against code/config
|
|
9
|
+
* - Policy bundles and versioning
|
|
10
|
+
* - Decision logging and auditing
|
|
11
|
+
*/
|
|
12
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
13
|
+
exports.policyEngine = exports.PolicyEngine = exports.BUILTIN_POLICIES = void 0;
|
|
14
|
+
// Built-in policy templates
|
|
15
|
+
exports.BUILTIN_POLICIES = [
|
|
16
|
+
{
|
|
17
|
+
id: 'no-hardcoded-secrets',
|
|
18
|
+
name: 'No Hardcoded Secrets',
|
|
19
|
+
description: 'Prevents hardcoded secrets in source code',
|
|
20
|
+
version: '1.0.0',
|
|
21
|
+
category: 'security',
|
|
22
|
+
severity: 'critical',
|
|
23
|
+
enabled: true,
|
|
24
|
+
tags: ['secrets', 'security', 'owasp'],
|
|
25
|
+
rego: `
|
|
26
|
+
package Guardrail.secrets
|
|
27
|
+
|
|
28
|
+
default allow = true
|
|
29
|
+
default violations = []
|
|
30
|
+
|
|
31
|
+
secret_patterns := [
|
|
32
|
+
"api[_-]?key\\\\s*[=:]\\\\s*['\\\"][^'\\\"]{10,}",
|
|
33
|
+
"password\\\\s*[=:]\\\\s*['\\\"][^'\\\"]{6,}",
|
|
34
|
+
"secret\\\\s*[=:]\\\\s*['\\\"][^'\\\"]{10,}",
|
|
35
|
+
"token\\\\s*[=:]\\\\s*['\\\"][^'\\\"]{10,}",
|
|
36
|
+
"aws_access_key_id",
|
|
37
|
+
"aws_secret_access_key"
|
|
38
|
+
]
|
|
39
|
+
|
|
40
|
+
violations[v] {
|
|
41
|
+
pattern := secret_patterns[_]
|
|
42
|
+
regex.match(pattern, lower(input.content))
|
|
43
|
+
v := {
|
|
44
|
+
"rule": "no-hardcoded-secrets",
|
|
45
|
+
"message": sprintf("Potential secret detected matching pattern: %s", [pattern]),
|
|
46
|
+
"severity": "critical"
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
allow {
|
|
51
|
+
count(violations) == 0
|
|
52
|
+
}
|
|
53
|
+
`,
|
|
54
|
+
},
|
|
55
|
+
{
|
|
56
|
+
id: 'secure-dependencies',
|
|
57
|
+
name: 'Secure Dependencies',
|
|
58
|
+
description: 'Ensures dependencies meet security requirements',
|
|
59
|
+
version: '1.0.0',
|
|
60
|
+
category: 'security',
|
|
61
|
+
severity: 'high',
|
|
62
|
+
enabled: true,
|
|
63
|
+
tags: ['dependencies', 'supply-chain'],
|
|
64
|
+
rego: `
|
|
65
|
+
package Guardrail.dependencies
|
|
66
|
+
|
|
67
|
+
default allow = true
|
|
68
|
+
default violations = []
|
|
69
|
+
|
|
70
|
+
blocked_packages := [
|
|
71
|
+
"event-stream",
|
|
72
|
+
"flatmap-stream",
|
|
73
|
+
"ua-parser-js@0.7.29"
|
|
74
|
+
]
|
|
75
|
+
|
|
76
|
+
violations[v] {
|
|
77
|
+
pkg := input.dependencies[_]
|
|
78
|
+
blocked := blocked_packages[_]
|
|
79
|
+
contains(sprintf("%s@%s", [pkg.name, pkg.version]), blocked)
|
|
80
|
+
v := {
|
|
81
|
+
"rule": "blocked-package",
|
|
82
|
+
"message": sprintf("Blocked package detected: %s@%s", [pkg.name, pkg.version]),
|
|
83
|
+
"severity": "critical"
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
violations[v] {
|
|
88
|
+
pkg := input.dependencies[_]
|
|
89
|
+
pkg.vulnerabilities[_].severity == "critical"
|
|
90
|
+
v := {
|
|
91
|
+
"rule": "critical-vulnerability",
|
|
92
|
+
"message": sprintf("Critical vulnerability in %s@%s", [pkg.name, pkg.version]),
|
|
93
|
+
"severity": "critical"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
allow {
|
|
98
|
+
count(violations) == 0
|
|
99
|
+
}
|
|
100
|
+
`,
|
|
101
|
+
},
|
|
102
|
+
{
|
|
103
|
+
id: 'license-compliance',
|
|
104
|
+
name: 'License Compliance',
|
|
105
|
+
description: 'Ensures dependency licenses are compliant',
|
|
106
|
+
version: '1.0.0',
|
|
107
|
+
category: 'compliance',
|
|
108
|
+
severity: 'high',
|
|
109
|
+
enabled: true,
|
|
110
|
+
tags: ['license', 'compliance', 'legal'],
|
|
111
|
+
rego: `
|
|
112
|
+
package Guardrail.licenses
|
|
113
|
+
|
|
114
|
+
default allow = true
|
|
115
|
+
default violations = []
|
|
116
|
+
|
|
117
|
+
copyleft_licenses := ["GPL-2.0", "GPL-3.0", "AGPL-3.0"]
|
|
118
|
+
|
|
119
|
+
violations[v] {
|
|
120
|
+
input.project_license == "MIT"
|
|
121
|
+
pkg := input.dependencies[_]
|
|
122
|
+
copyleft := copyleft_licenses[_]
|
|
123
|
+
pkg.license == copyleft
|
|
124
|
+
v := {
|
|
125
|
+
"rule": "copyleft-contamination",
|
|
126
|
+
"message": sprintf("Copyleft license %s in %s incompatible with MIT project", [pkg.license, pkg.name]),
|
|
127
|
+
"severity": "high"
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
allow {
|
|
132
|
+
count(violations) == 0
|
|
133
|
+
}
|
|
134
|
+
`,
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
id: 'agent-permissions',
|
|
138
|
+
name: 'AI Agent Permission Control',
|
|
139
|
+
description: 'Controls what AI agents can do',
|
|
140
|
+
version: '1.0.0',
|
|
141
|
+
category: 'access',
|
|
142
|
+
severity: 'high',
|
|
143
|
+
enabled: true,
|
|
144
|
+
tags: ['ai', 'agent', 'permissions'],
|
|
145
|
+
rego: `
|
|
146
|
+
package Guardrail.agent
|
|
147
|
+
|
|
148
|
+
default allow = false
|
|
149
|
+
|
|
150
|
+
dangerous_paths := ["/etc", "/root", "/var/log", "C:\\\\Windows\\\\System32"]
|
|
151
|
+
dangerous_commands := ["rm -rf", "del /f", "format", "shutdown", "reboot"]
|
|
152
|
+
|
|
153
|
+
allow {
|
|
154
|
+
input.action.type == "read"
|
|
155
|
+
not path_is_dangerous(input.action.path)
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
allow {
|
|
159
|
+
input.action.type == "write"
|
|
160
|
+
input.agent.permissions.write == true
|
|
161
|
+
not path_is_dangerous(input.action.path)
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
path_is_dangerous(path) {
|
|
165
|
+
dangerous := dangerous_paths[_]
|
|
166
|
+
startswith(path, dangerous)
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
command_is_dangerous(cmd) {
|
|
170
|
+
dangerous := dangerous_commands[_]
|
|
171
|
+
contains(lower(cmd), dangerous)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
violations[v] {
|
|
175
|
+
input.action.type == "execute"
|
|
176
|
+
command_is_dangerous(input.action.command)
|
|
177
|
+
v := {
|
|
178
|
+
"rule": "dangerous-command",
|
|
179
|
+
"message": sprintf("Dangerous command blocked: %s", [input.action.command]),
|
|
180
|
+
"severity": "critical"
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
`,
|
|
184
|
+
},
|
|
185
|
+
{
|
|
186
|
+
id: 'code-quality',
|
|
187
|
+
name: 'Code Quality Standards',
|
|
188
|
+
description: 'Enforces code quality standards',
|
|
189
|
+
version: '1.0.0',
|
|
190
|
+
category: 'quality',
|
|
191
|
+
severity: 'medium',
|
|
192
|
+
enabled: true,
|
|
193
|
+
tags: ['quality', 'standards'],
|
|
194
|
+
rego: `
|
|
195
|
+
package Guardrail.quality
|
|
196
|
+
|
|
197
|
+
default allow = true
|
|
198
|
+
default violations = []
|
|
199
|
+
|
|
200
|
+
violations[v] {
|
|
201
|
+
input.metrics.complexity > 20
|
|
202
|
+
v := {
|
|
203
|
+
"rule": "high-complexity",
|
|
204
|
+
"message": sprintf("Cyclomatic complexity %d exceeds threshold 20", [input.metrics.complexity]),
|
|
205
|
+
"severity": "medium"
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
violations[v] {
|
|
210
|
+
input.metrics.lines_of_code > 500
|
|
211
|
+
v := {
|
|
212
|
+
"rule": "large-file",
|
|
213
|
+
"message": sprintf("File has %d lines, exceeds threshold 500", [input.metrics.lines_of_code]),
|
|
214
|
+
"severity": "low"
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
violations[v] {
|
|
219
|
+
input.metrics.test_coverage < 60
|
|
220
|
+
v := {
|
|
221
|
+
"rule": "low-coverage",
|
|
222
|
+
"message": sprintf("Test coverage %d%% below threshold 60%%", [input.metrics.test_coverage]),
|
|
223
|
+
"severity": "medium"
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
allow {
|
|
228
|
+
count(violations) == 0
|
|
229
|
+
}
|
|
230
|
+
`,
|
|
231
|
+
},
|
|
232
|
+
];
|
|
233
|
+
/**
|
|
234
|
+
* Policy Engine for evaluating Rego policies
|
|
235
|
+
*/
|
|
236
|
+
class PolicyEngine {
|
|
237
|
+
policies = new Map();
|
|
238
|
+
decisionLog = [];
|
|
239
|
+
constructor() {
|
|
240
|
+
// Load built-in policies
|
|
241
|
+
for (const policy of exports.BUILTIN_POLICIES) {
|
|
242
|
+
this.policies.set(policy.id, policy);
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Register a custom policy
|
|
247
|
+
*/
|
|
248
|
+
registerPolicy(policy) {
|
|
249
|
+
this.policies.set(policy.id, policy);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Remove a policy
|
|
253
|
+
*/
|
|
254
|
+
removePolicy(policyId) {
|
|
255
|
+
return this.policies.delete(policyId);
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Get all registered policies
|
|
259
|
+
*/
|
|
260
|
+
getPolicies() {
|
|
261
|
+
return Array.from(this.policies.values());
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Get a specific policy
|
|
265
|
+
*/
|
|
266
|
+
getPolicy(policyId) {
|
|
267
|
+
return this.policies.get(policyId);
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Evaluate input against all enabled policies
|
|
271
|
+
*/
|
|
272
|
+
async evaluate(input) {
|
|
273
|
+
const decisions = [];
|
|
274
|
+
for (const policy of this.policies.values()) {
|
|
275
|
+
if (!policy.enabled)
|
|
276
|
+
continue;
|
|
277
|
+
const decision = await this.evaluatePolicy(policy, input);
|
|
278
|
+
decisions.push(decision);
|
|
279
|
+
this.decisionLog.push(decision);
|
|
280
|
+
}
|
|
281
|
+
return decisions;
|
|
282
|
+
}
|
|
283
|
+
/**
|
|
284
|
+
* Evaluate input against a specific policy
|
|
285
|
+
*/
|
|
286
|
+
async evaluatePolicy(policy, input) {
|
|
287
|
+
const startTime = Date.now();
|
|
288
|
+
try {
|
|
289
|
+
// In a real implementation, this would use an OPA client or WASM module
|
|
290
|
+
// For now, we use a simplified JavaScript-based evaluation
|
|
291
|
+
const result = await this.evaluateRego(policy.rego, input);
|
|
292
|
+
const violations = (result.violations || []).map((v) => ({
|
|
293
|
+
rule: v.rule || policy.id,
|
|
294
|
+
message: v.message || 'Policy violation',
|
|
295
|
+
severity: v.severity || policy.severity,
|
|
296
|
+
remediation: v.remediation,
|
|
297
|
+
location: v.location,
|
|
298
|
+
}));
|
|
299
|
+
return {
|
|
300
|
+
policyId: policy.id,
|
|
301
|
+
allowed: result.allow !== false && violations.length === 0,
|
|
302
|
+
violations,
|
|
303
|
+
warnings: result.warnings || [],
|
|
304
|
+
metadata: { policyVersion: policy.version },
|
|
305
|
+
evaluatedAt: new Date().toISOString(),
|
|
306
|
+
durationMs: Date.now() - startTime,
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
catch (error) {
|
|
310
|
+
return {
|
|
311
|
+
policyId: policy.id,
|
|
312
|
+
allowed: false,
|
|
313
|
+
violations: [{
|
|
314
|
+
rule: 'policy-error',
|
|
315
|
+
message: `Policy evaluation failed: ${error}`,
|
|
316
|
+
severity: 'high',
|
|
317
|
+
}],
|
|
318
|
+
warnings: [],
|
|
319
|
+
metadata: { error: String(error) },
|
|
320
|
+
evaluatedAt: new Date().toISOString(),
|
|
321
|
+
durationMs: Date.now() - startTime,
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Simplified Rego evaluation (placeholder for OPA integration)
|
|
327
|
+
* In production, this would use @open-policy-agent/opa-wasm or call OPA server
|
|
328
|
+
*/
|
|
329
|
+
async evaluateRego(_rego, input) {
|
|
330
|
+
const violations = [];
|
|
331
|
+
const warnings = [];
|
|
332
|
+
let allow = true;
|
|
333
|
+
const data = input.data;
|
|
334
|
+
// Basic pattern matching for demonstration
|
|
335
|
+
// Real implementation would parse and evaluate Rego
|
|
336
|
+
// Check for secrets in content
|
|
337
|
+
if (data.content) {
|
|
338
|
+
const secretPatterns = [
|
|
339
|
+
/api[_-]?key\s*[=:]\s*['"][^'"]{10,}/i,
|
|
340
|
+
/password\s*[=:]\s*['"][^'"]{6,}/i,
|
|
341
|
+
/secret\s*[=:]\s*['"][^'"]{10,}/i,
|
|
342
|
+
];
|
|
343
|
+
for (const pattern of secretPatterns) {
|
|
344
|
+
if (pattern.test(data.content)) {
|
|
345
|
+
violations.push({
|
|
346
|
+
rule: 'no-hardcoded-secrets',
|
|
347
|
+
message: 'Potential hardcoded secret detected',
|
|
348
|
+
severity: 'critical',
|
|
349
|
+
});
|
|
350
|
+
allow = false;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
// Check for dangerous dependencies
|
|
355
|
+
if (data.dependencies) {
|
|
356
|
+
const blocked = ['event-stream', 'flatmap-stream'];
|
|
357
|
+
for (const dep of data.dependencies) {
|
|
358
|
+
if (blocked.includes(dep.name)) {
|
|
359
|
+
violations.push({
|
|
360
|
+
rule: 'blocked-package',
|
|
361
|
+
message: `Blocked package: ${dep.name}`,
|
|
362
|
+
severity: 'critical',
|
|
363
|
+
});
|
|
364
|
+
allow = false;
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return { allow, violations, warnings };
|
|
369
|
+
}
|
|
370
|
+
/**
|
|
371
|
+
* Get decision log
|
|
372
|
+
*/
|
|
373
|
+
getDecisionLog() {
|
|
374
|
+
return [...this.decisionLog];
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Clear decision log
|
|
378
|
+
*/
|
|
379
|
+
clearDecisionLog() {
|
|
380
|
+
this.decisionLog = [];
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Export policies as a bundle
|
|
384
|
+
*/
|
|
385
|
+
exportBundle(name) {
|
|
386
|
+
return {
|
|
387
|
+
id: `bundle-${Date.now()}`,
|
|
388
|
+
name,
|
|
389
|
+
version: '1.0.0',
|
|
390
|
+
policies: this.getPolicies(),
|
|
391
|
+
createdAt: new Date().toISOString(),
|
|
392
|
+
updatedAt: new Date().toISOString(),
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Import policies from a bundle
|
|
397
|
+
*/
|
|
398
|
+
importBundle(bundle) {
|
|
399
|
+
for (const policy of bundle.policies) {
|
|
400
|
+
this.registerPolicy(policy);
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Validate Rego syntax (placeholder)
|
|
405
|
+
*/
|
|
406
|
+
validateRego(rego) {
|
|
407
|
+
const errors = [];
|
|
408
|
+
// Basic syntax checks
|
|
409
|
+
if (!rego.includes('package ')) {
|
|
410
|
+
errors.push('Missing package declaration');
|
|
411
|
+
}
|
|
412
|
+
if (!rego.includes('default ') && !rego.includes('allow') && !rego.includes('deny')) {
|
|
413
|
+
errors.push('Policy should define allow or deny rules');
|
|
414
|
+
}
|
|
415
|
+
return {
|
|
416
|
+
valid: errors.length === 0,
|
|
417
|
+
errors,
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
exports.PolicyEngine = PolicyEngine;
|
|
422
|
+
// Export singleton
|
|
423
|
+
exports.policyEngine = new PolicyEngine();
|
package/package.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "guardrail-compliance",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"main": "./dist/index.js",
|
|
5
|
+
"files": ["dist/**/*", "src/**/*"],
|
|
6
|
+
"types": "./dist/index.d.ts",
|
|
7
|
+
"exports": {
|
|
8
|
+
".": {
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"default": "./dist/index.js"
|
|
11
|
+
}
|
|
12
|
+
},
|
|
13
|
+
"scripts": {
|
|
14
|
+
"build": "tsc",
|
|
15
|
+
"dev": "tsc --watch",
|
|
16
|
+
"test": "vitest"
|
|
17
|
+
},
|
|
18
|
+
"dependencies": {
|
|
19
|
+
"guardrail-core": "^1.0.0",
|
|
20
|
+
"cron": "^3.1.6",
|
|
21
|
+
"nodemailer": "^7.0.12",
|
|
22
|
+
"zod": "^3.22.4"
|
|
23
|
+
},
|
|
24
|
+
"devDependencies": {
|
|
25
|
+
"@types/cron": "^2.0.1",
|
|
26
|
+
"@types/node": "^20.11.5",
|
|
27
|
+
"@types/nodemailer": "^6.4.14",
|
|
28
|
+
"typescript": "^5.9.3",
|
|
29
|
+
"vitest": "^1.2.0"
|
|
30
|
+
}
|
|
31
|
+
}
|