Skip to main content
sec0SecurityMiddleware(...) is the main Sec0 integration point for a tool server. This page keeps the configuration a developer normally sets in an application and leaves adapter internals out of the main reference path.

Minimal shape

import { sec0SecurityMiddleware } from "sec0-sdk/middleware";
import { LocalDevSigner } from "sec0-sdk/signer";

sec0SecurityMiddleware({
  policy: {
    source: "control-plane",
    scope: "auto",
  },
  signer: LocalDevSigner.fromKeyRef("file://./.sec0/keys/ed25519.key"),
  otel: {
    endpoint: process.env.OTLP_ENDPOINT!,
    serviceName: "orders-server",
    serviceVersion: "1.0.0",
    environment: "dev",
    tenant: "my-app",
  },
  sec0: {
    dir: ".sec0",
    retentionDays: 30,
  },
  controlPlaneUrl: process.env.SEC0_URL,
  auth: { apiKey: process.env.SEC0_API_KEY },
});
Preset wrappers are also available:
  • sec0LocalMiddleware(...) for local defaults
  • sec0HostedMiddleware(...) for control-plane defaults

MiddlewareOptions

KeyTypeRequiredDescription
policyPolicyObject, string, or ControlPlanePolicySourceYesPolicy object, YAML string, or remote policy source
signerSignerYesSigner used for audit envelopes
otelOTelConfigYesTrace export settings
sec0Sec0ConfigYesLocal audit storage settings
controlPlaneUrlstringNoPolicy server base URL
apiKeystringNoConvenience API key for audit upload discovery
authobjectNoAPI key or bearer token for policy fetch
runtimeobjectNoRuntime evaluation mode and remote evaluator settings
telemetryobjectNoTurn middleware tracing on or off
ap2objectNoAP2 mandate handling
sastobjectNoStatic analysis controls
dastobjectNoDynamic analysis controls
agentGuardobjectNoPrompt/output/run guard settings
The full internal adapter, raw-payload, and envelope extension hooks are intentionally left out of this page. Most app integrations do not need them.

policy

Accepted forms:
  • PolicyObject: parsed policy object
  • string: YAML policy loaded at runtime
  • ControlPlanePolicySource: fetch policy from the control plane

ControlPlanePolicySource

KeyTypeRequiredDescription
source"control-plane"YesRemote policy source selector
level"gateway" or "middleware"NoPolicy tier to fetch. Default is "middleware"
scope"base", "agent", or "auto"NoScope resolution mode
nodeIdstringNoDefault nodeId when runtime state is missing it
fallbackToBasebooleanNoFall back to workspace policy when agent policy is empty
refreshTtlMsnumberNoPolicy cache TTL in milliseconds. 0 fetches every call
See Agent Scoped Policies for how scope, nodeId, and fallbackToBase affect runtime policy lookup.

signer

If you provide a custom signer, it must match this shape:
MemberTypeDescription
keyIdstringKey identifier written into audit metadata
sign`(data: Uint8Array) => Promise<Uint8Array>Uint8Array`Signs the canonicalized payload bytes
For local development, use LocalDevSigner.fromKeyRef(...) from Signer & Tracing Reference.

otel

KeyTypeRequiredDescription
otel.endpointstringYesOTLP collector endpoint
otel.serviceNamestringYesService name
otel.serviceVersionstringNoService version
otel.environmentstringNoDeployment environment
otel.tenantstringNoTenant or workspace identifier

sec0

KeyTypeRequiredDescription
sec0.dirstringYesLocal audit directory
sec0.retentionDaysnumberNoLocal retention in days
sec0.presignobjectNoHosted audit upload settings

sec0.presign

KeyTypeRequiredDescription
sec0.presign.apiBaseUrlstringNoUpload API base URL
sec0.presign.auditKeystringYesAudit API key or bearer token
sec0.presign.tenantstringNoTenant hint
sec0.presign.clientNamestringNoClient name hint
sec0.presign.clientVersionstringNoClient version hint
sec0.presign.environmentstringNoEnvironment hint
sec0.presign.timeoutMsnumberNoUpload timeout override

apiKey and auth

apiKey is a convenience option. When it is set and sec0.presign is omitted, Sec0 can auto-discover hosted audit upload settings. Use auth when policy fetch should use explicit credentials:
KeyTypeRequiredDescription
auth.apiKeystringNoAPI key for policy fetch
auth.bearerTokenstringNoBearer token for policy fetch

runtime

The main runtime setting most developers care about is remote evaluation:

runtime.enforcement

KeyTypeRequiredDescription
runtime.enforcement.mode"local" or "remote"NoRuntime adapter mode. Default is local
runtime.enforcement.protocolVersionstringNoRuntime protocol version override
runtime.enforcement.failureMode"local", "allow", or "deny"NoFallback behavior when remote runtime fails
runtime.enforcement.remote.endpointstringNoRemote runtime evaluate endpoint
runtime.enforcement.remote.timeoutMsnumberNoRemote call timeout
runtime.enforcement.remote.maxRetriesnumberNoRetry count
runtime.enforcement.remote.retryBackoffMsnumberNoRetry backoff base
runtime.enforcement.remote.headersobjectNoExtra request headers
runtime.enforcement.remote.apiKeystringNoAPI key sent to the remote runtime

telemetry

KeyTypeRequiredDescription
telemetry.enabledbooleanNoDisable to turn off middleware traces

ap2

KeyTypeRequiredDescription
ap2.enabledbooleanNoEnable AP2 mandate checks
ap2.requireForSideEffectsbooleanNoRequire AP2 for side-effecting tools
ap2.headers.intentstringNoHeader name for intent mandate
ap2.headers.cartstringNoHeader name for cart mandate
ap2.headers.bundlestringNoHeader name for bundle
ap2.trust.didMethodsstring[]NoAllowed DID methods
ap2.trust.issuersAllowliststring[]NoAllowed issuers
ap2.trust.clockSkewSecnumberNoClock skew in seconds
ap2.tools.allowstring[]NoTool allowlist for AP2 checks

sast

KeyTypeRequiredDescription
sast.enabledbooleanNoEnable SAST
sast.block_on_changebooleanNoBlock while a new scan result is pending
sast.block_on_severitylow, medium, high, or criticalNoDeny threshold
sast.cache_ttl_msnumberNoResult cache TTL
sast.scan_all_on_server_changebooleanNoRescan all tools when server code changes

dast

KeyTypeRequiredDescription
dast.enabledbooleanNoEnable DAST
dast.block_on_changebooleanNoBlock while a new scan result is pending
dast.block_on_severitylow, medium, high, or criticalNoDeny threshold
dast.block_on_countnumberNoDeny when findings reach this count
dast.sandbox_urlstringNoDAST sandbox URL
dast.templatesstringNoTemplate path
dast.tagsstring[]NoIncluded scanner tags
dast.exclude_tagsstring[]NoExcluded scanner tags
dast.severitystring[]NoSeverity filter
dast.mode"sync" or "async"NoWhether middleware waits for the scan
dast.scope"server" or "tool"NoScan scope

agentGuard

KeyTypeRequiredDescription
agentGuard.enabledbooleanNoEnable Agent Guard
agentGuard.block_on_severityunknown, low, medium, high, or criticalNoDeny threshold
agentGuard.block_on_countnumberNoDeny when findings reach this count
agentGuard.pii_patternsstring[]NoOverride PII patterns
agentGuard.secret_patternsstring[]NoOverride secret patterns
agentGuard.prompt_injection_patternsstring[]NoOverride prompt injection patterns
agentGuard.dangerous_commandsstring[]NoOverride dangerous command patterns
agentGuard.toxicity_patternsstring[]NoOverride toxicity patterns
agentGuard.malicious_code_patternsstring[]NoOverride malicious code patterns
agentGuard.policy_violation_patternsstring[]NoOverride policy violation patterns
agentGuard.data_exfiltration_patternsstring[]NoOverride exfiltration patterns
agentGuard.run_contextobjectNoRun-context capture limits
agentGuard.adaptersarrayNoExternal scanner adapter chain

agentGuard.adapters[]

KeyTypeRequiredDescription
type"nemo", "guardrails", "llmguard", or "custom"YesAdapter type
serviceUrlstringConditionalRequired for hosted adapter types

agentGuard.run_context

KeyTypeRequiredDescription
enabledbooleanNoEnable run-context scanning
max_charsnumberNoMax total chars collected
max_eventsnumberNoMax events collected
max_event_charsnumberNoMax chars per event
max_runsnumberNoMax cached runs
ttl_msnumberNoCache TTL
include_objectivebooleanNoInclude objective in run context
include_metadatabooleanNoInclude metadata in run context