@highflame/policy 1.2.1 → 2.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/README.md +219 -0
- package/_schemas/overwatch/context.json +463 -0
- package/_schemas/overwatch/schema.cedarschema +184 -0
- package/_schemas/palisade/context.json +325 -0
- package/_schemas/palisade/schema.cedarschema +168 -0
- package/dist/builder.d.ts +1 -2
- package/dist/builder.d.ts.map +1 -1
- package/dist/builder.js.map +1 -1
- package/dist/context.gen.d.ts +1 -94
- package/dist/context.gen.d.ts.map +1 -1
- package/dist/context.gen.js +1 -97
- package/dist/context.gen.js.map +1 -1
- package/dist/engine.d.ts +18 -18
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +44 -28
- package/dist/engine.js.map +1 -1
- package/dist/engine.test.js.map +1 -1
- package/dist/entities.gen.d.ts +1 -0
- package/dist/entities.gen.d.ts.map +1 -1
- package/dist/entities.gen.js +1 -0
- package/dist/entities.gen.js.map +1 -1
- package/dist/overwatch-context.gen.d.ts +31 -0
- package/dist/overwatch-context.gen.d.ts.map +1 -0
- package/dist/overwatch-context.gen.js +32 -0
- package/dist/overwatch-context.gen.js.map +1 -0
- package/dist/palisade-context.gen.d.ts +25 -0
- package/dist/palisade-context.gen.d.ts.map +1 -0
- package/dist/palisade-context.gen.js +26 -0
- package/dist/palisade-context.gen.js.map +1 -0
- package/dist/schema.gen.d.ts +1 -1
- package/dist/schema.gen.d.ts.map +1 -1
- package/dist/schema.gen.js +60 -541
- package/dist/schema.gen.js.map +1 -1
- package/dist/schemas.d.ts +64 -0
- package/dist/schemas.d.ts.map +1 -0
- package/dist/schemas.js +70 -0
- package/dist/schemas.js.map +1 -0
- package/dist/schemas.test.d.ts +8 -0
- package/dist/schemas.test.d.ts.map +1 -0
- package/dist/schemas.test.js +381 -0
- package/dist/schemas.test.js.map +1 -0
- package/package.json +9 -6
- package/src/builder.ts +1 -2
- package/src/context.gen.ts +0 -97
- package/src/engine.test.ts +0 -1
- package/src/engine.ts +62 -33
- package/src/entities.gen.ts +1 -0
- package/src/overwatch-context.gen.ts +34 -0
- package/src/palisade-context.gen.ts +28 -0
- package/src/schema.gen.ts +60 -541
- package/src/schemas.test.ts +449 -0
- package/src/schemas.ts +91 -0
package/src/context.gen.ts
CHANGED
|
@@ -5,103 +5,6 @@
|
|
|
5
5
|
* Context attribute keys for Cedar policy evaluation.
|
|
6
6
|
*/
|
|
7
7
|
export const ContextKey = {
|
|
8
|
-
// Guardrails/Core context attributes
|
|
9
|
-
/** Name of tool being called */
|
|
10
|
-
ToolName: 'tool_name',
|
|
11
|
-
/** Name of resource being accessed */
|
|
12
|
-
ResourceName: 'resource_name',
|
|
13
|
-
/** Name of prompt */
|
|
14
|
-
PromptName: 'prompt_name',
|
|
15
|
-
/** Raw prompt text */
|
|
16
|
-
PromptText: 'prompt_text',
|
|
17
|
-
/** Response size in megabytes */
|
|
18
|
-
ResponseSizeMb: 'response_size_mb',
|
|
19
|
-
/** Set of detected YARA threat names */
|
|
20
|
-
YaraThreats: 'yara_threats',
|
|
21
|
-
/** Number of threats detected */
|
|
22
|
-
ThreatCount: 'threat_count',
|
|
23
|
-
/** Highest severity (0-4) */
|
|
24
|
-
MaxThreatSeverity: 'max_threat_severity',
|
|
25
|
-
/** User type: external or internal */
|
|
26
|
-
UserType: 'user_type',
|
|
27
|
-
/** Whether monitoring is active */
|
|
28
|
-
MonitoringEnabled: 'monitoring_enabled',
|
|
29
|
-
/** File path */
|
|
30
|
-
Path: 'path',
|
|
31
|
-
/** HTTP hostname */
|
|
32
|
-
Hostname: 'hostname',
|
|
33
|
-
/** IP address */
|
|
34
|
-
IpAddress: 'ip_address',
|
|
35
|
-
/** Whether the IP is private/loopback (set by application layer) */
|
|
36
|
-
IsPrivateIp: 'is_private_ip',
|
|
37
|
-
/** HTTP scheme */
|
|
38
|
-
Scheme: 'scheme',
|
|
39
|
-
/** Port number */
|
|
40
|
-
Port: 'port',
|
|
41
|
-
|
|
42
|
-
// Palisade context attributes
|
|
43
|
-
/** Environment: production, development, research */
|
|
44
|
-
Environment: 'environment',
|
|
45
|
-
/** Format: pickle, safetensors, gguf, onnx */
|
|
46
|
-
ArtifactFormat: 'artifact_format',
|
|
47
|
-
/** Whether artifact has signature */
|
|
48
|
-
ArtifactSigned: 'artifact_signed',
|
|
49
|
-
/** Severity: CRITICAL, HIGH, MEDIUM, LOW, INFO */
|
|
50
|
-
Severity: 'severity',
|
|
51
|
-
/** Type of security finding */
|
|
52
|
-
FindingType: 'finding_type',
|
|
53
|
-
/** Who signed the artifact */
|
|
54
|
-
ProvenanceSigner: 'provenance_signer',
|
|
55
|
-
/** RCE path found in pickle */
|
|
56
|
-
PickleExecPathDetected: 'pickle_exec_path_detected',
|
|
57
|
-
/** Malicious pattern in metadata */
|
|
58
|
-
MetadataMaliciousPattern: 'metadata_malicious_pattern',
|
|
59
|
-
/** Number of added tokens */
|
|
60
|
-
TokenizerAddedTokensCount: 'tokenizer_added_tokens_count',
|
|
61
|
-
/** Safetensors integrity failed */
|
|
62
|
-
SafetensorsIntegrityViolation: 'safetensors_integrity_violation',
|
|
63
|
-
/** Suspicious GGUF metadata */
|
|
64
|
-
GgufSuspiciousMetadata: 'gguf_suspicious_metadata',
|
|
65
|
-
/** LoRA adapter digest mismatch */
|
|
66
|
-
AdapterBaseDigestMismatch: 'adapter_base_digest_mismatch',
|
|
67
|
-
/** CoSAI maturity level (0-5) */
|
|
68
|
-
MetadataCosaiLevelNumeric: 'metadata_cosai_level_numeric',
|
|
69
|
-
|
|
70
|
-
// Overwatch context attributes
|
|
71
|
-
/** IDE source: cursor, claudecode, vscode, geminicli */
|
|
72
|
-
Source: 'source',
|
|
73
|
-
/** Hook event type: beforeShellExecution, PreToolUse, etc. */
|
|
74
|
-
Event: 'event',
|
|
75
|
-
/** The prompt/request content being evaluated */
|
|
76
|
-
Content: 'content',
|
|
77
|
-
/** User's email address (or 'anonymous') */
|
|
78
|
-
UserEmail: 'user_email',
|
|
79
|
-
/** Custom principal ID for policy evaluation */
|
|
80
|
-
CedarPrincipal: 'cedar_principal',
|
|
81
|
-
/** MCP server name: filesystem, playwright, etc. */
|
|
82
|
-
ServerName: 'server_name',
|
|
83
|
-
/** Whether the path is within the workspace */
|
|
84
|
-
IsWithinWorkspace: 'is_within_workspace',
|
|
85
|
-
/** Response content from tool execution */
|
|
86
|
-
ResponseContent: 'response_content',
|
|
87
|
-
/** Highest severity level: critical, high, medium, low */
|
|
88
|
-
HighestSeverity: 'highest_severity',
|
|
89
|
-
/** Array of threat types detected */
|
|
90
|
-
ThreatTypes: 'threat_types',
|
|
91
|
-
/** Array of threat categories found */
|
|
92
|
-
ThreatCategories: 'threat_categories',
|
|
93
|
-
/** Whether secrets were detected in the content */
|
|
94
|
-
ContainsSecrets: 'contains_secrets',
|
|
95
|
-
/** Number of concurrent calls */
|
|
96
|
-
ConcurrentCalls: 'concurrent_calls',
|
|
97
|
-
/** Request rate per minute */
|
|
98
|
-
RequestsPerMinute: 'requests_per_minute',
|
|
99
|
-
/** User trust level: high, medium, low */
|
|
100
|
-
UserTrustLevel: 'user_trust_level',
|
|
101
|
-
/** Whether alerting is enabled for this request */
|
|
102
|
-
AlertEnabled: 'alert_enabled',
|
|
103
|
-
/** Type of security scan being performed */
|
|
104
|
-
ScanType: 'scan_type',
|
|
105
8
|
} as const;
|
|
106
9
|
|
|
107
10
|
export type ContextKey = (typeof ContextKey)[keyof typeof ContextKey];
|
package/src/engine.test.ts
CHANGED
package/src/engine.ts
CHANGED
|
@@ -6,7 +6,6 @@
|
|
|
6
6
|
import * as cedar from "@cedar-policy/cedar-wasm/nodejs";
|
|
7
7
|
import { EntityType, EntityUID, Entity } from "./entities.gen.js";
|
|
8
8
|
import { ActionType } from "./actions.gen.js";
|
|
9
|
-
import { CEDAR_SCHEMA } from "./schema.gen.js";
|
|
10
9
|
|
|
11
10
|
// =============================================================================
|
|
12
11
|
// INPUT VALIDATION LIMITS (consistent across all language SDKs)
|
|
@@ -35,6 +34,8 @@ export interface InputLimits {
|
|
|
35
34
|
}
|
|
36
35
|
|
|
37
36
|
export interface EngineOptions {
|
|
37
|
+
/** Cedar schema string (optional - can also use loadSchema() method) */
|
|
38
|
+
schema?: string;
|
|
38
39
|
/** Custom input validation limits */
|
|
39
40
|
limits?: InputLimits;
|
|
40
41
|
/** Skip input validation (not recommended for production) */
|
|
@@ -142,9 +143,15 @@ export interface Decision {
|
|
|
142
143
|
|
|
143
144
|
export interface EvaluateRequest {
|
|
144
145
|
principal: EntityUID;
|
|
145
|
-
|
|
146
|
+
/**
|
|
147
|
+
* Action to evaluate. Can be:
|
|
148
|
+
* - A generated ActionType value (e.g., ActionType.CallTool)
|
|
149
|
+
* - A namespaced action string (e.g., 'Overwatch::Action::"call_tool"')
|
|
150
|
+
*/
|
|
151
|
+
action: ActionType | string;
|
|
146
152
|
resource: EntityUID;
|
|
147
153
|
context?: Record<string, unknown>;
|
|
154
|
+
entities?: Entity[];
|
|
148
155
|
}
|
|
149
156
|
|
|
150
157
|
/**
|
|
@@ -170,6 +177,33 @@ function toCedarValue(value: unknown): cedar.CedarValueJson {
|
|
|
170
177
|
return String(value);
|
|
171
178
|
}
|
|
172
179
|
|
|
180
|
+
/**
|
|
181
|
+
* Parse an action string into Cedar EntityUID format.
|
|
182
|
+
* Handles both non-namespaced and namespaced actions:
|
|
183
|
+
* - "call_tool" → { type: "Action", id: "call_tool" }
|
|
184
|
+
* - "Overwatch::Action::\"call_tool\"" → { type: "Overwatch::Action", id: "call_tool" }
|
|
185
|
+
* - "Overwatch::Action::call_tool" → { type: "Overwatch::Action", id: "call_tool" }
|
|
186
|
+
*/
|
|
187
|
+
function parseActionString(action: string): cedar.EntityUidJson {
|
|
188
|
+
// Check if action contains namespace separator
|
|
189
|
+
if (!action.includes("::")) {
|
|
190
|
+
// Non-namespaced action
|
|
191
|
+
return { type: "Action", id: action };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
// Namespaced action - find the last :: separator
|
|
195
|
+
const lastSeparator = action.lastIndexOf("::");
|
|
196
|
+
const actionType = action.substring(0, lastSeparator);
|
|
197
|
+
let actionId = action.substring(lastSeparator + 2);
|
|
198
|
+
|
|
199
|
+
// Remove surrounding quotes if present (e.g., "call_tool" → call_tool)
|
|
200
|
+
if (actionId.startsWith('"') && actionId.endsWith('"')) {
|
|
201
|
+
actionId = actionId.slice(1, -1);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
return { type: actionType, id: actionId };
|
|
205
|
+
}
|
|
206
|
+
|
|
173
207
|
/**
|
|
174
208
|
* PolicyEngine wraps cedar-wasm with Highflame schema types.
|
|
175
209
|
*/
|
|
@@ -181,6 +215,7 @@ export class PolicyEngine {
|
|
|
181
215
|
|
|
182
216
|
constructor(options?: EngineOptions) {
|
|
183
217
|
this.options = options ?? {};
|
|
218
|
+
this.schema = options?.schema;
|
|
184
219
|
this.limits = {
|
|
185
220
|
maxContextKeys: options?.limits?.maxContextKeys ?? DEFAULT_LIMITS.maxContextKeys,
|
|
186
221
|
maxStringLength: options?.limits?.maxStringLength ?? DEFAULT_LIMITS.maxStringLength,
|
|
@@ -198,19 +233,11 @@ export class PolicyEngine {
|
|
|
198
233
|
|
|
199
234
|
/**
|
|
200
235
|
* Load schema from a Cedar schema string.
|
|
201
|
-
* If not called, uses the embedded Highflame schema.
|
|
202
236
|
*/
|
|
203
237
|
loadSchema(schema: string): void {
|
|
204
238
|
this.schema = schema;
|
|
205
239
|
}
|
|
206
240
|
|
|
207
|
-
/**
|
|
208
|
-
* Load the embedded Highflame schema.
|
|
209
|
-
*/
|
|
210
|
-
loadHighflameSchema(): void {
|
|
211
|
-
this.schema = CEDAR_SCHEMA;
|
|
212
|
-
}
|
|
213
|
-
|
|
214
241
|
/**
|
|
215
242
|
* Evaluate a policy request and return a decision.
|
|
216
243
|
* @throws InputValidationError if context validation fails
|
|
@@ -226,10 +253,7 @@ export class PolicyEngine {
|
|
|
226
253
|
type: req.principal.type,
|
|
227
254
|
id: req.principal.id,
|
|
228
255
|
};
|
|
229
|
-
const action: cedar.EntityUidJson =
|
|
230
|
-
type: "Action",
|
|
231
|
-
id: req.action,
|
|
232
|
-
};
|
|
256
|
+
const action: cedar.EntityUidJson = parseActionString(req.action);
|
|
233
257
|
const resource: cedar.EntityUidJson = {
|
|
234
258
|
type: req.resource.type,
|
|
235
259
|
id: req.resource.id,
|
|
@@ -243,6 +267,15 @@ export class PolicyEngine {
|
|
|
243
267
|
}
|
|
244
268
|
}
|
|
245
269
|
|
|
270
|
+
// Convert entities to Cedar JSON format
|
|
271
|
+
const entities = (req.entities || []).map(e => ({
|
|
272
|
+
uid: e.uid,
|
|
273
|
+
attrs: e.attrs ? Object.fromEntries(
|
|
274
|
+
Object.entries(e.attrs).map(([k, v]) => [k, toCedarValue(v)])
|
|
275
|
+
) : {},
|
|
276
|
+
parents: e.parents || [],
|
|
277
|
+
}));
|
|
278
|
+
|
|
246
279
|
// Build the authorization call
|
|
247
280
|
const call: cedar.AuthorizationCall = {
|
|
248
281
|
principal,
|
|
@@ -250,7 +283,7 @@ export class PolicyEngine {
|
|
|
250
283
|
resource,
|
|
251
284
|
context,
|
|
252
285
|
policies: { staticPolicies: this.policies },
|
|
253
|
-
entities
|
|
286
|
+
entities,
|
|
254
287
|
};
|
|
255
288
|
|
|
256
289
|
// Add schema if available
|
|
@@ -284,7 +317,7 @@ export class PolicyEngine {
|
|
|
284
317
|
evaluateSimple(
|
|
285
318
|
principalType: EntityType,
|
|
286
319
|
principalId: string,
|
|
287
|
-
action: ActionType,
|
|
320
|
+
action: ActionType | string,
|
|
288
321
|
resourceType: EntityType,
|
|
289
322
|
resourceId: string,
|
|
290
323
|
context?: Record<string, unknown>
|
|
@@ -302,11 +335,13 @@ export class PolicyEngine {
|
|
|
302
335
|
* Returns validation errors or empty array if valid.
|
|
303
336
|
*/
|
|
304
337
|
validatePolicies(policies: string): string[] {
|
|
305
|
-
|
|
338
|
+
if (!this.schema) {
|
|
339
|
+
throw new Error("Schema is required for validation. Provide schema via constructor options or loadSchema().");
|
|
340
|
+
}
|
|
306
341
|
|
|
307
342
|
const result = cedar.validate({
|
|
308
343
|
validationSettings: { mode: "strict" },
|
|
309
|
-
schema:
|
|
344
|
+
schema: this.schema,
|
|
310
345
|
policies: { staticPolicies: policies },
|
|
311
346
|
});
|
|
312
347
|
|
|
@@ -326,10 +361,11 @@ export class PolicyValidator {
|
|
|
326
361
|
private schema: string;
|
|
327
362
|
|
|
328
363
|
/**
|
|
329
|
-
* Create a validator with
|
|
364
|
+
* Create a validator with a Cedar schema.
|
|
365
|
+
* @param schema Cedar schema string (required)
|
|
330
366
|
*/
|
|
331
|
-
constructor(schema
|
|
332
|
-
this.schema = schema
|
|
367
|
+
constructor(schema: string) {
|
|
368
|
+
this.schema = schema;
|
|
333
369
|
}
|
|
334
370
|
|
|
335
371
|
/**
|
|
@@ -375,23 +411,16 @@ export class PolicyValidator {
|
|
|
375
411
|
}
|
|
376
412
|
|
|
377
413
|
/**
|
|
378
|
-
* Validate a Cedar policy against
|
|
414
|
+
* Validate a Cedar policy against a schema.
|
|
379
415
|
* Convenience function that doesn't require creating a validator instance.
|
|
416
|
+
* @param schema Cedar schema string
|
|
417
|
+
* @param policy Policy text to validate
|
|
380
418
|
*/
|
|
381
|
-
export function validatePolicy(policy: string): { valid: boolean; errors: string[] } {
|
|
382
|
-
const validator = new PolicyValidator();
|
|
419
|
+
export function validatePolicy(schema: string, policy: string): { valid: boolean; errors: string[] } {
|
|
420
|
+
const validator = new PolicyValidator(schema);
|
|
383
421
|
return validator.validate(policy);
|
|
384
422
|
}
|
|
385
423
|
|
|
386
|
-
/**
|
|
387
|
-
* Get the embedded Highflame Cedar schema.
|
|
388
|
-
*/
|
|
389
|
-
export function getHighflameSchema(): string {
|
|
390
|
-
return CEDAR_SCHEMA;
|
|
391
|
-
}
|
|
392
|
-
|
|
393
424
|
// Re-export types
|
|
394
425
|
export { EntityType, EntityUID, Entity, newEntityUID, newEntity } from "./entities.gen.js";
|
|
395
426
|
export { ActionType, actionUID } from "./actions.gen.js";
|
|
396
|
-
export * from "./context.gen.js";
|
|
397
|
-
export { CEDAR_SCHEMA } from "./schema.gen.js";
|
package/src/entities.gen.ts
CHANGED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
// Code generated by highflame-policy-codegen. DO NOT EDIT.
|
|
2
|
+
// Source: schemas/overwatch/context.json
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context attribute keys for Overwatch Overwatch (Guardian) IDE security & policy enforcement.
|
|
6
|
+
*
|
|
7
|
+
* These constants correspond to the context attributes defined in the
|
|
8
|
+
* Overwatch Cedar schema and are used at policy evaluation time.
|
|
9
|
+
*/
|
|
10
|
+
export const OverwatchContextKey = {
|
|
11
|
+
ContainsSecrets: 'contains_secrets',
|
|
12
|
+
Content: 'content',
|
|
13
|
+
Cwd: 'cwd',
|
|
14
|
+
Event: 'event',
|
|
15
|
+
FilePath: 'file_path',
|
|
16
|
+
HighestSeverity: 'highest_severity',
|
|
17
|
+
MaxThreatSeverity: 'max_threat_severity',
|
|
18
|
+
McpServer: 'mcp_server',
|
|
19
|
+
McpTool: 'mcp_tool',
|
|
20
|
+
Path: 'path',
|
|
21
|
+
PromptText: 'prompt_text',
|
|
22
|
+
ResponseContent: 'response_content',
|
|
23
|
+
ServerName: 'server_name',
|
|
24
|
+
Source: 'source',
|
|
25
|
+
ThreatCategories: 'threat_categories',
|
|
26
|
+
ThreatCount: 'threat_count',
|
|
27
|
+
ThreatTypes: 'threat_types',
|
|
28
|
+
ToolName: 'tool_name',
|
|
29
|
+
UserEmail: 'user_email',
|
|
30
|
+
WorkspaceRoot: 'workspace_root',
|
|
31
|
+
YaraThreats: 'yara_threats',
|
|
32
|
+
} as const;
|
|
33
|
+
|
|
34
|
+
export type OverwatchContextKey = (typeof OverwatchContextKey)[keyof typeof OverwatchContextKey];
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// Code generated by highflame-policy-codegen. DO NOT EDIT.
|
|
2
|
+
// Source: schemas/palisade/context.json
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Context attribute keys for Palisade Palisade ML supply chain security & artifact scanning.
|
|
6
|
+
*
|
|
7
|
+
* These constants correspond to the context attributes defined in the
|
|
8
|
+
* Palisade Cedar schema and are used at policy evaluation time.
|
|
9
|
+
*/
|
|
10
|
+
export const PalisadeContextKey = {
|
|
11
|
+
AdapterBaseDigestMismatch: 'adapter_base_digest_mismatch',
|
|
12
|
+
ArtifactFormat: 'artifact_format',
|
|
13
|
+
ArtifactSigned: 'artifact_signed',
|
|
14
|
+
Environment: 'environment',
|
|
15
|
+
FindingType: 'finding_type',
|
|
16
|
+
GgufSuspiciousMetadata: 'gguf_suspicious_metadata',
|
|
17
|
+
MatchCount: 'match_count',
|
|
18
|
+
MetadataCosaiLevelNumeric: 'metadata_cosai_level_numeric',
|
|
19
|
+
MetadataMaliciousPattern: 'metadata_malicious_pattern',
|
|
20
|
+
Path: 'path',
|
|
21
|
+
PickleExecPathDetected: 'pickle_exec_path_detected',
|
|
22
|
+
ProvenanceSigner: 'provenance_signer',
|
|
23
|
+
SafetensorsIntegrityViolation: 'safetensors_integrity_violation',
|
|
24
|
+
Severity: 'severity',
|
|
25
|
+
TokenizerAddedTokensCount: 'tokenizer_added_tokens_count',
|
|
26
|
+
} as const;
|
|
27
|
+
|
|
28
|
+
export type PalisadeContextKey = (typeof PalisadeContextKey)[keyof typeof PalisadeContextKey];
|