Introducing a new way to review your PRs.

Read the announcement

affaan-m / agentshield

AI agent security scanner. Detect vulnerabilities in agent configurations, MCP servers, and tool permissions. Available as CLI, GitHub Action, ECC plugin, and GitHub App integration. 🛡️

View on GitHub

20 documents · Updated Sep 11, 2026

docs / adversarial-security-validation

Adversarial security validation

AgentShield uses active checks to test whether an agent configuration can resist hostile instructions, unsafe data flow, and risky hook behavior. These checks complement static rule review by asking how a configuration may fail and by observing what its commands do in a controlled run.

Validation scope

Adversarial validation covers three related risks. Prompt tests examine resistance to hostile messages. Taint analysis follows untrusted values toward dangerous actions. Sandbox analysis observes hook behavior before it can be trusted in a normal agent workflow.

Validation areaMain questionPrimary signal
Prompt resistanceCan hostile or disguised instructions override the agent's stated defenses?Blocked and bypassed payloads
Data-flow safetyCan untrusted data reach code execution, network, or file actions?Source-to-sink flows
Isolated behaviorWhat does a configured hook try to read, write, send, or keep running?Behavioral findings and risk verdicts

Validation workflow

The validation flow starts with discovered agent configuration and runs each active check that the scan enables. The results remain separate because a configuration can resist prompt attacks while still exposing a secret through a hook.

This diagram shows how configuration becomes three kinds of evidence and then becomes reportable scan output.

flowchart LR
    A[Discovered configuration] --> B[Taint analysis]
    A --> C[Injection test suite]
    A --> D[Hook execution]
    B --> E[Source-to-sink findings]
    C --> F[Blocked and bypassed payloads]
    D --> G[Behavioral risk findings]
    E --> H[Security report]
    F --> H
    G --> H

Prompt resistance

Prompt resistance testing compares the discovered configuration with a corpus of hostile payloads. The suite supplies the main instructions with any agent definitions and settings to an evaluator, which assesses payloads in controlled batches and returns one structured result per payload. See Injection and taint testing for the detailed payload and data-flow view.

The result records whether the payload appears to bypass the configuration, the evaluator's confidence, supporting evidence, the likely attack path, and a mitigation. A weighted resistance score gives more weight to higher-severity payloads, so one serious bypass matters more than several low-risk cases. The score is a guide to posture, not proof that the agent is safe. If the evaluator fails or omits a response, the result is marked with zero confidence and “Unable to evaluate” evidence rather than treated as a tested bypass.

References: src/…/index.ts• L33-83 src/…/tester.ts• L13-41 src/…/tester.ts• L148-215 src/…/tester.ts• L230-281 src/…/tester.ts• L295-360 src/…/tester.ts• L401-425

Data-flow safety

Taint analysis treats values such as environment variables, file content, user input, network data, and command-line arguments as untrusted sources. It looks for their movement toward sinks such as shell execution, evaluation, process creation, network sends, and file writes. This exposes paths where an instruction or secret can become an action rather than remaining data.

The analysis is a string-level check over discovered files. It reports direct same-line flows, nearby flows in the same file, and selected cross-file environment-variable use. It ranks input-to-execution and data-to-network paths above less direct paths, then returns source nodes, sink nodes, and sorted flows for review. See Injection and taint testing for the child page on this check.

References: src/…/analyzer.ts• L1-9 src/…/analyzer.ts• L11-91 src/…/analyzer.ts• L93-140 src/…/analyzer.ts• L181-193 src/…/analyzer.ts• L234-337

Isolated behavior

Sandbox analysis runs commands from configured hooks in a temporary work directory with a reduced environment, fake sensitive values, and a time limit. It supports the standard hook shape and a legacy flat shape, then runs each recognized command so the analysis can expose attempts to leak secrets or reach external resources without giving the hook the real credentials that an agent workflow may hold. See Sandbox execution for the execution and observation model.

The run records command output and observations for canary leaks, network and DNS activity, sensitive path access, file changes, persistent process attempts, suspicious output, and slow or timed-out behavior. These observations are pattern-based signals rather than a complete operating-system trace. The behavioral analyzer turns them into findings, a capped risk score, and a safe, suspicious, or malicious verdict. A critical observation is enough to produce a malicious verdict.

References: src/…/executor.ts• L8-38 src/…/executor.ts• L94-166 src/…/executor.ts• L174-312 src/…/executor.ts• L318-341 src/…/executor.ts• L346-500 src/…/executor.ts• L502-634 src/…/index.ts• L1-19

Result boundaries

The command-line scan enables taint, injection, and sandbox phases as separate options. Each phase can return no result when its module is unavailable or when the required configuration is absent, so a missing section must not be read as a clean security result.

The shared deep-scan result keeps static findings, taint flows, injection outcomes, and sandbox findings in distinct fields. The terminal report presents blocked payloads, bypassed payload details, source-to-sink flows, hook behavior, and sandbox risk findings so an engineer can connect a finding to the validation method that produced it.

Evidence interpretation

Each validation method answers a different question. An injection result is an assessment of the configuration's defenses against a payload. A taint flow is a static indication of a risky path. A sandbox finding is evidence observed during one hook run. Confidence, evidence, and the method's limits must stay with the result when teams use it for a security decision.

References: src/types.ts• L314-370 src/types.ts• L419-448 src/index.ts• L49-130 src/index.ts• L527-573 src/…/terminal.ts• L138-204 src/…/terminal.ts• L212-279 src/…/terminal.ts• L286-324

Change checklist

When these files or sections are changed, remember to consider these:

  • When injection payload fields or evaluator output fields change, update the evaluator tool contract, response parsing, shared suite mapping, and report rendering together.
  • When a taint source or sink changes, review its severity class and the cross-file flow rules. A new node type alone does not create a useful risk decision.
  • When sandbox observations change, update both the behavioral verdict logic and the CLI mapping from observations to SandboxBehavior and Finding records.
  • When hook schema support changes, keep standard and legacy parsing, unrecognized-hook warnings, command execution, and the sandbox child-page contract aligned.
  • When active scan flags or deep-scan fields change, keep phase enablement, null-result behavior, and terminal output aligned.
  • When hook execution settings change, re-check canary values, timeout handling, work-directory cleanup, and the claim that the run is isolated.

Important failure modes

TriggerConsequenceGuard
Injection evaluator API failure or missing tool responsePayloads are returned with vulnerable: false and zero confidence so the suite can look blocked even though it was not evaluated.Treat zero-confidence and “unable to evaluate” evidence as untested. Do not use it as a clean pass.
No valid settings file, no parsed hooks, or a hook schema that the parser does not recognizeSandbox analysis returns no result or executes zero hooks.Distinguish “nothing to execute” from “all hooks behaved safely.” Check for a declared but unrecognized hooks block.
Taint flow is indirect, non-local, or outside the supported text patternsThe static check can miss a real source-to-sink path or report a nearby pattern without proving runtime flow.Pair it with sandbox evidence and manual review of high-impact hooks.
A hook reads outside its temporary work directory or uses a behavior not visible in command outputThe temporary directory and fake environment do not provide a complete operating-system boundary.Treat this executor as a detection aid, not a full host sandbox. Run untrusted commands in a stronger isolation boundary.
A hook uses a network or file behavior that the output patterns do not revealThe run can under-report external access or file activity.Review the command and its outputs, then use stronger runtime controls when the hook is untrusted.
Sandbox cleanup failsTemporary work data can remain after analysis.Check cleanup results in the operating environment and remove residual sandbox directories under controlled ownership.

Key files

FileWhy to read it
src/index.tsShows how the scan enables the three active validation phases and maps their results into the overall report.
src/types.tsDefines the shared contracts for injection results, taint flows, sandbox results, and deep-scan output.
src/…/index.tsShows how discovered configuration becomes the public injection-suite result used by the scan.
src/…/payloads.tsDefines the hostile payload corpus and the categories used to vary attack techniques.
src/…/tester.tsExplains how configuration context is assessed, how evaluator failures are represented, and how resistance evidence and scores are formed.
src/…/analyzer.tsDefines the source, sink, flow, and severity model for untrusted data paths.
src/…/executor.tsDefines hook-shape support, controlled execution, canary values, timeout handling, cleanup, and runtime observations.
src/…/index.tsShows the public boundary between sandbox execution, behavior analysis, and their result types.
src/…/analyzer.tsConverts sandbox observations into findings, a risk score, and a behavior verdict.