Summary
Microsoft APM's CLI improperly follows symbolic links when integrating prompt and agent files from dependencies, allowing arbitrary filesystem content to be read and copied into deployment directories.
An attacker who controls a remote APM dependency can inject symlinks that cause sensitive or unexpected files to be included in a project's deploy tree and source control, bypassing integrity checks and pre-deploy scanning.
Affected context
This issue affects projects using Microsoft APM CLI versions 0.5.4 through 0.12.4 that:
- Depend on remote APM packages containing prompt or agent definitions under:
.apm/prompts/<x>.prompt.md.apm/agents/<x>.agent.md- Use the primitive integrators that enumerate files via
Path.glob()/Path.rglob()and read them withPath.read_text()without restricting symlinks - Rely on the auto-generated
.gitignoreand built-in integrity checks (content_hash, SecurityGate scan, apm audit) to catch unsafe content
In these conditions, symlinks preserved into apm_modules/ may be transparently dereferenced during integration, with their resolved content written into deploy directories that are not ignored by default.
Exploit preconditions
- Attack surface: Supply-chain dependencies in the APM ecosystem (remote APM packages).
- Required access: Ability to publish or modify an APM dependency consumed by the target project, or to influence which dependency versions are pulled.
- Trigger point: Running the APM CLI integrators that:
- Clone or update dependencies into
apm_modules/ - Enumerate prompt/agent files under
.apm/prompts/or.apm/agents/viaPath.glob()/Path.rglob() - Read and rewrite each matched file into the project's deploy directories.
- Why exploitation is possible:
- Symlinks inside dependencies are preserved when cloned into
apm_modules/. - The integrators do not filter or special-case symlinks and use
Path.read_text()directly, causing symlinks to be dereferenced. - The resulting materialized files in deploy directories are treated as regular content, not flagged by
content_hash, SecurityGate, orapm audit. - Deploy roots are not automatically ignored by
.gitignore, sogit addstages these files by default.
Why this happens
The root cause is insecure handling of filesystem traversal and symlinks in the APM CLI's integration logic.
The integrators use Path.glob() / Path.rglob() to enumerate prompt and agent files and Path.read_text() to read each match, implicitly trusting that all discovered paths are regular files. Symbolic links are treated the same as real files, so a symlink within a dependency pointing to an arbitrary location is transparently followed. The resolved content is then copied into the deploy directories as if it originated from the dependency's prompt or agent definition.
This behavior maps to CWE-59: Improper Link Resolution Before File Access ('Link Following') because the code does not constrain or validate link targets before accessing them. The additional association with CWE-200: Exposure of Sensitive Information to an Unauthorized Actor arises because symlink targets can include sensitive local files whose contents become embedded in project artifacts and even committed to version control.
Potential impact
- A malicious dependency could cause arbitrary local files (e.g., configuration files, private prompts, API keys stored in text files) to be read and embedded into the project's deploy directories.
- Sensitive information available on the development machine or CI environment may be exposed if the generated deploy files are committed to source control or distributed with application artifacts.
- Untrusted or unexpected content may be injected into prompts or agent definitions, potentially altering AI agent behavior in subtle or malicious ways.
- Integrity assumptions based on
content_hash, SecurityGate scan, andapm auditmay be undermined, as they do not flag symlink-based content substitution in this workflow. - Downstream consumers of the project may unknowingly redistribute files that originated from symlink-resolved paths, amplifying data exposure or supply-chain risks.
General mitigation guidance
Mitigation focuses on enforcing strict file-type and path controls when traversing dependency content and on limiting the trust placed in downstream deployment artifacts.
Useful defensive patterns include:
- Symlink-aware file traversal: Explicitly check
Path.is_symlink()before reading files discovered viagloborrglob, and either skip symlinks or handle them under a tightly scoped policy (e.g., only within a known safe tree). - Canonicalization and path constraints: Normalize and validate file paths, ensuring that resolved paths remain within expected directories (e.g., under
.apm/prompts/or.apm/agents/) and do not escape via..segments or symlinks. - Separation of build and source trees: Treat deploy directories as build artifacts, not as source, and avoid automatically staging them in version control. Default
.gitignorepatterns can be configured to exclude deploy roots. - Least-privilege filesystem design: Avoid placing highly sensitive files in locations that could be reached by automated tooling, and isolate secrets or confidential prompts in dedicated locations with stricter access control.
- Defense-in-depth scanning: Apply generic content and secret scanning to generated deploy directories, regardless of whether they passed earlier integrity or audit checks.
How teams detect issues like this
Detection can be approached by combining static analysis of integration code, runtime monitoring of filesystem access, and policy enforcement in CI/CD.
Potential strategies include:
- Static analysis rules: Flag usage of
Path.glob()/Path.rglob()combined with directPath.read_text()or similar read operations whereis_symlink()or path canonicalization checks are absent. Tools can be configured to highlight file traversal logic that does not explicitly handle symbolic links. - Code review signals: Reviewers should pay special attention to:
- Any integration or packaging code that walks directories and copies files into deployment or build output locations.
- Cases where "all files" under a directory are processed without constraints on file type or symlink resolution.
- Situations where deployment artifacts are placed under version-controlled paths by default.
- Policy enforcement in CI/CD: Enforce policies that:
- Prevent deploy directories from being checked into source control or require justification for such patterns.
- Run content and secret scanners over generated artifacts to detect unexpected inclusion of sensitive files.
- Automated tooling: Optional use of automated code review or SAST tools to track link-following behavior and identify potential CWE-59 patterns across the codebase, particularly in build and integration scripts.

