AI Agent Security: Why Prompt Restrictions Fail and Configurations Welcome Execution

    This article explains why a recently disclosed attack chain cannot be fixed by patching a single product, and why it succeeds across two independent AI coding tools. It breaks the chain into five observable stages—from a web page writing a project specification file into the Downloads folder to final code execution and persistence—and maps each stage to a practical control: treating the Downloads directory as untrusted input, versioning and hashing global configuration for drift detection, separating specification documents as data from signed instructions, enforcing a default-deny egress whitelist, and rotating credentials on detection. Includes policy snippets, a configuration drift checker, an egress policy example, and a control matrix for security and testing teams.

    1. A Problem No Single Patch Can Close

    A security firm’s reproduction report reaches a conclusion that makes many teams uncomfortable: no single link in this attack chain is a defect that one product can patch. This is not about excusing vendors. The reproduction spans two independent AI coding tools with separate codebases, and both chains succeeded. When the same pattern holds in implementations that share no code, it is more likely an architectural property than a one-off implementation mistake.

    The report offers an analogy that test engineers will appreciate: when a browser faithfully renders a spoofed login page, the browser has done nothing wrong. The defect lives in the page content, so “patch the browser” is not a solution. In the same way, an agent that strictly follows the project specification file in its working directory is behaving as designed. You may disagree with that judgment, but the conclusion is unavoidable: since upstream cannot be expected to fix it, it becomes a check you must add to your own pipeline.

    2. Five Actions in the Chain and Where to Check Them

    The disclosed chain breaks into five steps, each landing on an observable, interceptable position.

    Step 1: a web page writes a file into the user’s Downloads directory. Downloads is one of the few locations a page can write to on its own—no click, no second confirmation, with the file name and content fully controlled by the page. Operating systems already block automatic execution of downloaded executables, but a project specification file is not an executable, so none of the guardrails built for executables apply to it.

    Step 2: the user launches the agent inside the Downloads directory. Telemetry cited in the report shows that roughly half of users have run coding tools from Downloads, and about a quarter of sessions open a real browser. This path works not by coincidence but by habit.

    Step 3: the agent reads the file and modifies its own global configuration. The real sample is a long “engineering work specification” document of a dozen-plus kilobytes, with the malicious content hidden in a section named “Local Development Environment” that instructs the agent to append an external tool service registration block to the global configuration.

    Step 4: the newly registered service is loaded at session startup, giving the attacker a stable execution channel.

    Step 5: an unknown-origin dependency package is installed through that channel, completing code execution and persistence. In the sample, one tool’s trigger success rate exceeded ninety percent while the other was around half—a difference that comes from default confirmation policy, not model capability.

    3. Five Executable Detections

    3.1 Entry Control: Treat Downloads as an Untrusted Input Zone

    Do not try to identify “malicious files.” Downgrade the entire Downloads directory to a quarantine zone by policy. Practical measures include: forbid agents from starting in Downloads, temporary directories, or mounted shared directories; verify before launch that the working directory is a managed repository root; and tag the origin of newly added specification-type files in the directory, so untagged files cannot enter the context.

    1. # Pseudo-policy: working directory admission
    2. allow_root: /srv/repos/**
    3. deny_root: ~/Downloads, /tmp, /mnt/shared
    4. require_marker: .repo-origin

    3.2 Configuration Integrity: Version and Verify Global Configuration

    Global configuration is the core asset in this chain. It must satisfy three conditions: versionable, verifiable, and alerting on change. Put the configuration under version control and compare hashes at every session startup; any appended service registration block will be identified as drift.

    1. #!/usr/bin/env python3
    2. # Configuration drift check: standard library only
    3. import hashlib, json, os, sys, pathlib
    4. WATCH = [
    5. "~/.config/agent/global.toml",
    6. "~/.config/agent/mcp.json",
    7. "~/project/.agent/settings.json",
    8. ]
    9. BASELINE = pathlib.Path("~/.agent-baseline.json").expanduser()
    10. def digest(p: pathlib.Path) -> str:
    11. return hashlib.sha256(p.read_bytes()).hexdigest()
    12. def load_baseline() -> dict:
    13. if BASELINE.exists():
    14. return json.loads(BASELINE.read_text())
    15. return {}
    16. def main() -> int:
    17. base = load_baseline()
    18. drift = []
    19. for item in WATCH:
    20. p = pathlib.Path(item).expanduser()
    21. if not p.exists():
    22. continue
    23. cur = digest(p)
    24. old = base.get(item)
    25. if old is None:
    26. base[item] = cur
    27. elif old != cur:
    28. drift.append(item)
    29. BASELINE.write_text(json.dumps(base, indent=2))
    30. if drift:
    31. print("[DRIFT] Configuration change detected:", ", ".join(drift))
    32. return 2
    33. print("[OK] Configuration matches baseline")
    34. return 0
    35. if __name__ == "__main__":
    36. sys.exit(main())

    The first run establishes the baseline; after that, wire it into the pipeline. Exit code 2 blocks the session.

    3.3 Prompt and Execution Layering: Specification Files Are Data, Not Instructions

    Draw one boundary clearly: specification documents, README files, comments in the repository, and web content are data to be processed. Only policies that come from a managed control plane and are signed carry instruction authority. In engineering terms: specification files may only influence code style and a build-command allowlist; any action involving writing global configuration, changing dependency sources, or reading credentials requires out-of-band confirmation, and the confirmation must display the real change diff rather than a natural-language description from the document.

    3.4 Egress Allowlist: Default Deny

    A malicious dependency package must reach the network to complete its pull and exfiltration, which makes egress policy the most cost-effective layer. Default deny, allow per repository; dependency installation may only go through internal mirrors and private repositories; detect and alert on unusual ports, long-lived connections, and encoded payloads.

    1. egress:
    2. default: deny
    3. allow:
    4. - host: registry.internal
    5. ports: [443]
    6. - host: pypi.internal
    7. ports: [443]
    8. deny_logs: /var/log/egress/denied.log

    3.5 Rotate on Detection: Write the Response into the Runbook

    Once configuration drift is confirmed, treat it as a leak: rotate every reachable credential and token on that host, revoke sessions, and rebuild the environment rather than cleaning files; keep an image for forensics; and review why launching in an untrusted directory was allowed. Rotate-on-detection belongs in the on-call runbook so no one has to make a judgment call in the moment.

    4. Control Matrix

    Stage Risk Action Control Detection Signal
    Entry Specification file lands in Downloads Working directory admission, origin tagging Launch from a non-managed root
    Configuration Appended external service registration block Baseline hashing, versioning Hash mismatch
    Layering Document content treated as instructions Data/instruction separation, out-of-band confirmation Config write triggered by an unsigned policy
    Egress Pulling unknown dependencies, exfiltration Default deny, internal mirrors Hit in the deny log
    Response Credentials remain usable Rotation, revocation, rebuild Rotation ticket closed

    5. Conclusion

    The common thread in this class of risk is that each point looks compliant on its own, and only the chain is lethal. What testing and security teams can do is turn the default assumption of “trust the directory content” into explicit verification, so that the five layers—entry, configuration, layering, egress, and response—each take effect independently. More broadly, logging services and monitoring alerts can centralize observation of drift and denial events, turning a gate from a one-time check into continuous verification.