vendor-sdk-response-hygiene-v1
18 rules · Keryn Software Licence · rules 0.8.0 · all packs
How to read a rule
- Severity
- How bad the finding is if it is real:
errorfails a default gate,warningandinfodo not. - Confidence
- P0 exploitable as written; P1 dangerous in context; P2 a heuristic or a posture check: confirm by reading the code.
- False-positive risk
- low: an exact API or flag, so hits are almost always real; medium: the pattern is legitimate in many programs, so check each hit; high: it finds a lead to confirm, so expect benign hits.
- Edge
- The relationship the finding sits on. reaches: content or traffic gets to a thing; calls: one thing invokes another; reads: one thing reads from another; writes: one thing writes to another; sends: data leaves for another party; grants: authority is given or left unchecked; depends_on: something relies on a component it does not verify; trusts: one party believes another without evidence. The boundary it crosses, when there is one: user->prompt (untrusted input reaching a prompt); model->code (model output reaching code, a shell, a query or a page); secret->outside (a secret leaving the trusted side); supply-chain (code, models or prompts pulled in from outside).
- Taxonomy chips
- References for readers who work in OWASP LLM 2025, OWASP Agentic, CWE or NIST AI RMF. They say where a rule belongs, not that a framework is satisfied.
keryn.vendor.anthropic-content-read-without-stop-reason-check-py
Section titled “keryn.vendor.anthropic-content-read-without-stop-reason-check-py”warning python anthropic
The text of an Anthropic Messages response is read without looking at stop_reason. The API reports “max_tokens” (truncated), “refusal” (declined for safety) and “pause_turn” (server tool loop interrupted) through that field while content still holds partial text, so the caller treats an incomplete or refused answer as a complete one. Branch on response.stop_reason before using response.content.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reads one thing reads from another.
Fix: After every messages.create call read response.stop_reason: retry or continue on “max_tokens”, surface a safe fallback on “refusal”, resume the turn on “pause_turn”, and only then read the content blocks.
References: https://platform.claude.com/docs/en/api/messages · https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons
keryn.vendor.anthropic-content-read-without-stop-reason-check-js
Section titled “keryn.vendor.anthropic-content-read-without-stop-reason-check-js”warning javascript, typescript anthropic
The text of an Anthropic Messages response is read without looking at stop_reason. The API reports “max_tokens” (truncated), “refusal” (declined for safety) and “pause_turn” (server tool loop interrupted) through that field while content still holds partial text, so the caller treats an incomplete or refused answer as a complete one. Branch on response.stop_reason before using response.content.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reads one thing reads from another.
Fix: After every messages.create call read response.stop_reason: retry or continue on “max_tokens”, surface a safe fallback on “refusal”, resume the turn on “pause_turn”, and only then read the content blocks.
References: https://platform.claude.com/docs/en/api/messages · https://platform.claude.com/docs/en/build-with-claude/handling-stop-reasons
keryn.vendor.openai-content-read-without-refusal-check-py
Section titled “keryn.vendor.openai-content-read-without-refusal-check-py”warning python openai
An OpenAI chat completion’s message.content is read without checking message.refusal or finish_reason. With structured outputs the model can return a refusal with content null, and finish_reason “length” or “content_filter” marks a cut or filtered answer; the caller then parses None or a partial string as the real reply. Check choices[0].message.refusal and choices[0].finish_reason first.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reads one thing reads from another.
Fix: Read choices[0].message.refusal and choices[0].finish_reason before content: return a safe fallback on a refusal, retry with a larger budget or report truncation on “length”, and treat “content_filter” as no answer.
References: https://developers.openai.com/api/docs/guides/structured-outputs#refusals · https://developers.openai.com/api/reference/resources/chat
keryn.vendor.openai-content-read-without-refusal-check-js
Section titled “keryn.vendor.openai-content-read-without-refusal-check-js”warning javascript, typescript openai
An OpenAI chat completion’s message.content is read without checking message.refusal or finish_reason. With structured outputs the model can return a refusal with content null, and finish_reason “length” or “content_filter” marks a cut or filtered answer; the caller then parses null or a partial string as the real reply. Check choices[0].message.refusal and choices[0].finish_reason first.
Confidence P1: dangerous in context. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: reads one thing reads from another.
Fix: Read choices[0].message.refusal and choices[0].finish_reason before content: return a safe fallback on a refusal, retry with a larger budget or report truncation on “length”, and treat “content_filter” as no answer.
References: https://developers.openai.com/api/docs/guides/structured-outputs#refusals · https://developers.openai.com/api/reference/resources/chat
keryn.vendor.anthropic-messages-without-metadata-user-id-py
Section titled “keryn.vendor.anthropic-messages-without-metadata-user-id-py”info python anthropic
messages.create is called without the metadata parameter, so Anthropic cannot attribute this traffic to an end user. The metadata.user_id field (an opaque, non-identifying id such as a hash) is how abuse by one of your users is isolated from your whole account; without it a single abuser can get the account’s access restricted. Pass metadata={“user_id”: <hashed id>}.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: grants authority is given or left unchecked.
Fix: Add metadata={“user_id”: <stable hashed or UUID identifier of the end user>} to every messages.create call that serves end users; never put an email, name or phone number in the field.
References: https://platform.claude.com/docs/en/api/messages
keryn.vendor.anthropic-messages-without-metadata-user-id-js
Section titled “keryn.vendor.anthropic-messages-without-metadata-user-id-js”info javascript, typescript anthropic
messages.create is called without the metadata parameter, so Anthropic cannot attribute this traffic to an end user. The metadata.user_id field (an opaque, non-identifying id such as a hash) is how abuse by one of your users is isolated from your whole account; without it a single abuser can get the account’s access restricted. Pass metadata: { user_id: <hashed id> }.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: grants authority is given or left unchecked.
Fix: Add metadata: { user_id: <stable hashed or UUID identifier of the end user> } to every messages.create call that serves end users; never put an email, name or phone number in the field.
References: https://platform.claude.com/docs/en/api/messages
keryn.vendor.openai-chat-without-user-identifier-py
Section titled “keryn.vendor.openai-chat-without-user-identifier-py”info python openai
The OpenAI call carries neither a user nor a safety_identifier parameter, so OpenAI cannot tell your end users apart. Those fields are what lets the platform act on one abusive end user instead of your whole organisation when policy-violating prompts arrive. Pass safety_identifier (or user on older endpoints) with a hashed end-user id.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: grants authority is given or left unchecked.
Fix: Pass safety_identifier=<hashed end-user id> on responses.create and chat.completions.create (user=<hashed id> on endpoints that predate safety_identifier). Hash or tokenise the id; do not send names or emails.
References: https://developers.openai.com/api/docs/guides/safety-best-practices · https://developers.openai.com/api/reference/resources/responses/methods/create
keryn.vendor.openai-chat-without-user-identifier-js
Section titled “keryn.vendor.openai-chat-without-user-identifier-js”info javascript, typescript openai
The OpenAI call carries neither a user nor a safety_identifier parameter, so OpenAI cannot tell your end users apart. Those fields are what lets the platform act on one abusive end user instead of your whole organisation when policy-violating prompts arrive. Pass safety_identifier (or user on older endpoints) with a hashed end-user id.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: grants authority is given or left unchecked.
Fix: Pass safety_identifier: <hashed end-user id> on responses.create and chat.completions.create (user: <hashed id> on endpoints that predate safety_identifier). Hash or tokenise the id; do not send names or emails.
References: https://developers.openai.com/api/docs/guides/safety-best-practices · https://developers.openai.com/api/reference/resources/responses/methods/create
keryn.vendor.gemini-generate-content-without-safety-settings-py
Section titled “keryn.vendor.gemini-generate-content-without-safety-settings-py”info python gemini, google-genai
Gemini content is generated without explicit safety_settings. The default harm-block thresholds differ between model generations (newer models block nothing by default), so the filtering this code gets depends on the model string rather than on a decision in the code. Set safety_settings with an explicit threshold per harm category.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: trusts one party believes another without evidence.
Fix: Pass config=types.GenerateContentConfig(safety_settings=[types.SafetySetting(category=…, threshold=…)]) (or safety_settings= on GenerativeModel in the legacy SDK) with a threshold chosen per harm category, and keep that list in one shared place so every call uses it.
References: https://ai.google.dev/gemini-api/docs/safety-settings
keryn.vendor.gemini-generate-content-without-safety-settings-js
Section titled “keryn.vendor.gemini-generate-content-without-safety-settings-js”info javascript, typescript gemini, google-genai
Gemini content is generated without explicit safetySettings. The default harm-block thresholds differ between model generations (newer models block nothing by default), so the filtering this code gets depends on the model string rather than on a decision in the code. Set safetySettings with an explicit threshold per harm category.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: trusts one party believes another without evidence.
Fix: Pass config: { safetySettings: [{ category, threshold }] } to generateContent (or safetySettings on getGenerativeModel in the legacy SDK) with a threshold chosen per harm category, and keep that list in one shared place so every call uses it.
References: https://ai.google.dev/gemini-api/docs/safety-settings
keryn.vendor.cohere-chat-safety-mode-off-py
Section titled “keryn.vendor.cohere-chat-safety-mode-off-py”warning python cohere
Cohere chat is called with safety_mode=“OFF”, which switches off the model’s built-in safety behaviour for every request through this call. Use “CONTEXTUAL” (default for most models) or “STRICT” unless the product has its own content controls in front of the model.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: trusts one party believes another without evidence.
Fix: Remove safety_mode=“OFF” or set it to “CONTEXTUAL” or “STRICT”; if OFF is needed for a specific internal use, isolate that call path and document the compensating control.
References: https://docs.cohere.com/docs/safety-modes
keryn.vendor.cohere-chat-safety-mode-off-js
Section titled “keryn.vendor.cohere-chat-safety-mode-off-js”warning javascript, typescript cohere
Cohere chat is called with safetyMode “OFF”, which switches off the model’s built-in safety behaviour for every request through this call. Use “CONTEXTUAL” (default for most models) or “STRICT” unless the product has its own content controls in front of the model.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: trusts one party believes another without evidence.
Fix: Remove safetyMode “OFF” or set it to “CONTEXTUAL” or “STRICT”; if OFF is needed for a specific internal use, isolate that call path and document the compensating control.
References: https://docs.cohere.com/docs/safety-modes
keryn.vendor.cohere-chat-without-safety-mode-py
Section titled “keryn.vendor.cohere-chat-without-safety-mode-py”info python cohere
Cohere chat is called without a safety_mode, so the request inherits whatever the model’s default mode is. The default differs by model family and is not visible in this code; set safety_mode explicitly (“CONTEXTUAL” or “STRICT”) so the behaviour is decided here.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: trusts one party believes another without evidence.
Fix: Pass safety_mode=“CONTEXTUAL” (or “STRICT” for consumer-facing surfaces) on every chat and chat_stream call, ideally from one shared client wrapper.
References: https://docs.cohere.com/docs/safety-modes
keryn.vendor.cohere-chat-without-safety-mode-js
Section titled “keryn.vendor.cohere-chat-without-safety-mode-js”info javascript, typescript cohere
Cohere chat is called without a safetyMode, so the request inherits whatever the model’s default mode is. The default differs by model family and is not visible in this code; set safetyMode explicitly (“CONTEXTUAL” or “STRICT”) so the behaviour is decided here.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: trusts one party believes another without evidence.
Fix: Pass safetyMode: “CONTEXTUAL” (or “STRICT” for consumer-facing surfaces) on every chat and chatStream call, ideally from one shared client wrapper.
References: https://docs.cohere.com/docs/safety-modes
keryn.vendor.mistral-chat-safe-prompt-disabled-py
Section titled “keryn.vendor.mistral-chat-safe-prompt-disabled-py”warning python mistral
Mistral chat is called with safe_prompt=False, explicitly declining the guardrail system prompt Mistral prepends when safe_prompt is on. Every request through this call runs without that layer. Enable safe_prompt=True, or document the compensating control if this is a deliberate internal use.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: trusts one party believes another without evidence.
Fix: Set safe_prompt=True on chat.complete / chat.stream, or remove the parameter and set it once in a shared client wrapper.
References: https://docs.mistral.ai/studio/safety-moderation
keryn.vendor.mistral-chat-safe-prompt-disabled-js
Section titled “keryn.vendor.mistral-chat-safe-prompt-disabled-js”warning javascript, typescript mistral
Mistral chat is called with safePrompt false, explicitly declining the guardrail system prompt Mistral prepends when safePrompt is on. Every request through this call runs without that layer. Enable safePrompt true, or document the compensating control if this is a deliberate internal use.
Confidence P1: dangerous in context. False-positive risk low: an exact API or flag, so hits are almost always real.
Edge inspected: trusts one party believes another without evidence.
Fix: Set safePrompt: true on chat.complete / chat.stream, or remove the parameter and set it once in a shared client wrapper.
References: https://docs.mistral.ai/studio/safety-moderation
keryn.vendor.mistral-chat-without-safe-prompt-py
Section titled “keryn.vendor.mistral-chat-without-safe-prompt-py”info python mistral
Mistral chat is called without safe_prompt, which defaults to off: the guardrail system prompt is not applied. Decide it in code by passing safe_prompt=True on consumer-facing paths.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: trusts one party believes another without evidence.
Fix: Pass safe_prompt=True on chat.complete / chat.stream for user-facing traffic, ideally from one shared client wrapper so no call site forgets it.
References: https://docs.mistral.ai/studio/safety-moderation
keryn.vendor.mistral-chat-without-safe-prompt-js
Section titled “keryn.vendor.mistral-chat-without-safe-prompt-js”info javascript, typescript mistral
Mistral chat is called without safePrompt, which defaults to off: the guardrail system prompt is not applied. Decide it in code by passing safePrompt: true on consumer-facing paths.
Confidence P2: a heuristic or a posture check: confirm by reading the code. False-positive risk medium: the pattern is legitimate in many programs, so check each hit.
Edge inspected: trusts one party believes another without evidence.
Fix: Pass safePrompt: true on chat.complete / chat.stream for user-facing traffic, ideally from one shared client wrapper so no call site forgets it.
References: https://docs.mistral.ai/studio/safety-moderation