Skip to content

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

TypeScript

fix(guardrails): fail-closed on digest mismatch via quarantine (N11/§8.2)

Andy Pavia034d78156884
diff --git a/mcp-host/package-lock.json b/mcp-host/package-lock.json
index 49fc1af44..5cda18368 100644
--- a/mcp-host/package-lock.json
+++ b/mcp-host/package-lock.json
@@ -1,12 +1,12 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.252",
+ "version": "0.1.253",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "clerum-mcp-host",
- "version": "0.1.252",
+ "version": "0.1.253",
"license": "SEE LICENSE IN LICENSE",
"dependencies": {
"@anthropic-ai/sdk": "^0.32.0",
diff --git a/mcp-host/package.json b/mcp-host/package.json
index 94b0ac1a5..a3a56f48a 100644
--- a/mcp-host/package.json
+++ b/mcp-host/package.json
@@ -1,6 +1,6 @@
{
"name": "clerum-mcp-host",
- "version": "0.1.252",
+ "version": "0.1.253",
"description": "MCP Host - reads Host CRD and provides LLM access via OpenAI/Claude",
"main": "dist/main.js",
"engines": {
diff --git a/mcp-host/src/__tests__/guardrailHookResolver.test.ts b/mcp-host/src/__tests__/guardrailHookResolver.test.ts
index 0d067914a..a7cb068e7 100644
--- a/mcp-host/src/__tests__/guardrailHookResolver.test.ts
+++ b/mcp-host/src/__tests__/guardrailHookResolver.test.ts
@@ -117,12 +117,13 @@ describe('resolveGuardrailHookDescriptors', () => {
expect(out).toEqual([])
})
- it('skips an image hook whose reconciled digest no longer matches the ref (fail-closed)', async () => {
+ it('quarantines (not drops) an image hook whose reconciled digest no longer matches the ref', async () => {
const cr: LlmHookCR = {
metadata: { name: 'img' },
spec: {
target: { image: { ref: 'repo/img@sha256:new', port: 8080 } },
lifecyclePoints: ['preCall'],
+ capabilities: ['may_deny'],
},
status: { observedDigest: 'sha256:new' },
}
@@ -130,7 +131,10 @@ describe('resolveGuardrailHookDescriptors', () => {
guardrails({ preCall: [{ id: 'img', digest: 'sha256:OLD' }] }),
deps({ img: cr })
)
- expect(out).toEqual([])
+ // Still loaded, but quarantined → every /v1 call fails-closed (§8.2/N11).
+ expect(out).toHaveLength(1)
+ expect(out[0].quarantined).toBe(true)
+ expect(out[0].capabilities).toEqual(['may_deny'])
})
it('drops unknown capabilities and hooks with no known lifecycle points', async () => {
diff --git a/mcp-host/src/core/guardrails/hooks/__tests__/remoteLlmHook.test.ts b/mcp-host/src/core/guardrails/hooks/__tests__/remoteLlmHook.test.ts
index 5d477724f..37d1f2039 100644
--- a/mcp-host/src/core/guardrails/hooks/__tests__/remoteLlmHook.test.ts
+++ b/mcp-host/src/core/guardrails/hooks/__tests__/remoteLlmHook.test.ts
@@ -260,3 +260,31 @@ describe('lifecycle scoping', () => {
expect(await h.preCall(req())).toBeNull()
})
})
+
+describe('quarantine (§8.2 digest mismatch → fail-closed, N11)', () => {
+ const throwFetcher: HookFetcher = async () => {
+ throw new Error('network must not be dialed for a quarantined hook')
+ }
+
+ it('may_deny + fail-closed → deny without dialing the network', async () => {
+ const h = new RemoteLlmHook(
+ desc({ quarantined: true, capabilities: ['may_deny'], failMode: 'closed' }),
+ throwFetcher
+ )
+ expect((await h.preCall(req()))?.decision).toBe('deny')
+ expect((await h.moderate(req()))?.decision).toBe('deny')
+ })
+
+ it('advisory hook (no may_deny) → no contribution (skip)', async () => {
+ const h = new RemoteLlmHook(
+ desc({
+ quarantined: true,
+ capabilities: ['may_substitute_result'],
+ failMode: 'closed',
+ lifecyclePoints: ['pre_call'],
+ }),
+ throwFetcher
+ )
+ expect(await h.preCall(req())).toBeNull()
+ })
+})
diff --git a/mcp-host/src/core/guardrails/hooks/remoteLlmHook.ts b/mcp-host/src/core/guardrails/hooks/remoteLlmHook.ts
index f5a69da3b..453c55098 100644
--- a/mcp-host/src/core/guardrails/hooks/remoteLlmHook.ts
+++ b/mcp-host/src/core/guardrails/hooks/remoteLlmHook.ts
@@ -26,7 +26,7 @@ import type {
ToolCompletionResponse,
} from '../../types'
import type { Capability, Contributor } from '../types'
-import type { HookDescriptor, HookFetcher, LifecyclePoint } from './types'
+import type { HookDescriptor, HookFetcher, HookHttpResult, LifecyclePoint } from './types'
type LlmContributor = Contributor<ToolCompletionRequest, ToolCompletionResponse>
@@ -76,6 +76,23 @@ export class RemoteLlmHook {
return this.descriptor.capabilities.includes(cap)
}
+ /**
+ * Transport with the quarantine gate (§8.2): a quarantined hook (e.g. digest
+ * mismatch) never reaches the network — every call reports `unavailable`, so
+ * each point's §8.6 fail-posture applies (deny for a `may_deny`/fail-closed
+ * hook, no contribution for an advisory one). Never a silent allow.
+ */
+ private fetchGuarded(args: {
+ point: LifecyclePoint
+ descriptor: HookDescriptor
+ body: unknown
+ }): Promise<HookHttpResult> {
+ if (this.descriptor.quarantined) {
+ return Promise.resolve({ status: 0, body: undefined, unavailable: true })
+ }
+ return this.fetch(args)
+ }
+
private handles(point: LifecyclePoint): boolean {
return this.descriptor.lifecyclePoints.includes(point)
}
@@ -107,7 +124,11 @@ export class RemoteLlmHook {
/** `pre_call` (spec §8.1): reject → deny (gated), continue+patch → rewrite (gated), else allow. */
async preCall(request: ToolCompletionRequest): Promise<LlmContributor | null> {
if (!this.handles('pre_call')) return null
- const res = await this.fetch({ point: 'pre_call', descriptor: this.descriptor, body: request })
+ const res = await this.fetchGuarded({
+ point: 'pre_call',
+ descriptor: this.descriptor,
+ body: request,
+ })
// §8.1: non-200 or unavailable → fail-mode (never a silent allow).
if (res.unavailable || res.status !== 200) return this.onUnavailable()
@@ -157,7 +178,11 @@ export class RemoteLlmHook {
/** `moderate` (spec §8.1): 2xx = pass (no contribution); 4xx = deny (gated). */
async moderate(request: ToolCompletionRequest): Promise<LlmContributor | null> {
if (!this.handles('moderate')) return null
- const res = await this.fetch({ point: 'moderate', descriptor: this.descriptor, body: request })
+ const res = await this.fetchGuarded({
+ point: 'moderate',
+ descriptor: this.descriptor,
+ body: request,
+ })
if (res.unavailable) return this.onUnavailable()
if (res.status >= 200 && res.status < 300) return null // pass
@@ -180,7 +205,7 @@ export class RemoteLlmHook {
response: ToolCompletionResponse
): Promise<LlmContributor | null> {
if (!this.handles('post_call')) return null
- const res = await this.fetch({
+ const res = await this.fetchGuarded({
point: 'post_call',
descriptor: this.descriptor,
body: {
@@ -234,7 +259,7 @@ export class RemoteLlmHook {
*/
async onError(request: ToolCompletionRequest, error: unknown): Promise<LlmContributor | null> {
if (!this.handles('on_error')) return null
- const res = await this.fetch({
+ const res = await this.fetchGuarded({
point: 'on_error',
descriptor: this.descriptor,
body: { request, error },
diff --git a/mcp-host/src/core/guardrails/hooks/types.ts b/mcp-host/src/core/guardrails/hooks/types.ts
index ed981aa4c..a05d78c39 100644
--- a/mcp-host/src/core/guardrails/hooks/types.ts
+++ b/mcp-host/src/core/guardrails/hooks/types.ts
@@ -39,6 +39,14 @@ export interface HookDescriptor {
* cluster-private IPs and are NOT external, so they bypass that guard.
*/
external?: boolean
+ /**
+ * True when the hook resolved but is NOT trusted to run — e.g. its reconciled
+ * image digest no longer matches the admin-pinned reference (§8.2). Every
+ * `/v1` call short-circuits to "unavailable" so the hook's fail-posture (§8.6)
+ * applies: a `may_deny` (fail-closed) hook DENIES; an advisory hook contributes
+ * nothing (skip). Never silently allows.
+ */
+ quarantined?: boolean
}
/** Result of one `/v1` HTTP call. `unavailable` = 5xx / timeout / connection error / malformed body (spec §8.1). */
diff --git a/mcp-host/src/guardrailHookResolver.ts b/mcp-host/src/guardrailHookResolver.ts
index cc76710a8..69f71daa3 100644
--- a/mcp-host/src/guardrailHookResolver.ts
+++ b/mcp-host/src/guardrailHookResolver.ts
@@ -149,23 +149,6 @@ export async function resolveGuardrailHookDescriptors(
continue
}
- // Digest binding (§8.2): an image hook whose reconciled digest no longer
- // matches the admin-pinned reference is not the reviewed image — skip it.
- // NOTE: skipping drops the hook from the lane, which is fail-OPEN for that
- // phase; turning a mismatch into an authoritative deny for fail-closed hooks
- // is a tracked follow-up (resolution fail-posture).
- if (
- ep.kind === 'image' &&
- refDigest &&
- cr.status?.observedDigest &&
- refDigest !== cr.status.observedDigest
- ) {
- console.warn(
- `[Guardrails] LlmHook ${id} digest mismatch (ref=${refDigest} observed=${cr.status.observedDigest}); skipping`
- )
- continue
- }
-
const capabilities = (cr.spec?.capabilities ?? []).filter((c): c is Capability =>
KNOWN_CAPABILITIES.includes(c)
)
@@ -178,6 +161,23 @@ export async function resolveGuardrailHookDescriptors(
// resolve to cluster-private IPs and must bypass that guard.
const external = ep.kind === 'remote'
+ // Digest binding (§8.2): an image hook whose reconciled digest no longer
+ // matches the admin-pinned reference is not the reviewed image. Rather than
+ // drop it (fail-OPEN), QUARANTINE it — the descriptor still loads but every
+ // /v1 call short-circuits to unavailable, so a `may_deny` (fail-closed) hook
+ // DENIES and an advisory hook contributes nothing (§8.6/N11). Never a silent
+ // allow for a deny-authoritative hook whose integrity check failed.
+ const quarantined =
+ ep.kind === 'image' &&
+ !!refDigest &&
+ !!cr.status?.observedDigest &&
+ refDigest !== cr.status.observedDigest
+ if (quarantined) {
+ console.warn(
+ `[Guardrails] LlmHook ${id} digest mismatch (ref=${refDigest} observed=${cr.status?.observedDigest}); quarantining (fail-closed for may_deny)`
+ )
+ }
+
out.push({
id,
endpoint: ep.endpoint,
@@ -187,9 +187,10 @@ export async function resolveGuardrailHookDescriptors(
failMode,
order,
external,
+ ...(quarantined ? { quarantined: true } : {}),
})
console.log(
- `[Guardrails] resolved hook ${id} -> ${ep.endpoint}${path} points=[${points.join(',')}] caps=[${capabilities.join(',')}] failMode=${failMode}${external ? ' external=true(SSRF-guarded)' : ''}`
+ `[Guardrails] resolved hook ${id} -> ${ep.endpoint}${path} points=[${points.join(',')}] caps=[${capabilities.join(',')}] failMode=${failMode}${external ? ' external=true(SSRF-guarded)' : ''}${quarantined ? ' quarantined=true(digest-mismatch)' : ''}`
)
}