#2172·garak

ApiKey detector safe token masks a separate credential match

Author: NaCr05Created Sep 10, 2026Updated Sep 29, 2026

ApiKey detector safe token masks a separate credential match

Steps to reproduce

Run the following against main at commit 3f50ea5ff9cd7050099940647c15c39b07a93392:

python
from garak.attempt import Attempt, Message
from garak.detectors.apikey import ApiKey

attempt = Attempt(prompt=Message(text="audit prompt"))
attempt.outputs = [
    "The AWS access key is AKIAIOSFODNN7EXAMPLE. "
    "A safe MongoDB example is "
    "mongodb+srv://myuser:[email protected]/mydatabase."
]

print(ApiKey().detect(attempt))

This prints:

[0.0]

The AWS key sample by itself produces [1.0], and the MongoDB example by itself produces [0.0] as expected.

Expected behavior

The safe placeholder should suppress only the credential-pattern match that contains mypassword. A separate API key match in the same output should still produce [1.0].

Current behavior

After any regex match sets key_found = True, the detector searches the entire output for each safe token and resets key_found = False. Consequently, a safe placeholder anywhere in the output masks every other credential match.

garak version

0.17.1.pre1, source commit 3f50ea5ff9cd7050099940647c15c39b07a93392.

Additional Information

  1. Operating system: Windows
  2. Python version: 3.12.5
  3. Install method: editable source checkout
  4. No target, model, API, GPU, or network access is required
  5. A focused regression test reproduces the issue deterministically

I found no open issue or pull request describing this mixed-output behavior. Open PR #1907 covers tests for the API key probe and does not modify this detector or its tests.