Skip to main content

Secret detection

The same guardrails that mask personal data also catch secrets, so a key or a password pasted into a prompt does not reach the model provider. Set up the guardrails once and both protections are on.

What it detects​

KindWhat it covers
SECRET_PROVIDER_KEYAPI keys for online services
SECRET_CLOUD_KEYCloud access keys
SECRET_PRIVATE_KEYPrivate keys
SECRET_CONNECTION_STRINGDatabase connection strings that contain a password
SECRET_JWTLogin tokens (JWTs)
SECRET_TOKENPasswords and tokens written next to a word such as password, parol, or пароль

Detection uses the default rule set of gitleaks (version 8.30.1), plus Pishtaq's own rules for connection strings and for password words. For the generic password and token rules, values that look like code or like an obvious placeholder, such as changeme, are left alone.

Block or mask​

What happens depends on who is sending the request.

TrafficDefaultWhat the person sees
A person chatting directlyBlockAn error that names the kind of secret and asks them to remove it, and to rotate it if it was shared
A coding agent such as Claude Code, Codex, opencode, or Cursor, or any request that declares toolsMaskNothing changes. The model sees a placeholder such as <SECRET_PROVIDER_KEY_3f9a1c2b7d40>. When it writes that placeholder back, for example while editing a .env file, Pishtaq puts the real secret back into the tool call

A blocked request gets an HTTP 400 and is not sent to the provider.

Agents resend the whole conversation on every turn, so blocking them would end the session for good once a tool had read a secret. Masking keeps the session going, and the secret still never reaches the provider.

A secret in a tool definition, or in another setting of the request such as the response format, is always blocked, whatever the traffic.

Change the defaults for a team​

A team can change either default, or allow certain kinds of secret, with the pishtaq_secrets key of its metadata. For example, with the /team/update API:

curl -X POST "https://pishtaq.example.com/team/update" \
-H "Authorization: Bearer $PISHTAQ_ADMIN_KEY" \
-H "Content-Type: application/json" \
-d '{
"team_id": "<team id>",
"metadata": {
"pishtaq_secrets": {
"direct": "mask",
"agent": "block",
"allow": ["SECRET_JWT", "generic-api-key"]
}
}
}'

/team/update replaces the whole metadata object of the team with the one you send. Keys that you leave out are removed, except a few that Pishtaq manages itself. To keep the team's other metadata, read it first with GET /team/info?team_id=<team id>. The response holds the team under team_info, so the metadata to keep is team_info.metadata. Add pishtaq_secrets to that object and send all of it as metadata.

  • direct and agent each take block or mask.
  • allow takes a list of kinds from the table above, or gitleaks rule ids such as generic-api-key. The two Pishtaq rules are pishtaq-connection-string and pishtaq-password-word. A secret that matches an allowed entry is passed through unchanged.

An invalid setting, including an unknown key, is ignored and the defaults apply. Pishtaq writes a warning to the log.

Only a proxy admin can add, change, or remove pishtaq_secrets. Team admins, organization admins, and key owners get a 403 if they try, through the admin UI or the API. Pishtaq reads the setting from the team of the key that made the request, never from the request body, so a caller cannot send their own policy. The same rule covers opted_out_global_guardrails on keys and teams, since it can turn masking off altogether. Every metadata key Pishtaq reads is listed in pishtaq_ee/metadata.py, and core protects each key listed there.

A policy pipeline always starts with Pishtaq masking, even when the policy lists it later or leaves it out, so every guardrail in the pipeline sees masked text. A pipeline cannot soften it either: masking blocks the request on any failure or error, whatever the pipeline says, and the policy's own steps decide the rest.

A request can name policies to apply (policies in the request body) only if it comes from a proxy admin, or from a team whose metadata sets guardrails.modify_guardrails to true. Anyone else gets a 403, so a caller cannot apply another team's policy.

Security events​

Every block or mask writes a pishtaq_security_event line to the log. It is a JSON object with these fields:

  • kind
  • action, either blocked or masked
  • traffic, either agent or direct
  • team_id
  • key_alias
  • endpoint
  • count, the number of secrets of that kind in the request
  • litellm_call_id

The line never contains the secret itself.

Alerts by email and Telegram for these events are not part of this version. Today the events reach you through the log only.