Keeping Secrets and Sensitive Data Out of AI Coding Tools
Protect credentials and sensitive information when using AI coding tools. Review context access, integrations, repository exclusions and response to accidental exposure.
An AI coding tool can receive more information than the text typed into a prompt. Depending on its configuration, it may read repository files, terminal output, logs, attachments, retrieved documents and connected services.
Before using it on a project, establish what information the tool can access and where that information can be sent. Apply the controls to the actual product, account and deployment configuration rather than assuming every AI service handles data in the same way.
Define permitted context
Identify credentials, customer data, private keys, production exports and commercially sensitive material. Decide which categories may be used, under what conditions and with whose authority.
Use sanitised examples and synthetic records when they provide the required context. Removing a person's name alone may leave an identifiable account number, address or distinctive narrative in the remaining material.
Review repository and workspace access
Keep secrets outside source control and avoid placing production configuration in a broadly accessible workspace. Review local environment files, database dumps, support bundles and generated logs before granting project access.
Exclusion files can help limit context, but their meaning varies between tools and features. Confirm whether an exclusion applies to indexing, direct file reads, terminal commands and connected services. Do not treat a filename pattern as a complete security boundary without checking its behaviour.
Limit integrations and tool permissions
Give the coding assistant only the repositories and services needed for the task. Review connectors that can read tickets, cloud configuration or secret stores. A read-only integration can still disclose sensitive information into another system.
Separate development credentials from production and constrain any permitted execution environment. Require appropriate human review before privileged actions, especially where generated commands can reach external endpoints or alter deployed services.
Use harmless placeholders consistently
Provide examples such as EXAMPLE_API_TOKEN and explain how the application retrieves the real value at runtime. Avoid pasting a working key simply to demonstrate the format.
Check generated files and commits for accidental copying of sensitive values. Review console transcripts and error messages too; a failed command may print more context than a successful one.
Prepare an exposure response
| Step | Practical action |
|---|---|
| Identify | Record the material, destination, time and relevant account. |
| Contain | Stop further sharing and restrict the affected integration if needed. |
| Revoke | Invalidate exposed credentials and relevant derived access. |
| Investigate | Review access and use through the available audit records. |
| Handle copies | Follow the service's applicable deletion and retention process. |
| Learn | Correct the context, access or workflow that caused disclosure. |
Deleting a conversation or repository line does not by itself invalidate a credential. Check the provider's current controls and contractual arrangements when assessing retained copies and further processing.
Maintain an approved way of working
Document permitted tools, account types, data categories and escalation contacts. Revisit the decision when a provider changes features, integrations or terms, or when the team grants new capabilities.
Make safe examples easy to use so that developers can obtain useful help without copying production material. Include a quick review of context handling in onboarding and significant project changes.
Related resources
Read our testing methodology or discuss your assessment.