Sub topic 3
Prompt Injection and Data Exfiltration
This chapter assumes basic Git, command-line, environment-variable, and AI assistant knowledge.
Prompt Injection and Data Exfiltration
A prompt injection is untrusted text that tries to change an AI agent's instructions. It may appear in an issue, README, log, web page, or source comment. For example, a malicious comment might tell an agent to upload .env to a remote service.
Data exfiltration is the unauthorized transfer of data out of your system. Treat files, command output, and tool responses as untrusted input. An agent should not follow instructions found in that content.
Vetting Extensions and Tool Servers
Extensions and tool servers, including MCP servers, can receive prompts, files, and command results. Review their source, maintainer, permissions, network destinations, update history, and data policy. Install only the tools your project needs. Use a separate process or container when the trust level is unclear.
Catching Secrets Before They Are Committed
Run secret scanning before commits and in continuous integration. For example, configure a scanner with pre-commit:
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: gitleakspip install pre-commit
pre-commit install
pre-commit run --all-filesWhen a Secret Leaks
Treat a leaked credential as compromised, even if you delete the file.
- Revoke or disable it.
- Rotate it and update dependent services.
- Inspect logs for misuse.
- Remove it from source, history, prompts, and artifacts.
- Record the cause and improve controls.
When to Use a Self-Hosted or Local Model
A local or self-hosted model can reduce provider exposure, but it does not make data automatically safe. The host, extensions, logs, backups, and network still need protection. Choose this option when policy or data sensitivity requires control over storage and processing, and when your team can maintain the infrastructure.
Writing a Team Policy
Define approved tools, prohibited data classes, retention requirements, agent permissions, review steps, scanning requirements, and incident contacts. Require human approval for external communication and production changes. Reassess vendors and extensions when their terms or permissions change.
Exercise
An agent finds a token in a pasted log and proposes sending it to a debugging service. What should you do?
Show answer
Reject the transfer, redact the token, revoke and rotate it, inspect access logs, and report the incident.