Deterministic advisor prompt-injection gate (D-0048) #123

Merged
hannah-vernon merged 1 commit from feature/advisor-injection-gate into dev 2026-09-21 12:51:54 -05:00
Owner

What does this PR do?

Adds a deterministic prompt-injection gate for the local-model advisor (ADR D-0048), the prerequisite D-0042 required before any de-escalation because both candidate models are prompt-injectable.

A detector scans only the untrusted observed data the advisor would hand to the model (incident evidence descriptions and extracted event strings, the prompt variables marked UntrustedObservedData), never the trusted base fields. It matches two tiers of patterns:

  • A code-defined, immutable base list (LocalModelAdvisorBaseInjectionPatterns): six categories - InstructionOverride, RoleOrSystemImpersonation, OutputControlHijack, DelimiterOrFenceBreakout, EncodedPayload, ExfiltrationOrToolAbuse - seeded from a catalogue produced by a second model (Fable-5) and curated for precision against genuine security-incident text.
  • An add-only operator list (local_model_advisor_injection_patterns) edited on /configuration (step-up gated, audited). Operators can add and validate extra patterns but cannot edit, disable, or remove any base pattern, so the control cannot be weakened from the UI. Invalid stored rows are skipped without throwing.

A new InjectionAction setting selects the behaviour on a positive detection: RecordOnly runs the consult and records the detection, or SkipAdvisor (default) skips the model call entirely so the deterministic base classification stands. Either way the detection is recorded on the consult as InjectionDetected, AdvisorSkippedForInjection, and a matched-category JSON column, and surfaced on /advisor and /api/v1/advisor. An escalating flagged consult (only possible under RecordOnly) also carries an [advisor] injection reason within the existing two-slot reason cap. The detector runs before the response cache (D-0046) and ensemble (D-0047), and the escalate-only clamp (D-0042) remains enforced on every path.

How was this tested?

  • dotnet build - 0 errors, 0 warnings
  • dotnet test - 916 pass, 0 fail, 0 skip (+18 from 898)
  • Detector unit tests (each category matches malicious examples, does not fire on benign incident prose / hashes / legitimate base64), classifier RecordOnly vs SkipAdvisor behaviour, settings round-trip (default SkipAdvisor), and Postgres pattern-store round-trip incl. invalid-row skip

Checklist

  • I have read the Contributing Guide
  • Changes are focused - one logical change per PR
  • Documentation updated (DECISIONS.md D-0048, AGENT-README.md)
  • New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (none added)
  • No secrets, credentials, or real infrastructure identifiers in the diff
  • No commented-out code or debug leftovers
## What does this PR do? Adds a deterministic prompt-injection gate for the local-model advisor (ADR D-0048), the prerequisite D-0042 required before any de-escalation because both candidate models are prompt-injectable. A detector scans only the untrusted observed data the advisor would hand to the model (incident evidence descriptions and extracted event strings, the prompt variables marked `UntrustedObservedData`), never the trusted base fields. It matches two tiers of patterns: - A **code-defined, immutable base list** (`LocalModelAdvisorBaseInjectionPatterns`): six categories - InstructionOverride, RoleOrSystemImpersonation, OutputControlHijack, DelimiterOrFenceBreakout, EncodedPayload, ExfiltrationOrToolAbuse - seeded from a catalogue produced by a second model (Fable-5) and curated for precision against genuine security-incident text. - An **add-only operator list** (`local_model_advisor_injection_patterns`) edited on `/configuration` (step-up gated, audited). Operators can add and validate extra patterns but cannot edit, disable, or remove any base pattern, so the control cannot be weakened from the UI. Invalid stored rows are skipped without throwing. A new `InjectionAction` setting selects the behaviour on a positive detection: `RecordOnly` runs the consult and records the detection, or `SkipAdvisor` (default) skips the model call entirely so the deterministic base classification stands. Either way the detection is recorded on the consult as `InjectionDetected`, `AdvisorSkippedForInjection`, and a matched-category JSON column, and surfaced on `/advisor` and `/api/v1/advisor`. An escalating flagged consult (only possible under `RecordOnly`) also carries an `[advisor]` injection reason within the existing two-slot reason cap. The detector runs before the response cache (D-0046) and ensemble (D-0047), and the escalate-only clamp (D-0042) remains enforced on every path. ## How was this tested? - [x] `dotnet build` - 0 errors, 0 warnings - [x] `dotnet test` - 916 pass, 0 fail, 0 skip (+18 from 898) - [x] Detector unit tests (each category matches malicious examples, does not fire on benign incident prose / hashes / legitimate base64), classifier RecordOnly vs SkipAdvisor behaviour, settings round-trip (default SkipAdvisor), and Postgres pattern-store round-trip incl. invalid-row skip ## Checklist - [x] I have read the Contributing Guide - [x] Changes are focused - one logical change per PR - [x] Documentation updated (DECISIONS.md D-0048, AGENT-README.md) - [x] New dependencies are MIT/Apache-2.0/BSD, security-vetted, and recorded in THIRD-PARTY-NOTICES.md (none added) - [x] No secrets, credentials, or real infrastructure identifiers in the diff - [x] No commented-out code or debug leftovers
Scan untrusted observed data (evidence and event strings) for prompt-injection
patterns before the advisor consults the model.  Base pattern set is code-defined
and immutable (six categories, seeded from a Fable-5 catalogue, curated for
precision); operators may add extra patterns in local_model_advisor_injection_patterns
(add-only, validated) on /configuration but cannot weaken the base.

InjectionAction setting selects RecordOnly or SkipAdvisor (default): a skip makes
no model call and no cache read and leaves the deterministic base unchanged.  Each
consult records InjectionDetected, AdvisorSkippedForInjection, and matched categories,
surfaced on /advisor and /api/v1/advisor; an escalating flagged consult carries an
[advisor] injection reason.  Escalate-only clamp remains enforced on every path.

Prerequisite for de-escalation (D-0042).  916 tests pass (+18).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
hannah-vernon/viegard-sentinel!123
No description provided.