@highflame/policy 2.1.15 → 2.1.17

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.
@@ -0,0 +1,33 @@
1
+ // MCP Server Allowlist Template
2
+ // Only allow specific MCP servers to be used
3
+ // Category: tools
4
+ //
5
+ // NOTE: Users should customize the mcp_server values in the permit rule
6
+ // to match their allowed servers before deploying this template.
7
+
8
+ @id("mcp-allowlist-permit")
9
+ @name("Allow specific MCP servers")
10
+ @description("Only allow connections to pre-approved MCP servers (customize the list)")
11
+ @severity("medium")
12
+ @tags("mcp,allowlist,server,governance")
13
+ permit (
14
+ principal,
15
+ action == AIGateway::Action::"connect_server",
16
+ resource
17
+ )
18
+ when {
19
+ context has mcp_server &&
20
+ (context.mcp_server == "filesystem" ||
21
+ context.mcp_server == "playwright")
22
+ };
23
+
24
+ @id("mcp-allowlist-deny")
25
+ @name("Deny unallowed MCP servers")
26
+ @description("Block all MCP server connections not in the allowlist")
27
+ @severity("medium")
28
+ @tags("mcp,deny-default,server")
29
+ forbid (
30
+ principal,
31
+ action == AIGateway::Action::"connect_server",
32
+ resource
33
+ );
@@ -0,0 +1,77 @@
1
+ // =============================================================================
2
+ // MCP Tool Permissions Template (AIGateway)
3
+ // =============================================================================
4
+ // Per-tool access control for MCP servers.
5
+ // Complements the MCP Server Allowlist (connect_server action)
6
+ // with fine-grained per-tool control on call_tool action.
7
+ //
8
+ // Category: tools
9
+ // Namespace: AIGateway
10
+ // =============================================================================
11
+
12
+ // -- GitHub MCP: Read-only access -------------------------------------------
13
+
14
+ @id("mcp-tool-allow-read-github")
15
+ @name("Allow read-only GitHub tools")
16
+ @description("Permit read operations from GitHub MCP server")
17
+ @severity("medium")
18
+ @tags("mcp,github,read-only,least-privilege")
19
+ permit (
20
+ principal,
21
+ action == AIGateway::Action::"call_tool",
22
+ resource
23
+ ) when {
24
+ context has mcp_server && context.mcp_server == "github" &&
25
+ context has tool_name &&
26
+ (context.tool_name == "read_issues" ||
27
+ context.tool_name == "get_issue" ||
28
+ context.tool_name == "list_repos" ||
29
+ context.tool_name == "get_pull_request" ||
30
+ context.tool_name == "search_code" ||
31
+ context.tool_name == "get_file_contents")
32
+ };
33
+
34
+ @id("mcp-tool-deny-write-github")
35
+ @name("Deny write GitHub tools")
36
+ @description("Block create/update/delete operations on GitHub MCP server")
37
+ @severity("high")
38
+ @tags("mcp,github,write-block,least-privilege")
39
+ forbid (
40
+ principal,
41
+ action == AIGateway::Action::"call_tool",
42
+ resource
43
+ ) when {
44
+ context has mcp_server && context.mcp_server == "github"
45
+ };
46
+
47
+ // -- Organization-wide MCP server exclusions --------------------------------
48
+
49
+ @id("mcp-tool-exclude-server")
50
+ @name("Exclude specific MCP servers")
51
+ @description("Block all tool calls from excluded MCP servers (org-wide exclusion list)")
52
+ @severity("critical")
53
+ @tags("mcp,exclusion,org-wide,block")
54
+ forbid (
55
+ principal,
56
+ action == AIGateway::Action::"call_tool",
57
+ resource
58
+ ) when {
59
+ context has mcp_server &&
60
+ (context.mcp_server == "untrusted-server" ||
61
+ context.mcp_server == "deprecated-server")
62
+ };
63
+
64
+ // -- Block unverified MCP servers -------------------------------------------
65
+
66
+ @id("mcp-tool-block-unverified")
67
+ @name("Block tools from unverified MCP servers")
68
+ @description("Deny tool calls from MCP servers not in the verified registry")
69
+ @severity("high")
70
+ @tags("mcp,trust,verification")
71
+ forbid (
72
+ principal,
73
+ action == AIGateway::Action::"call_tool",
74
+ resource
75
+ ) when {
76
+ context has mcp_server_verified && context.mcp_server_verified == false
77
+ };
@@ -0,0 +1,89 @@
1
+ // =============================================================================
2
+ // PII Redaction Policy
3
+ // =============================================================================
4
+ // Block or redact requests containing personally identifiable information.
5
+ // Covers all AI Gateway actions (MCP tool calls, LLM prompts, file ops).
6
+ //
7
+ // Category: data_protection
8
+ // Namespace: AIGateway
9
+ // =============================================================================
10
+
11
+ // Block requests with PII detected
12
+ @id("data-block-pii")
13
+ @name("Block PII in requests")
14
+ @description("Block any AI Gateway operation when PII is detected in the content")
15
+ @severity("high")
16
+ @tags("pii,data-protection,owasp-llm06,dlp")
17
+ @reject_message("Request was blocked because personally identifiable information (PII) was detected. Remove sensitive data before retrying.")
18
+ forbid (
19
+ principal,
20
+ action == AIGateway::Action::"process_prompt",
21
+ resource
22
+ )
23
+ when {
24
+ context has pii_detected && context.pii_detected == true
25
+ };
26
+
27
+ // Block requests with secrets/credentials
28
+ @id("data-block-secrets")
29
+ @name("Block secrets in requests")
30
+ @description("Block any AI Gateway operation when secrets or credentials are detected")
31
+ @severity("critical")
32
+ @tags("secrets,data-protection,credentials,dlp")
33
+ @reject_message("Request was blocked because secrets or credentials were detected in the content. Remove sensitive credentials before retrying.")
34
+ forbid (
35
+ principal,
36
+ action == AIGateway::Action::"process_prompt",
37
+ resource
38
+ )
39
+ when {
40
+ context has contains_secrets && context.contains_secrets == true
41
+ };
42
+
43
+ // Block MCP tool calls with PII
44
+ @id("data-block-pii-tools")
45
+ @name("Block PII in tool calls")
46
+ @description("Block MCP tool execution when PII is detected in tool arguments")
47
+ @severity("high")
48
+ @tags("pii,tools,data-protection,dlp")
49
+ @reject_message("Tool call was blocked because PII was detected in the arguments.")
50
+ forbid (
51
+ principal,
52
+ action == AIGateway::Action::"call_tool",
53
+ resource
54
+ )
55
+ when {
56
+ context has pii_detected && context.pii_detected == true
57
+ };
58
+
59
+ // Block MCP tool calls with secrets
60
+ @id("data-block-secrets-tools")
61
+ @name("Block secrets in tool calls")
62
+ @description("Block MCP tool execution when secrets or credentials are detected")
63
+ @severity("critical")
64
+ @tags("secrets,tools,data-protection,dlp")
65
+ @reject_message("Tool call was blocked because secrets were detected in the arguments.")
66
+ forbid (
67
+ principal,
68
+ action == AIGateway::Action::"call_tool",
69
+ resource
70
+ )
71
+ when {
72
+ context has contains_secrets && context.contains_secrets == true
73
+ };
74
+
75
+ // Block bulk PII exposure (3+ PII matches)
76
+ @id("data-block-bulk-pii")
77
+ @name("Block bulk PII exposure")
78
+ @description("Block operations with 3 or more PII matches -- indicates data dump or exfiltration attempt")
79
+ @severity("critical")
80
+ @tags("pii,bulk,data-protection,exfiltration")
81
+ @reject_message("Request was blocked because multiple PII matches were detected, indicating potential data exfiltration.")
82
+ forbid (
83
+ principal,
84
+ action,
85
+ resource
86
+ )
87
+ when {
88
+ context has pii_count && context.pii_count >= 3
89
+ };
@@ -0,0 +1,117 @@
1
+ {
2
+ "service": "ai_gateway",
3
+ "version": "2.0.0",
4
+ "description": "AIGateway policy templates for MCP + LLM gateway security",
5
+ "categories": [
6
+ {
7
+ "id": "semantic",
8
+ "name": "Semantic Threat Detection",
9
+ "description": "Detect and block prompt injection, jailbreak attempts, and high-severity AI security threats"
10
+ },
11
+ {
12
+ "id": "tools",
13
+ "name": "Tool Permissioning",
14
+ "description": "Control access to MCP tools, enforce risk scoring, and manage per-tool permissions"
15
+ },
16
+ {
17
+ "id": "agent_security",
18
+ "name": "Agent Security",
19
+ "description": "Detect and block tool poisoning, rug pull attacks, indirect prompt injection, and MCP supply chain threats"
20
+ },
21
+ {
22
+ "id": "data_protection",
23
+ "name": "Data Protection",
24
+ "description": "Prevent secrets and PII leakage in LLM chat completions and MCP operations"
25
+ },
26
+ {
27
+ "id": "content_safety",
28
+ "name": "Content Safety",
29
+ "description": "Enforce content moderation score thresholds on LLM prompts and MCP content"
30
+ },
31
+ {
32
+ "id": "organization",
33
+ "name": "Organization Rules",
34
+ "description": "Apply organization-wide policy baselines for AI gateway operations"
35
+ }
36
+ ],
37
+ "defaults": [
38
+ {
39
+ "id": "baseline-default",
40
+ "name": "Baseline Permit",
41
+ "description": "Permits all actions by default -- threat-specific forbid policies override this when threats are detected",
42
+ "category": "organization",
43
+ "file": "defaults/baseline.cedar",
44
+ "severity": "low",
45
+ "tags": ["baseline", "permit-default", "organization"],
46
+ "is_active": true
47
+ },
48
+ {
49
+ "id": "semantic-default",
50
+ "name": "Semantic Threat Detection",
51
+ "description": "Detect and block prompt injection, jailbreak attempts, and high-severity threats in MCP tool calls and LLM prompts",
52
+ "category": "semantic",
53
+ "file": "defaults/semantic.cedar",
54
+ "severity": "critical",
55
+ "tags": ["prompt-injection", "jailbreak", "owasp-llm01", "owasp-llm02", "security", "baseline"],
56
+ "is_active": true
57
+ },
58
+ {
59
+ "id": "tools-default",
60
+ "name": "Tool Permissioning",
61
+ "description": "Enforce tool risk scoring, block dangerous tools, and detect command injection in MCP tool arguments",
62
+ "category": "tools",
63
+ "file": "defaults/tools.cedar",
64
+ "severity": "critical",
65
+ "tags": ["tool-risk", "command-injection", "owasp-llm06", "owasp-asi02", "baseline"],
66
+ "is_active": true
67
+ },
68
+ {
69
+ "id": "agent-security-default",
70
+ "name": "Agent Security",
71
+ "description": "Detect and block tool poisoning, rug pull attacks, indirect prompt injection, and MCP supply chain threats",
72
+ "category": "agent_security",
73
+ "file": "defaults/agent_security.cedar",
74
+ "severity": "critical",
75
+ "tags": ["tool-poisoning", "rug-pull", "indirect-injection", "mcp-security", "owasp-asi01", "owasp-asi04", "baseline"],
76
+ "is_active": true
77
+ }
78
+ ],
79
+ "templates": [
80
+ {
81
+ "id": "tools-mcp-allowlist",
82
+ "name": "MCP Server Allowlist",
83
+ "description": "Only allow specific MCP servers to be used",
84
+ "category": "tools",
85
+ "file": "mcp_server_allowlist.cedar",
86
+ "severity": "medium",
87
+ "tags": ["mcp", "allowlist", "whitelist"]
88
+ },
89
+ {
90
+ "id": "tools-mcp-tool-permissions",
91
+ "name": "MCP Tool Permissions",
92
+ "description": "Per-tool access control for MCP servers -- allow specific tools while denying others, exclude servers org-wide, block unverified sources",
93
+ "category": "tools",
94
+ "file": "mcp_tool_permissions.cedar",
95
+ "severity": "high",
96
+ "tags": ["mcp", "tools", "least-privilege", "per-server", "exclusion"]
97
+ },
98
+ {
99
+ "id": "data-pii-redaction",
100
+ "name": "PII & Secrets Redaction",
101
+ "description": "Block requests containing PII or secrets across LLM prompts and MCP tool calls -- prevents data leakage and credential exposure",
102
+ "category": "data_protection",
103
+ "file": "pii_redaction.cedar",
104
+ "severity": "high",
105
+ "tags": ["pii", "secrets", "data-protection", "dlp", "owasp-llm06"]
106
+ },
107
+ {
108
+ "id": "llm-default-allow",
109
+ "name": "Default Allow LLM Proxy",
110
+ "description": "Permit all LLM chat completion requests by default -- deploy alongside threat-specific forbid policies for a default-allow posture",
111
+ "category": "organization",
112
+ "file": "llm_default_allow.cedar",
113
+ "severity": "low",
114
+ "tags": ["llm", "permit-default", "proxy", "organization"]
115
+ }
116
+ ]
117
+ }
@@ -0,0 +1,53 @@
1
+ /**
2
+ * Context attribute keys for AiGateway Context attributes for AIGateway Cedar policies (MCP + LLM).
3
+ *
4
+ * These constants correspond to the context attributes defined in the
5
+ * AiGateway Cedar schema and are used at policy evaluation time.
6
+ */
7
+ export declare const AiGatewayContextKey: {
8
+ readonly ContainsInvisibleChars: "contains_invisible_chars";
9
+ readonly ContainsSecrets: "contains_secrets";
10
+ readonly Content: "content";
11
+ readonly CrimeScore: "crime_score";
12
+ readonly DetectedThreats: "detected_threats";
13
+ readonly HateSpeechScore: "hate_speech_score";
14
+ readonly HighestSeverity: "highest_severity";
15
+ readonly IndirectInjectionScore: "indirect_injection_score";
16
+ readonly InjectionConfidence: "injection_confidence";
17
+ readonly InvisibleCharsScore: "invisible_chars_score";
18
+ readonly JailbreakConfidence: "jailbreak_confidence";
19
+ readonly LoopCount: "loop_count";
20
+ readonly LoopDetected: "loop_detected";
21
+ readonly MaxThreatSeverity: "max_threat_severity";
22
+ readonly McpConfigRisk: "mcp_config_risk";
23
+ readonly McpRiskScore: "mcp_risk_score";
24
+ readonly McpServer: "mcp_server";
25
+ readonly McpServerVerified: "mcp_server_verified";
26
+ readonly McpTool: "mcp_tool";
27
+ readonly ModelName: "model_name";
28
+ readonly ModelProvider: "model_provider";
29
+ readonly PatternType: "pattern_type";
30
+ readonly PiiCount: "pii_count";
31
+ readonly PiiDetected: "pii_detected";
32
+ readonly PiiTypes: "pii_types";
33
+ readonly ProfanityScore: "profanity_score";
34
+ readonly RugPullDetected: "rug_pull_detected";
35
+ readonly RugPullScore: "rug_pull_score";
36
+ readonly SecretCount: "secret_count";
37
+ readonly SecretTypes: "secret_types";
38
+ readonly SequenceRisk: "sequence_risk";
39
+ readonly SexualScore: "sexual_score";
40
+ readonly SuspiciousPattern: "suspicious_pattern";
41
+ readonly ThreatCategories: "threat_categories";
42
+ readonly ThreatCount: "threat_count";
43
+ readonly ToolCategory: "tool_category";
44
+ readonly ToolIsBuiltin: "tool_is_builtin";
45
+ readonly ToolIsSensitive: "tool_is_sensitive";
46
+ readonly ToolName: "tool_name";
47
+ readonly ToolPoisoningDetected: "tool_poisoning_detected";
48
+ readonly ToolPoisoningScore: "tool_poisoning_score";
49
+ readonly ToolRiskScore: "tool_risk_score";
50
+ readonly ViolenceScore: "violence_score";
51
+ readonly WeaponsScore: "weapons_score";
52
+ };
53
+ export type AiGatewayContextKey = (typeof AiGatewayContextKey)[keyof typeof AiGatewayContextKey];
@@ -0,0 +1,54 @@
1
+ // Code generated by highflame-policy-codegen. DO NOT EDIT.
2
+ // Source: schemas/ai_gateway/context.json
3
+ /**
4
+ * Context attribute keys for AiGateway Context attributes for AIGateway Cedar policies (MCP + LLM).
5
+ *
6
+ * These constants correspond to the context attributes defined in the
7
+ * AiGateway Cedar schema and are used at policy evaluation time.
8
+ */
9
+ export const AiGatewayContextKey = {
10
+ ContainsInvisibleChars: 'contains_invisible_chars',
11
+ ContainsSecrets: 'contains_secrets',
12
+ Content: 'content',
13
+ CrimeScore: 'crime_score',
14
+ DetectedThreats: 'detected_threats',
15
+ HateSpeechScore: 'hate_speech_score',
16
+ HighestSeverity: 'highest_severity',
17
+ IndirectInjectionScore: 'indirect_injection_score',
18
+ InjectionConfidence: 'injection_confidence',
19
+ InvisibleCharsScore: 'invisible_chars_score',
20
+ JailbreakConfidence: 'jailbreak_confidence',
21
+ LoopCount: 'loop_count',
22
+ LoopDetected: 'loop_detected',
23
+ MaxThreatSeverity: 'max_threat_severity',
24
+ McpConfigRisk: 'mcp_config_risk',
25
+ McpRiskScore: 'mcp_risk_score',
26
+ McpServer: 'mcp_server',
27
+ McpServerVerified: 'mcp_server_verified',
28
+ McpTool: 'mcp_tool',
29
+ ModelName: 'model_name',
30
+ ModelProvider: 'model_provider',
31
+ PatternType: 'pattern_type',
32
+ PiiCount: 'pii_count',
33
+ PiiDetected: 'pii_detected',
34
+ PiiTypes: 'pii_types',
35
+ ProfanityScore: 'profanity_score',
36
+ RugPullDetected: 'rug_pull_detected',
37
+ RugPullScore: 'rug_pull_score',
38
+ SecretCount: 'secret_count',
39
+ SecretTypes: 'secret_types',
40
+ SequenceRisk: 'sequence_risk',
41
+ SexualScore: 'sexual_score',
42
+ SuspiciousPattern: 'suspicious_pattern',
43
+ ThreatCategories: 'threat_categories',
44
+ ThreatCount: 'threat_count',
45
+ ToolCategory: 'tool_category',
46
+ ToolIsBuiltin: 'tool_is_builtin',
47
+ ToolIsSensitive: 'tool_is_sensitive',
48
+ ToolName: 'tool_name',
49
+ ToolPoisoningDetected: 'tool_poisoning_detected',
50
+ ToolPoisoningScore: 'tool_poisoning_score',
51
+ ToolRiskScore: 'tool_risk_score',
52
+ ViolenceScore: 'violence_score',
53
+ WeaponsScore: 'weapons_score',
54
+ };
@@ -0,0 +1,61 @@
1
+ /**
2
+ * AiGateway policy category identifiers.
3
+ * Maps to UI tab names in Studio.
4
+ */
5
+ export type AiGatewayCategory = 'semantic' | 'tools' | 'agent_security' | 'data_protection' | 'content_safety' | 'organization';
6
+ /**
7
+ * Category metadata for UI display.
8
+ */
9
+ export interface AiGatewayCategoryInfo {
10
+ id: AiGatewayCategory;
11
+ name: string;
12
+ description: string;
13
+ }
14
+ /**
15
+ * A default policy that is auto-created for new projects.
16
+ */
17
+ export interface AiGatewayDefaultPolicy {
18
+ /** Template identifier */
19
+ id: string;
20
+ /** Human-readable name */
21
+ name: string;
22
+ /** Description for UI display */
23
+ description: string;
24
+ /** Policy category */
25
+ category: AiGatewayCategory;
26
+ /** Cedar policy text (source of truth) */
27
+ cedarText: string;
28
+ /** Severity level */
29
+ severity: string;
30
+ /** Tags for filtering */
31
+ tags: string[];
32
+ /** Whether this default should be activated immediately */
33
+ isActive: boolean;
34
+ }
35
+ /**
36
+ * A policy template available for users to create from.
37
+ */
38
+ export interface AiGatewayTemplate {
39
+ /** Template identifier */
40
+ id: string;
41
+ /** Human-readable name */
42
+ name: string;
43
+ /** Description for UI display */
44
+ description: string;
45
+ /** Policy category */
46
+ category: AiGatewayCategory;
47
+ /** Cedar policy text */
48
+ cedarText: string;
49
+ /** Severity level */
50
+ severity: string;
51
+ /** Tags for filtering */
52
+ tags: string[];
53
+ }
54
+ export declare const AI_GATEWAY_CATEGORIES: AiGatewayCategoryInfo[];
55
+ export declare const AI_GATEWAY_DEFAULTS: AiGatewayDefaultPolicy[];
56
+ export declare const AI_GATEWAY_TEMPLATES: AiGatewayTemplate[];
57
+ /** Raw templates.json metadata for the AiGateway service. */
58
+ export declare const AI_GATEWAY_TEMPLATES_JSON: string;
59
+ export declare function getAiGatewayDefaultsByCategory(category: AiGatewayCategory): AiGatewayDefaultPolicy[];
60
+ export declare function getAiGatewayTemplatesByCategory(category: AiGatewayCategory): AiGatewayTemplate[];
61
+ export declare function getAiGatewayTemplateById(id: string): AiGatewayTemplate | undefined;