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 / injection-and-taint-testing

Injection and taint testing

Injection and taint testing are two active checks for agent security. Injection testing asks whether an agent configuration resists hostile instructions, while taint analysis follows untrusted data toward actions that can execute code, send data, or change files. Together they connect model behavior with the configuration paths that can turn risky input into impact. See Adversarial security validation for the parent view and Sandbox execution for runtime observation of hooks.

Validation role

These checks answer different questions about the same agent-facing system. Injection testing evaluates the strength of written defenses against known attack patterns. Taint analysis checks whether configuration text creates a path from an untrusted value to a dangerous operation.

The checks are complementary rather than interchangeable:

CheckMain questionEvidence produced
Injection testingCan a hostile instruction bypass the agent's stated rules?Per-payload resistance, evidence, attack path, and mitigation
Taint analysisCan risky data reach a dangerous operation in configuration or hook content?Sources, sinks, and severity-ranked flows

Validation boundaries

Injection testing is an AI-assisted assessment of configuration context. Taint analysis is a static string-level scan. Neither check proves that a live agent is safe in every possible state, so the results work best with the static rule scan and the sandbox execution view.

References: src/…/tester.ts• L148-170 src/…/analyzer.ts• L181-190 src/types.ts• L419-431

Injection testing

Injection testing builds a test suite from hostile prompt examples and asks an evaluator to judge the target configuration against each example. The suite focuses on whether the configuration enforces instruction order, protects its instructions, separates data from commands, limits tools, and detects hostile input.

Payload corpus

The payload corpus is a structured set of attack cases. Each case has an ID, category, text, expected behavior, severity, and source attribution, which lets a run be filtered without losing the reason that a case matters.

The corpus covers these attack families:

FamilyAttack categoriesRisk being probed
Persona and pressureDAN, roleplay jailbreaks, crescendo, emotional manipulationAttempts to replace the agent's role or weaken its refusal behavior
Instruction boundariesSystem prompt extraction, instruction hierarchy, delimiter confusionAttempts to make user content look like higher-priority instructions or reveal protected rules
ObfuscationBase64 and other encoding, Unicode homoglyphs, multi-language inputAttempts to evade simple text checks
Content channelsMarkdown injection and indirect injectionAttempts to hide instructions in rendered content, documents, code, tool output, or other data

The corpus can be selected by category or by a minimum severity. This supports focused checks while keeping the same case metadata for comparison across runs. Corpus checks also protect stable IDs, category coverage, severity values, source attribution, and the expected shape of modern indirect-injection cases.

References: src/…/payloads.ts• L5-27 src/…/payloads.ts• L31-44 src/…/payloads.ts• L842-885 tests/injection.test.ts• L21-120

Configuration evaluation

The evaluator receives one context that joins the main agent instructions, optional settings, and agent definitions. The CLI integration discovers these configuration parts from the target and passes them to the tester, so the assessment covers the same agent-facing material that the scan found.

The evaluation considers whether the context has:

  • Clear instruction hierarchy and anti-override rules.
  • Protection against system-prompt extraction.
  • Input checks that can detect hostile forms.
  • Permission limits that reduce the result of a successful bypass.
  • Clear boundaries between instructions and data.

The tester sends payloads in controlled batches through the selected language-model provider. A structured evaluator response records whether each case is vulnerable, the confidence of the judgment, the evidence, the possible attack path, and a suggested mitigation. The suite returns counts for tested, vulnerable, and resistant cases.

The following flow shows how discovered configuration and selected payloads become per-case security evidence.

flowchart LR
    A[Discovered agent configuration] --> B[Configuration context]
    P[Payload corpus] --> C[Payload batches]
    B --> C
    C --> D[Selected language-model evaluator]
    D --> E[Structured per-payload results]
    E --> F[Suite counts and resistance score]

References: src/…/index.ts• L33-67 src/…/tester.ts• L148-215 src/…/tester.ts• L230-281 tests/injection.test.ts• L193-239

Resistance results

The suite reports a resistance score from 0 to 100. A resistant case contributes its full severity weight. A vulnerable case lowers the score, with critical cases carrying more weight and low-confidence findings receiving partial credit.

The result is not only a pass rate. The evidence and attack path explain why the evaluator believes a case can succeed, while the mitigation points to the defense that is missing or insufficient. A case with confidence 0 means that the evaluator did not make a usable judgment; it must not be read as proof that the payload was blocked.

The command-line bridge maps the detailed suite to the scan result shape. It reports resistant cases as blocked and vulnerable cases as bypassed. This mapping makes incomplete evaluator responses especially important: an API failure or missing payload result is represented as non-vulnerable with zero confidence so that the failure evidence remains available, but the blocked count and score must not be treated as a security verdict without checking that evidence.

References: src/…/tester.ts• L256-281 src/…/tester.ts• L295-362 src/…/tester.ts• L393-425 src/…/index.ts• L70-83 tests/injection.test.ts• L281-383 tests/injection.test.ts• L386-540

Taint analysis

Taint analysis models a tainted flow as a path from a source of untrusted data to a sink that can cause an external effect. It works on the discovered configuration files and reports the source node, sink node, path description, and severity so engineers can inspect the risky boundary.

Source and sink model

Sources represent values that an agent or hook should not trust by default. Sinks represent operations that can execute commands, move data outside the environment, write files, or start processes.

Source groupExamples of data represented
EnvironmentEnvironment variable references and environment entries
User or caller inputStandard input, prompt-like values, and command-line arguments
File and network dataInterpolated file content and URLs or fetched values
Sink groupEffect represented
Command executionShell commands, evaluation, or process spawning
Network sendRequests or transfers to a URL or network tool
File writeRedirection, tee, or file-writing operations

The analyzer treats the relationship between a source and sink as the important signal. For example, user input reaching shell execution is more severe than an environment value reaching a file write because the possible impact is different.

References: src/…/analyzer.ts• L1-7 src/…/analyzer.ts• L11-91 src/types.ts• L349-370

Flow detection

The analysis looks for direct source-and-sink pairs on one line and for a source followed by a sink within a small forward window in the same file. It also checks a narrower cross-file case in which an environment name defined in one file appears near a sink in another file. This gives useful early warning for common hook and agent configuration patterns without claiming to trace full program behavior.

Severity ranks the possible relationship. Untrusted user, file, or network data reaching code execution is critical. Data that can reach a network send or an evaluation operation is high risk. Environment values reaching network sends are also high risk because they may contain secrets. Other matches receive lower severity when the sink or source combination has less direct impact.

The result removes duplicate nodes and duplicate flow descriptions, then sorts flows from critical to low severity. It does not execute the hook, resolve variables, or follow multi-step program logic.

References: src/…/analyzer.ts• L93-141 src/…/analyzer.ts• L191-297 src/…/analyzer.ts• L299-372

Scan lifecycle

The scan command enables injection testing and taint analysis as separate modes. The --deep option enables both along with sandbox execution and other analysis layers, so the final summary can place model resistance, data flow, and observed hook behavior side by side.

Analysis stages

The command first discovers the target files for the normal static scan. When enabled, taint analysis reads those discovered files and injection testing extracts the main configuration, settings, and agent definitions for its evaluator context. The two checks then render their own results and add their typed outputs to the deep-scan result.

The following flow shows how one discovered target produces separate evidence types before the deep-scan summary joins them.

flowchart TD
    A[Target path] --> B[Configuration discovery]
    B --> C[Static rule scan]
    B --> D[Taint analysis]
    B --> E[Injection testing]
    B --> F[Sandbox hook execution]
    C --> G[Deep scan summary]
    D --> G
    E --> G
    F --> G

This lifecycle keeps static evidence, model-based judgment, and runtime behavior as separate evidence types. A taint flow can show that a path exists even when no payload has bypassed the written defenses. An injection result can show weak instruction defenses even when no hook has yet produced a suspicious runtime action.

References: src/index.ts• L269-313 src/index.ts• L527-573 src/index.ts• L638-652 src/types.ts• L419-431

Change checklist

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

  • Payload IDs, categories, severity, and expected behavior affect filtering, score weight, and the meaning of historical suite results.
  • The fields in the evaluator tool response must stay aligned with the parser and with the bridge that maps detailed results to blocked and bypassed counts.
  • The selected language-model provider must remain compatible with the evaluator tool contract and the model resolution path.
  • Changes to configuration discovery must keep the injection context and taint input set aligned with the files that the static scan sees.
  • Changes to source or sink patterns must be reviewed with severity rules because a new match can change both flow counts and risk order.
  • Changes to the deep-scan result shape must be reflected in the terminal summary so missing analysis is distinct from an empty or successful analysis.

Important failure modes

TriggerConsequenceGuard
The evaluator API call fails for a payload batch.The batch is returned with confidence: 0 and a non-vulnerable flag. The CLI bridge can therefore count an unevaluated case as blocked.Check the tested count, confidence, and failure evidence before treating the blocked count or resistance score as a security verdict.
The evaluator omits some payloads or does not return the required tool response.Missing cases become unevaluated results and can increase the calculated resistance score because they are represented as non-vulnerable with zero confidence.Treat incomplete batches as unknown and inspect the per-payload evidence.
A hostile configuration is included in the evaluator context.Instructions in that configuration can influence the AI-assisted judgment, so the result may not be independent evidence of resistance.Compare the result with static findings, taint flows, and sandbox observations.
A provider does not support the required structured evaluator response.Results can be incomplete or unevaluated even though the scan returns a suite result.Verify provider support for tool-based output and inspect zero-confidence cases.
A tainted source and sink use different lines or files outside the supported proximity pattern.The analyzer can miss a real multi-step flow. A nearby but unrelated pair can also create a noisy flow.Use the flow as a lead for review and confirm behavior with runtime or targeted analysis.
A payload category or severity is changed without keeping its metadata and filters aligned.Coverage and resistance scores change without a clear change in agent posture.Preserve stable IDs and review category coverage, severity weights, and report interpretation together.

Key files

FileWhy to read it
src/…/payloads.tsDefines the payload contract, attack families, severity metadata, and corpus selection behavior.
src/…/tester.tsShows how configuration context becomes batched evaluator work and how results become resistance measurements.
src/…/index.tsConnects discovered configuration files to injection testing and maps results into the scan contract.
src/…/analyzer.tsDefines the source-to-sink model, flow matching scope, severity rules, and returned evidence.
src/index.tsShows when the CLI enables each check and how both outputs join the deep-scan lifecycle.
src/types.tsDefines the shared injection, taint, and deep-scan result contracts.
src/…/terminal.tsShows how engineers see taint counts, injection block rates, and bypass warnings in terminal output.
tests/injection.test.tsDescribes the expected payload coverage, evaluator response handling, score behavior, and configuration-context checks.