agentsec-core 0.2.0

AgentSec core library — scan / web / paste logic, pure Rust
Documentation
//! Built-in injection-pattern list for paste-content detection.
//!
//! Six pattern groups:
//!
//! 1. **Role hijack / instruction override** (`p001`–`p008`) — *conservative*.
//!    These phrases appear in benign discussion of LLM behavior, so the
//!    bias is to only match the explicit override form.
//! 2. **Instruction separators / role tokens** (`p009`–`p015`) — the
//!    `[INST]` / `<|system|>` family.
//! 3. **System-prompt labels** (`p016`–`p020`).
//! 4. **Prompt reveal / persona shift** (`p021`–`p025`).
//! 5. **Credential exfiltration intent** (`p026`–`p051`) — *aggressive*.
//!    Phrases like "show me your api key" have near-zero false-positive
//!    rate in normal conversation.
//! 6. **Sensitive file enumeration** (`p052`–`p070`) — *aggressive*.
//! 7. **Network exfiltration channels** (`p071`–`p076`) — *aggressive*.
//! 8. **Jailbreak triggers** (`p077`–`p088`) — *aggressive*.

/// Pairs of `(pattern_id, needle)` consumed by
/// [`crate::paste::detector::scan`]. Order matters for id stability:
/// matched ids are stable across versions to support downstream tooling.
pub const PATTERNS: &[(&str, &str)] = &[
    // ── Role hijack / instruction override (conservative) ───────────────────
    ("p001", "ignore all previous instructions"),
    ("p002", "ignore previous instructions"),
    ("p003", "disregard prior instructions"),
    ("p004", "ignore the above"),
    ("p005", "you are now"),
    ("p006", "act as if you are"),
    ("p007", "system prompt:"),
    ("p008", "developer message:"),
    // ── Instruction separators / role tokens ────────────────────────────────
    ("p009", "[INST]"),
    ("p010", "[/INST]"),
    ("p011", "<|system|>"),
    ("p012", "<|assistant|>"),
    ("p013", "<|user|>"),
    ("p014", "<|im_start|>"),
    ("p015", "<|im_end|>"),
    // ── System prompt labels ────────────────────────────────────────────────
    ("p016", "BEGIN SYSTEM PROMPT"),
    ("p017", "END SYSTEM PROMPT"),
    ("p018", "###system"),
    ("p019", "###user"),
    ("p020", "###assistant"),
    // ── Prompt reveal / persona shift ───────────────────────────────────────
    ("p021", "reveal your prompt"),
    ("p022", "print your instructions"),
    ("p023", "show me your system message"),
    ("p024", "from now on"),
    ("p025", "new persona"),
    // ── Credential exfiltration intent (aggressive) ─────────────────────────
    ("p026", "get credential"),
    ("p027", "show credential"),
    ("p028", "leak credential"),
    ("p029", "dump credential"),
    ("p030", "exfiltrate credential"),
    ("p031", "export credential"),
    ("p032", "show me your api key"),
    ("p033", "reveal api key"),
    ("p034", "dump api key"),
    ("p035", "show your token"),
    ("p036", "reveal your token"),
    ("p037", "dump tokens"),
    ("p038", "leak tokens"),
    ("p039", "show your secret"),
    ("p040", "reveal secret"),
    ("p041", "dump secret"),
    ("p042", "leak secret"),
    ("p043", "show password"),
    ("p044", "reveal password"),
    ("p045", "dump password"),
    ("p046", "print env"),
    ("p047", "dump env"),
    ("p048", "echo $"),
    ("p049", "printenv"),
    ("p050", "show authorization header"),
    ("p051", "bearer token"),
    // ── Sensitive file enumeration ──────────────────────────────────────────
    ("p052", ".env file"),
    ("p053", "cat .env"),
    ("p054", "read .env"),
    ("p055", "contents of .env"),
    ("p056", "~/.ssh"),
    ("p057", "id_rsa"),
    ("p058", "id_ed25519"),
    ("p059", "private key"),
    ("p060", ".aws/credentials"),
    ("p061", "aws_secret_access_key"),
    ("p062", "kubeconfig"),
    ("p063", "/etc/passwd"),
    ("p064", "/etc/shadow"),
    ("p065", "access_token"),
    ("p066", "refresh_token"),
    ("p067", "session cookie"),
    ("p068", "dump cookies"),
    ("p069", "localstorage"),
    ("p070", "sessionstorage"),
    // ── Network exfiltration channels ───────────────────────────────────────
    ("p071", "send to webhook"),
    ("p072", "post to webhook"),
    ("p073", "exfiltrate to"),
    ("p074", "base64 encode and send"),
    ("p075", "dns exfil"),
    ("p076", "dns tunnel"),
    // ── Jailbreak triggers ──────────────────────────────────────────────────
    ("p077", "do anything now"),
    ("p078", "DAN mode"),
    ("p079", "jailbreak mode"),
    ("p080", "developer mode enabled"),
    ("p081", "pretend you are unrestricted"),
    ("p082", "without any restrictions"),
    ("p083", "without filters"),
    ("p084", "bypass safety"),
    ("p085", "ignore guidelines"),
    ("p086", "ignore policy"),
    ("p087", "disregard policy"),
    ("p088", "ignore safety"),
];

/// Pattern ids in the same order as [`PATTERNS`]. Used by the detector to
/// look up the id for a matched needle by its Aho-Corasick `pattern_id`.
pub fn ids() -> Vec<&'static str> {
    PATTERNS.iter().map(|(id, _)| *id).collect()
}

/// Needles in the same order as [`PATTERNS`]. Fed verbatim into the
/// Aho-Corasick builder in [`crate::paste::detector`].
pub fn needles() -> Vec<&'static str> {
    PATTERNS.iter().map(|(_, n)| *n).collect()
}