Skip to content

Evenfire is an intelligence layer platform for running LLM agents that take real actions, on your infrastructure

TypeScript

fix(guardrails): gate preCall/onError egress hooks as content-bearing (§8.4)

Andy Pavia41cfd1a54a5e
diff --git a/control-api/package-lock.json b/control-api/package-lock.json
index e580496e1..7a68d2d8d 100644
--- a/control-api/package-lock.json
+++ b/control-api/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-control-api",
- "version": "0.1.439",
+ "version": "0.1.440",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-control-api",
- "version": "0.1.439",
+ "version": "0.1.440",
"dependencies": {
"@clerum/image-policy": "file:../packages/image-policy",
"@clerum/llm-providers": "file:../packages/llm-providers",
diff --git a/control-api/package.json b/control-api/package.json
index cde104553..caddbdcb8 100644
--- a/control-api/package.json
+++ b/control-api/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-control-api",
- "version": "0.1.439",
+ "version": "0.1.440",
"description": "Internal Clerum control plane REST API + UI for managing CRDs and secrets",
"main": "dist/main.js",
"engines": {
diff --git a/control-api/src/routes/admin/__tests__/installHookTrust.test.ts b/control-api/src/routes/admin/__tests__/installHookTrust.test.ts
index a6074a54b..7fa80bc04 100644
--- a/control-api/src/routes/admin/__tests__/installHookTrust.test.ts
+++ b/control-api/src/routes/admin/__tests__/installHookTrust.test.ts
@@ -8,7 +8,11 @@
* Every non-curated org is capped at the default cap (mid).
*/
import { describe, expect, it } from 'vitest'
-import { resolveHookTrustLevel } from '../registry.js'
+import {
+ contentEgressRequiresHighTrust,
+ isContentBearingHook,
+ resolveHookTrustLevel,
+} from '../registry.js'
const entry = (name: string, trust_level: string) => ({ name, trust_level })
@@ -42,3 +46,76 @@ describe('resolveHookTrustLevel', () => {
expect(resolveHookTrustLevel(entry('@clerum/x', ''), null)).toBe('low')
})
})
+
+describe('content-bearing classification (§8.4/§8.7 fix A)', () => {
+ it('every message-carrying point is content-bearing — incl. preCall and onError', () => {
+ expect(isContentBearingHook(['preCall'])).toBe(true)
+ expect(isContentBearingHook(['moderate'])).toBe(true)
+ expect(isContentBearingHook(['postCallSuccess'])).toBe(true)
+ expect(isContentBearingHook(['onError'])).toBe(true)
+ })
+
+ it('an empty/unknown point set is not content-bearing', () => {
+ expect(isContentBearingHook([])).toBe(false)
+ expect(isContentBearingHook(undefined)).toBe(false)
+ expect(isContentBearingHook(['somethingElse'])).toBe(false)
+ })
+})
+
+describe('content/egress separation gate (§8.4)', () => {
+ // The hole fix A closes: a preCall/onError egress hook below high trust must be refused.
+ it('preCall + egress at mid trust → requires high (blocked)', () => {
+ expect(
+ contentEgressRequiresHighTrust({
+ lifecyclePoints: ['preCall'],
+ hasEgress: true,
+ isRemote: false,
+ trustLevel: 'mid',
+ })
+ ).toBe(true)
+ })
+
+ it('onError + remote target at low trust → requires high (blocked)', () => {
+ expect(
+ contentEgressRequiresHighTrust({
+ lifecyclePoints: ['onError'],
+ hasEgress: false,
+ isRemote: true,
+ trustLevel: 'low',
+ })
+ ).toBe(true)
+ })
+
+ it('moderate + egress at high trust → allowed', () => {
+ expect(
+ contentEgressRequiresHighTrust({
+ lifecyclePoints: ['moderate'],
+ hasEgress: true,
+ isRemote: false,
+ trustLevel: 'high',
+ })
+ ).toBe(false)
+ })
+
+ it('content WITHOUT egress at low trust → allowed (can see content, cannot exfiltrate)', () => {
+ expect(
+ contentEgressRequiresHighTrust({
+ lifecyclePoints: ['preCall'],
+ hasEgress: false,
+ isRemote: false,
+ trustLevel: 'low',
+ })
+ ).toBe(false)
+ })
+
+ it('egress WITHOUT content at low trust → allowed (nothing to leak)', () => {
+ expect(
+ contentEgressRequiresHighTrust({
+ lifecyclePoints: [],
+ hasEgress: true,
+ isRemote: false,
+ trustLevel: 'low',
+ })
+ ).toBe(false)
+ })
+})
diff --git a/control-api/src/routes/admin/registry.ts b/control-api/src/routes/admin/registry.ts
index d7b40a282..c951cdbce 100644
--- a/control-api/src/routes/admin/registry.ts
+++ b/control-api/src/routes/admin/registry.ts
@@ -131,9 +131,42 @@ const NO_CREDENTIAL_SCHEMA: RegistryCredentialSchema = {
// ── install-hook trust policy (guardrails spec §8.4) ────────────────────────
const HOOK_TRUST_ORDER: Record<string, number> = { low: 0, mid: 1, high: 2 }
-// Lifecycle points that receive message/response CONTENT (§8.4). pre_call shaping
-// gets model+params+metadata, not bodies, so it is not content-bearing.
-const CONTENT_BEARING_POINTS = new Set(['moderate', 'postCallSuccess'])
+// Lifecycle points that receive message/response CONTENT (§8.4/§8.7). The runtime
+// currently sends the full ToolCompletionRequest (messages) to preCall and onError
+// as well as moderate/postCallSuccess, and no content projection redacts it yet, so
+// EVERY message-carrying point is content-bearing for this gate (interim fix A,
+// §12.4). The target model (B) keys this on the per-hook `spec.contentAccess`
+// declaration once the projection enforces it — until then, treat them all as
+// content-bearing so a preCall/onError egress hook can't dodge the high-trust bar.
+const CONTENT_BEARING_POINTS = new Set(['preCall', 'moderate', 'postCallSuccess', 'onError'])
+
+/**
+ * §8.4/§8.7 — does this hook receive message/response CONTENT at any of its
+ * lifecycle points? Interim fix A: every message-carrying point counts (see
+ * CONTENT_BEARING_POINTS). Target model B keys this on `spec.contentAccess`.
+ */
+export function isContentBearingHook(lifecyclePoints: string[] | undefined): boolean {
+ return Array.isArray(lifecyclePoints) && lifecyclePoints.some(p => CONTENT_BEARING_POINTS.has(p))
+}
+
+/**
+ * §8.4 content/egress separation gate: a content-bearing hook that can ALSO reach
+ * the network (declared `egressBindings` or a `remote` target) is an exfiltration
+ * path and is admissible only at `trust_level: high`. Returns true when the hook
+ * must be refused. Content-alone or egress-alone is fine below high.
+ */
+export function contentEgressRequiresHighTrust(args: {
+ lifecyclePoints: string[] | undefined
+ hasEgress: boolean
+ isRemote: boolean
+ trustLevel: string
+}): boolean {
+ return (
+ isContentBearingHook(args.lifecyclePoints) &&
+ (args.hasEgress || args.isRemote) &&
+ args.trustLevel !== 'high'
+ )
+}
/** Registry `hook_meta` shape (mirrors the registry HookMeta / LlmHook.spec, §8.5). */
type HookMetaShape = {
@@ -1743,15 +1776,21 @@ export function createAdminRegistryRouter(gateway?: K8sGateway): Router {
// Step 5 — content/egress separation gate (§8.4 / registry gap #2). A
// content-bearing hook that can also reach the network is an exfiltration
// path, admissible only for a vetted high-trust hook.
- const isContentBearing = hookMeta.lifecyclePoints.some(p => CONTENT_BEARING_POINTS.has(p))
const hasEgress =
Array.isArray(hookMeta.requiredEgress) && hookMeta.requiredEgress.length > 0
const isRemote = !!hookMeta.target.remote
- if (isContentBearing && (hasEgress || isRemote) && trustLevel !== 'high') {
+ if (
+ contentEgressRequiresHighTrust({
+ lifecyclePoints: hookMeta.lifecyclePoints,
+ hasEgress,
+ isRemote,
+ trustLevel,
+ })
+ ) {
res.status(403).json({
error: 'content_egress_requires_high_trust',
reason:
- 'a content-bearing hook (moderate/postCallSuccess) with egress or a remote target requires trust_level high (§8.4)',
+ 'a content-bearing hook (preCall/moderate/postCallSuccess/onError) with egress or a remote target requires trust_level high (§8.4)',
})
return
}