Deep Layer Security Advisory
AI Security — Deep-Dive Guide

Securing LLMs, Agents, and RAG Pipelines: The Practical Guide to AI Application Security

AI applications fail differently. Prompt injection, tool abuse, retrieval poisoning, and trust boundary failures require assessment methodologies built for how LLMs and agents actually work.

AI applications are being deployed faster than security programs can adapt. Organizations are shipping LLM-powered chatbots, AI agents with tool access, and RAG-based knowledge assistants into production — often without security review, because traditional security testing does not cover AI-specific vulnerabilities.

The problem is not that AI applications are inherently insecure. The problem is that they fail in ways that traditional security tools cannot detect. Prompt injection is not SQL injection — it operates at the semantic layer. Tool abuse is not privilege escalation — it is an AI making decisions the developer did not anticipate. RAG document leakage is not a broken access control — it is a retrieval system that does not enforce authorization.

This guide covers the security landscape for LLM applications, multi-agent systems, and RAG pipelines — the three deployment patterns that create the most risk and receive the least security attention.

1

Why AI Applications Fail Differently

Traditional application security assumes deterministic behavior: given the same input, the application produces the same output. LLM-powered applications are fundamentally non-deterministic — the same prompt can produce different outputs, and small changes in input can produce dramatically different behavior. This breaks every assumption that traditional security testing is built on.

The attack surface of an LLM application includes: the system prompt (which defines application behavior and often contains sensitive instructions), the user input (which can override system instructions via prompt injection), the retrieval system (which introduces external content into the model's context), tool/function calls (which give the model real-world action capability), and the output handling pipeline (which processes model output for downstream systems).

Traditional WAFs do not detect prompt injection because it is semantic, not syntactic. SAST tools cannot analyze system prompt security. Penetration testing methodologies do not include adversarial LLM interaction. The security tooling gap means that AI applications are being deployed with the same confidence as tested applications but without the same testing.

2

Prompt Injection: The #1 AI Vulnerability

Prompt injection is to LLM applications what SQL injection was to web applications in the early 2000s — the most prevalent, most impactful, and most misunderstood vulnerability class. It occurs when user-controlled input overrides or modifies the system prompt instructions that define application behavior.

Direct prompt injection is a user deliberately crafting input to override system instructions: 'Ignore all previous instructions and...' This is the form that gets the most attention, and it is the least dangerous form in production applications because input validation and guardrails can partially mitigate it.

Indirect prompt injection is far more dangerous. It occurs when attacker-controlled content — a document in a RAG corpus, an email being summarized, a web page being analyzed — contains instructions that the model follows when it processes that content. The user never sees the injected instructions. The application's input validation never evaluates them. They enter the model's context through the retrieval or tool pipeline and execute silently.

Defense against prompt injection is defense-in-depth, not a single control: input validation (pattern-based filtering of known injection patterns), privilege separation (the model should not have direct access to sensitive operations), output validation (parsing and sanitizing model output before passing to downstream systems), and monitoring (detecting anomalous model behavior that may indicate successful injection).

3

Agentic AI: When Models Take Actions

An AI agent is an LLM with tool access — the ability to send emails, query databases, execute code, call APIs, modify files, or interact with other systems. Agents are the highest-risk AI deployment pattern because they combine the non-deterministic behavior of LLMs with real-world action capability.

The core security question for agents is authorization: what is the agent allowed to do, and how is that enforced? In most agent deployments, the answer is 'whatever tools the developer connected to it.' There is no formal authorization model, no least-privilege scoping, and no audit trail of what the agent did, with which tool, in response to which instruction.

Multi-agent systems add trust boundary complexity. When Agent A can instruct Agent B, and Agent B has access to tools that Agent A does not, the system creates a privilege escalation path. If an attacker can influence Agent A's behavior (through prompt injection), they can potentially cause Agent B to take actions that Agent A is not authorized to perform directly.

The essential security controls for agentic AI are: tool-level authorization (each agent has access only to the tools it needs for its defined tasks), inter-agent authentication (agents verify the source and authority of instructions from other agents), human-in-the-loop gates (high-impact actions require human approval before execution), and comprehensive audit logging (every tool call, every parameter, every instruction, attributed to the originating user and agent).

4

RAG Pipeline Security: The Retrieval Problem

Retrieval-Augmented Generation (RAG) pipelines connect LLMs to organizational knowledge — documents, wikis, databases, emails. The security problem: most RAG implementations retrieve documents based on semantic similarity, not authorization. If a user can query the assistant, they can potentially access any document in the corpus, regardless of whether they should have access to that document.

The RAG authorization gap is the most consistently found vulnerability in RAG security assessments. Vector stores (Pinecone, Weaviate, pgvector, Qdrant) do not natively enforce document-level authorization at retrieval time. The application must implement authorization — typically through metadata filtering — but most implementations either skip this entirely or implement it with bypassable filters.

Beyond authorization, RAG pipelines introduce a second risk: indirect prompt injection via the document corpus. If an attacker can get a document into the RAG corpus (through a shared drive, an email attachment, a wiki page), they can embed instructions in that document that the model will follow when it retrieves and processes the content. The user asking the question never sees the injected instructions.

Securing a RAG pipeline requires: document-level authorization enforced at retrieval time (not just at ingestion), ingestion pipeline validation (scanning documents for injection patterns before they enter the corpus), corpus integrity monitoring (detecting injected content in existing documents), and output grounding (ensuring model responses are actually based on retrieved content, not fabricated).

5

Governance Before Technical Controls

The most common AI security mistake is reaching for technical controls before establishing governance. Organizations deploy prompt injection filters and output validators before answering fundamental questions: What AI systems do we have? Who approved them? What data do they access? What decisions do they influence?

AI governance provides the foundation that technical controls build on. It includes: an AI inventory (knowing what AI is deployed, where, and by whom), an acceptable use policy (defining what AI can and cannot be used for), a risk framework (classifying AI use cases by risk level), an approval workflow (requiring security review before AI systems access sensitive data or take consequential actions), and regulatory mapping (understanding which regulations apply — EU AI Act, NIST AI RMF, ISO 42001).

The practical sequencing for most organizations is: governance first (policies, inventory, risk framework), then architecture review (threat modeling, reference architecture validation), then security testing (LLM assessment, RAG assessment, agent review), then ongoing monitoring (detection rules, anomaly alerts, periodic reassessment). Each layer builds on the previous one.

Key Takeaways

AI applications fail differently — prompt injection, tool abuse, and retrieval leakage are invisible to traditional security testing tools
Indirect prompt injection (via retrieved documents, not user input) is the most dangerous AI vulnerability because it bypasses all user-facing input validation
Agentic AI is the highest-risk deployment pattern — enforce tool-level authorization, inter-agent trust boundaries, and human-in-the-loop gates
Most RAG pipelines do not enforce document-level authorization at retrieval time — this is the most consistently found vulnerability in RAG assessments
Build governance (inventory, policies, risk framework) before technical controls — you cannot scope a security assessment if you do not know what AI you have

Related Articles

Awareness

Prompt Injection Explained

Awareness

Why AI Agents Are the Highest-Risk Deployment

Awareness

The RAG Authorization Gap

Evaluation

OWASP LLM Top 10: Practical Guide

Decision

What an LLM Security Assessment Covers

Want to discuss your ai security posture?

30-minute discovery call — focused on your environment and challenges. No sales pitch.