GebSecure Docs v0.1.0

Guides · Security

Prompt-injection defense

Scoring untrusted content, sanitizing and blocking it, and tainting agents that read injected instructions.

Agents read content they do not control — web pages, emails, documents, retrieved chunks, tool and MCP output. GebSecure scores that content for prompt injection before the model sees it, returns a safe form, and remembers when an agent has been exposed so that its next consequential actions need a human.

Inspecting content#

POST {gateway}/v1/inspect (permission authorize; the SDKs' inspect):

Request field Meaning
content string (up to 1 MB), object or array
source prompt, web, email, document, rag, mcp_response, tool_output
origin URL or identifier of where it came from (up to 2048 characters)
dlp also run inbound DLP (default true)
environmentId for agents in several environments

The response:

Field Meaning
action BLOCK if the injection check or DLP blocks; otherwise SANITIZE if the injection check sanitized; otherwise the DLP action (MASK, REDACT, REQUIRE_APPROVAL) if not ALLOW; otherwise the injection action (ALLOW or FLAG)
content what to hand to the model: sanitized or masked, or null when blocked
injection score (0–100), level (none, low, medium, high, critical), action, findings (rule, category, excerpt), provenance, model, detectionId, tainted
dlp inbound DLP outcome (action, summary, rules, eventId) or null
examples/typescript-agent/src/agent.ts
// 6. Retrieved content (RAG, web, tool output) is inspected too. Injected instructions are flagged,
//    sanitized or blocked; a flagged result also taints the agent, so its next write actions need approval.
const kb = await gs.inspect({ content: KB_ARTICLE, source: 'rag', origin: 'kb://refund-policy' }, child);
console.log(`knowledge-base inspection: ${kb.action} (injection ${kb.injection.level}, score ${kb.injection.score}, tainted: ${kb.injection.tainted ?? false})`);
outcomes.kbInspection = kb.action;

GebSecure also inspects automatically: connector execution output (tool_output), MCP tool results, resources and prompts (mcp_response) and browser pages.

Scoring#

Rules detect categories of injection — instruction_override, role_injection, exfiltration, tool_coercion, credential_solicitation, hidden_content, prompt_leak, authority_claim, encoded_payload (and model for the optional classifier). Weights add up with diminishing returns per category; hidden content (Unicode tag characters, HTML comments, CSS-hidden text, base64 and similar encodings) adds weight. The score is multiplied by the source's trust: prompt content is user-trusted (×0.7); every other source is untrusted (×1.0).

Levels: critical ≥ 80, high ≥ 60, medium ≥ 35, low > 0. Actions, with the default thresholds:

Score Action
< 25 ALLOW
≥ 25 (flagAt) FLAG
≥ 45 (sanitizeAt) SANITIZE — matched spans become [removed: possible prompt injection] and the text is wrapped in <untrusted_content source=… trust=… sha256=…>
≥ 75 (blockAt) BLOCK

Model-assisted classifier. With DETECTION_MODEL_PROVIDER=anthropic and DETECTION_MODEL_API_KEY set, content whose rule score is between 15 and 70 is also scored by a model (DETECTION_MODEL, timeout DETECTION_MODEL_TIMEOUT_MS); the result blends both. If the classifier fails, the rule score is used.

Taint#

When an agent reads content scoring at or above taintApprovalAt (45), it becomes tainted for taintTtlSeconds (1800 s). While tainted, any action that would be allowed but whose category is in taintActionCategories (write, delete, admin) becomes APPROVAL_REQUIRED (policy id injection-taint, reason "Agent recently ingested untrusted content with prompt-injection indicators…"). Read actions are not affected. Taint also adds the risk signal content.injection (up to 40 points).

Clear a taint with DELETE /v1/injection/taint/{principalId} (permission dlp:configure; audited as taint.clear).

Configuration#

PATCH /v1/injection/policy (permission dlp:configure) sets flagAt, sanitizeAt, blockAt, taintApprovalAt (0–100), taintActionCategories and taintTtlSeconds (60–86400) for the organization; GET /v1/injection/policy reads them. Detections are listed with GET /v1/injection/detections (principalId, minScore); each non-ALLOW inspection records a detection, the audit event injection.detect and the event injection.detected.

In framework integrations#

The framework integrations call /v1/inspect on tool output marked untrusted (inspectOutput with a source): a BLOCK (or a FLAG with blockOnFlag) withholds the output from the model, SANITIZE and DLP masking replace it, and a failed inspection fails closed.