Skip to content

Commit 88502e5

Browse files
committed
bump: adds new semgrep rules
1 parent 7cb05d0 commit 88502e5

File tree

1 file changed

+85
-0
lines changed

1 file changed

+85
-0
lines changed

plugins/tools/semgrep/embedded/rules.yaml

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113519,4 +113519,89 @@ rules:
113519113519
category: security
113520113520
impact: MEDIUM
113521113521
confidence: LOW
113522+
- id: codacy.python.openai.non-guardrails-direct-call
113523+
message: "Direct OpenAI SDK call detected. Use Guardrails client (GuardrailsOpenAI/GuardrailsAsyncOpenAI) instead."
113524+
severity: WARNING
113525+
languages: [python]
113526+
metadata:
113527+
category: security
113528+
cwe: "CWE-20: Improper Input Validation"
113529+
references:
113530+
- https://openai.github.io/openai-guardrails-python/
113531+
justification: >
113532+
Guardrails is a drop-in replacement that automatically validates inputs/outputs.
113533+
Prefer Guardrails clients over raw openai.* calls.
113534+
confidence: MEDIUM
113535+
patterns:
113536+
- pattern-either:
113537+
- pattern: openai.ChatCompletion.create(...)
113538+
- pattern: openai.Completion.create(...)
113539+
- pattern: openai.chat.completions.create(...)
113540+
- pattern: openai.responses.create(...)
113541+
- pattern: openai.embeddings.create(...)
113542+
- pattern: openai.images.generate(...)
113543+
- pattern: openai.audio.transcriptions.create(...)
113544+
- pattern: openai.audio.speech.create(...)
113545+
- id: codacy.python.openai.non-guardrails-client-usage
113546+
message: "OpenAI client used without Guardrails. Replace with GuardrailsOpenAI / GuardrailsAsyncOpenAI."
113547+
severity: WARNING
113548+
languages: [python]
113549+
metadata:
113550+
category: security
113551+
cwe: "CWE-20: Improper Input Validation"
113552+
references:
113553+
- https://openai.github.io/openai-guardrails-python/
113554+
justification: >
113555+
Guardrails advises using GuardrailsOpenAI/GuardrailsAsyncOpenAI as a drop-in replacement
113556+
so validation runs automatically on every API call.
113557+
confidence: MEDIUM
113558+
# Catch typical client flows while avoiding false hits when the client *is* a Guardrails client.
113559+
patterns:
113560+
- pattern-either:
113561+
# Synchronous client patterns
113562+
- pattern: |
113563+
$C = OpenAI(...)
113564+
...
113565+
$C.chat.completions.create(...)
113566+
- pattern: |
113567+
$C = OpenAI(...)
113568+
...
113569+
$C.responses.create(...)
113570+
- pattern: |
113571+
$C = OpenAI(...)
113572+
...
113573+
$C.embeddings.create(...)
113574+
# Async client patterns
113575+
- pattern: |
113576+
$C = AsyncOpenAI(...)
113577+
...
113578+
$C.chat.completions.create(...)
113579+
- pattern: |
113580+
$C = AsyncOpenAI(...)
113581+
...
113582+
$C.responses.create(...)
113583+
- pattern: |
113584+
$C = AsyncOpenAI(...)
113585+
...
113586+
$C.embeddings.create(...)
113587+
- pattern-not: |
113588+
$C = GuardrailsOpenAI(...)
113589+
- pattern-not: |
113590+
$C = GuardrailsAsyncOpenAI(...)
113591+
- id: codacy.python.openai.import-without-guardrails
113592+
message: "OpenAI SDK imported without Guardrails import. Consider GuardrailsOpenAI / GuardrailsAsyncOpenAI."
113593+
severity: INFO
113594+
languages: [python]
113595+
metadata:
113596+
category: security
113597+
references:
113598+
- https://openai.github.io/openai-guardrails-python/
113599+
confidence: MEDIUM
113600+
# Soft signal: import present but no Guardrails import in same file.
113601+
# This is informational to help teams spot likely non-guardrailed files early.
113602+
pattern: |
113603+
import openai
113604+
pattern-not: |
113605+
from guardrails import GuardrailsOpenAI |
113606+
from guardrails import GuardrailsAsyncOpenAI
113522113607

0 commit comments

Comments
 (0)