Static security analysis
AgentShield's static security analysis inspects agent-related repository material without running the agent or its hooks. It finds the files that define instructions, tools, hooks, skills, and external tool connections, adds source context to each result, and applies built-in checks to expose risky configuration before the system runs.
Analysis flow
The scan turns a repository path into a set of typed files, then into findings and a security report. The same scan result can also support later policy, baseline, reporting, and deeper analysis steps.
This diagram shows the main path from repository input to static analysis output.
flowchart LR
A[Repository path] --> B[Repository material]
B --> C[Typed source context]
C --> D[Built-in security rules]
D --> E[Findings]
E --> F[Severity ordering and source labels]
F --> G[Security report and score]
Repository material
Repository discovery treats agent configuration as a connected surface rather than a single file. It finds known root markers and related directories, reads each selected file, and assigns a type so the right checks can inspect it. The discovery and context details are covered in Repository discovery and context.
The scan covers these broad material groups:
- Agent instructions and definitions, such as CLAUDE.md and agent files.
- Settings and permission files.
- MCP server definitions. MCP means Model Context Protocol, which lets an agent call external tools.
- Skills, commands, rules, and context documents.
- Hook scripts and code, including scripts named by hook manifests.
- Package-manager and automation configuration that can affect the agent supply chain.
Discovery skips common generated or dependency directories. It also avoids treating a hook as a source file when its reference is external, absolute, outside the scan root, missing, or not a supported script type. These limits keep the scan tied to repository material that it can inspect as source. Dangling links in scanned configuration areas still produce low-severity findings so missing agent material is visible instead of silently ignored.
References: src/…/discovery.ts• L6-20 src/…/discovery.ts• L69-90 src/…/discovery.ts• L152-239 src/…/index.ts• L82-109 src/types.ts• L60-84
Source context
Source context records how closely a finding represents active runtime behavior. AgentShield uses the file path and file type to distinguish normal project configuration from optional local settings, documentation examples, plugin material, hook code, and declarative hook manifests.
This context changes how a reader should act on a finding. Structural findings from examples or plugin caches receive a lower severity and a clear title and description. Secret findings keep their severity because a secret remains exposed even when it appears in documentation or packaged content. A plugin manifest also points the reader to the referenced hook implementation for confirmation.
The context model prevents two opposite errors: treating sample guidance as confirmed runtime exposure, and ignoring real secret material because it appears outside the main configuration. See Repository discovery and context for the source classifications and their inputs.
References: src/source-context.ts• L1-18 src/source-context.ts• L33-55 src/…/index.ts• L111-171 src/…/index.ts• L187-238
Rule evaluation
The rule engine checks every discovered file against the built-in rule set. A rule can use the current file alone or compare it with the full discovered set, which lets the analysis relate definitions to other repository material. The engine collects all findings and orders them from critical to informational. The rule families and their checks are described in Security rule engine.
Static checks look for unsafe access, execution, data, and instruction patterns. They include secrets, permissions, hooks, MCP servers, agents, prompt defenses, package-manager settings, skills, harnesses, and agent-specific configuration. MCP checks can also compare server packages with known vulnerability data and inspect tool descriptions or arguments for poisoning and exfiltration signals.
The built-in registry also groups checks for Codex, Hermes, Claude Code, and other supported harnesses. This lets one scan apply shared security checks and checks for agent-specific configuration surfaces without requiring a separate scan for each harness.
Each finding identifies the rule result and its location. It may also include evidence, a line number, a runtime-confidence label, and a suggested fix. This gives downstream reports enough information to show what was found and why it matters without executing the configuration.
References: src/…/index.ts• L1-41 src/…/index.ts• L30-70 src/types.ts• L15-28 src/types.ts• L86-98 src/…/mcp-cve.ts• L8-24 src/…/mcp-tool-poisoning.ts• L4-14
Static analysis result
The scanner returns the discovered target, ordered findings, skill health data, and detected harness adapters. A harness adapter is a recognized agent environment such as Claude Code, OpenCode, Codex, Gemini, Zed, or VS Code; its match gives later consumers a view of which agent surface the repository uses. The scan also reports dangling configuration links as findings when discovery cannot resolve them.
The report layer turns findings into a score that starts at 100 and deducts points by severity. It keeps category scores for secrets, permissions, hooks, MCP, and agents, then derives the overall grade from those categories. Source context weights structural findings from examples, optional settings, plugin material, and manifests so inventory does not look like active exposure. The command line can filter findings by minimum severity before it builds the report.
References: src/…/index.ts• L18-45 src/…/index.ts• L82-109 src/types.ts• L100-110 src/…/score.ts• L14-31 src/…/score.ts• L52-103 src/index.ts• L315-332
Analysis boundaries
Static analysis reads repository material and applies pattern and configuration checks. It does not prove what a hook will do at runtime, whether an instruction can be bypassed in a live session, or whether a data flow is exploitable. Those questions belong to the optional injection, sandbox, taint, and AI-assisted analysis stages that can follow the static phase.
The normal scan therefore provides an early risk map. A deep scan can place that map beside active validation results, but it does not change the role of static analysis as the first pass over repository-defined agent behavior.
Change checklist
When these files or sections are changed, remember to consider these:
- A new agent configuration location needs discovery, a
ConfigFileType, and rule coverage. If the location changes runtime confidence, update source-context classification and score weighting together. - A new rule family must be registered in
getBuiltinRules; otherwise the rule exists but never runs in a normal scan. - A new
FindingCategoryorRuntimeConfidencevalue must stay aligned with score mapping and source-context adjustment. An unmapped category can silently affect the wrong score bucket. - A change to hook manifest syntax must update both manifest checks and referenced-script discovery. Otherwise the scan can report the declaration without inspecting its implementation.
- A change to dangling-link handling must keep discovery output and finding construction aligned. Otherwise missing configuration can disappear from the report or receive the wrong category.
- A change to severity filtering must be checked against report scoring. The command builds the report from the filtered finding set.
Important failure modes
| Trigger | Consequence | Guard |
|---|---|---|
A configuration is placed under an ignored directory such as node_modules, dist, or vendor | The material is not part of the scan target and its risks are not reported | Keep security-relevant configuration in a discovered repository surface or add an intentional discovery rule |
| A hook uses a missing, unsupported, external, absolute, or out-of-root script path | The hook implementation is not added to the source set, so code-level hook checks cannot inspect it | Use a supported local script path and verify that the referenced file exists inside the scan root |
| A documentation or plugin-cache finding is read without its runtime-confidence label | A sample or packaged behavior can be mistaken for active project configuration | Review the source label and the adjusted title and description before treating the finding as runtime exposure |
| A new rule is not returned by the built-in rule registry | The rule never evaluates files during a standard scan | Register every new rule family in src/…/index.ts |
| A dangling configuration link is treated as a normal discovered file | The report can miss that an agent expects material that no longer exists | Review low-severity dangling-link findings and restore or remove the link |
| A malformed JSON hook or MCP file cannot be parsed | Checks that need structured data may produce no finding for that file | Keep these configuration files valid and review parse-related scan gaps when a file is rejected |
Key files
| File | Why to read it |
|---|---|
| src/…/index.ts | Primary static scan flow, finding collection, ordering, source-context adjustment, and dangling-link findings. |
| src/…/discovery.ts | Repository material discovery, file typing, ignored paths, and hook reference following. |
| src/source-context.ts | Shared path classifications for examples and plugin caches. |
| src/…/index.ts | Registry that makes the built-in rule families active in each scan. |
| src/types.ts | Contracts for discovered files, findings, confidence labels, and scan results. |
| src/…/score.ts | Translation from static findings and confidence into category scores and the overall grade. |
| src/…/agents.ts | Representative checks for agent tool scope, metadata, and risky agent behavior. |
| src/…/hooks.ts | Representative checks for hook injection, external data transfer, and persistence surfaces. |
| src/…/mcp.ts | Representative checks for MCP access and server risk profiles. |
| src/…/mcp-cve.ts and src/…/mcp-tool-poisoning.ts | Cross-checks for known vulnerable packages and hostile MCP tool configuration. |
| src/index.ts | Command-level placement of static analysis before optional deep analysis and report generation. |