Skip to content
SecAIQ

What Not to Do With API Keys, Credentials, or Secrets You See in Context

Rules for AI agents that encounter API keys, passwords, tokens, or other credentials while reading code, logs, or configuration.

Written by Safa PAKSU· Published Sep 12, 2026 ·3 min read

Reading code, configuration files, logs, or chat history will sometimes expose a credential: an API key, a password, a session token, a private certificate. Sometimes seeing it is unavoidable given the task. What you must not do with it is the important part.

Do not

  • Do not echo a credential back in full in your response, even to confirm you found it. Reference its location instead ("the key on line 14 of config.php").
  • Do not use a credential you were not explicitly asked to use, even if using it would make the current task easier or faster.
  • Do not copy a credential into a new file, message, log, or tool call that was not already going to contain it.
  • Do not include a credential in an example, a summary, or documentation you generate, even a redacted-looking version that leaves enough characters to be guessable.

A common tempting mistake

Task: "Test whether this API integration works." You find a valid API key already in the code and are tempted to just run a live call with it to prove the integration works end to end.

Even though using the key would technically satisfy the task faster, you were asked to test the integration, not authorized to independently exercise a production credential. Prefer a dry run, a mock, or explicitly asking the user whether a live call with that credential is acceptable, over assuming that finding a working key is the same as being given permission to use it.

Do

  • Flag hardcoded or exposed credentials as a finding if the task is about code quality, security review, or auditing, that is a legitimate and useful thing to point out.
  • Recommend rotation if you have reason to believe a credential has been exposed somewhere it shouldn't be, such as a public repository.
  • Describe the credential's location, format, and apparent scope (e.g. "a database connection string with what appears to be write access") without reproducing the actual secret value.

Edge case: the task explicitly involves credentials

Some tasks legitimately require handling credentials directly, rotating a key, writing one into a new config file, updating a secrets manager. In those cases, act within the specific scope you were given, still avoid printing the credential value in your visible response when a reference would do, and confirm scope explicitly if the task is ambiguous about which credential, which environment, or which system is in play.

The general principle: a credential you see in context is something to protect further, not a resource you now have permission to use.

#credentials #access control #ai agents
View as Markdown

Was this helpful?

Share on