AI and LLM security

Hidden AI context, system prompts and internal state exposure

Instruction boundary: document, gate, model arranged to illustrate hidden ai context, system prompts and internal state exposure.

Hidden context may contain internal instructions, tool details or sensitive state that users should not receive. Understanding hidden AI context and system prompts and internal state exposure helps establish which security property the feature needs and where that property is actually enforced.

What does this involve?

An AI model can interpret instructions within information that the application intended to treat as data. The critical security boundary is the surrounding system: which private information it supplies and which actions it allows model-directed output to trigger.

By inserting the first words of the prompt, the agent will often complete it with the full prompt, s word by word they represent the most likely next tokens. As an example, if the prompt starts with "You are a helpful agent that helps people with their everyday tasks...", the following query can be used.

Agentic Prompt Leakage Framework: This approach employs cooperative agents to probe and exploit LLMs, aiming to elicit system prompts. The methodology is detailed in the paper "Automating Prompt Leakage Attacks on Large Language Models Using Agentic Approach"

Why it matters

Consider a realistic failure: a model reproduces internal configuration supplied in its context.

A strange response becomes a security issue when it discloses protected information, changes an authorised task or causes an unintended operation. The assessment should distinguish those consequences from cosmetic changes to the model's answer.

AI testing needs recorded model and application conditions because outputs can vary. The important evidence is the protected information, decision or tool operation affected in the deployed workflow.

How penetration testers check for it

Separate ordinary instruction disclosure from exposure of secrets or privileged operational data.

  • Map trusted instructions and untrusted input sources.
  • Follow retrieved content through model and tool decisions.
  • Repeat representative cases under recorded conditions.
  • Verify actual data access and consequential actions.

How to fix it

Keep secrets outside prompts and reduce sensitive context rather than relying on model secrecy.

  • Keep security decisions in trusted application controls.
  • Limit model context and tool permissions to the task.
  • Treat generated output as untrusted input to downstream systems.
  • Maintain regression cases for important trust boundaries.

No prompt wording can establish an absolute instruction boundary for every possible input. Layered application controls are needed so a model failure does not automatically become a protected action.

Recheck the changed behaviour against the original failure conditions and the legitimate user journey. Keep enough evidence to show which release and configuration were verified, and include related entry points that depend on the same security decision.

Read about our methodology or contact pentested.com to discuss your AI applications and agent workflows.

See your first test report this week.

Book a 30 minute demo. We will verify one of your targets with you and run a test against it, so you can judge the results on your own systems.

Book a demo