litellm/.semgrep/rules
ryan-crabbe-berri 509ef61103 refactor(proxy): ban raw datetime.fromisoformat via parse_utc_datetime helper
Extract parse_utc_datetime into litellm_core_utils/datetime_utils.py as the
single ISO-8601 parse entrypoint for the proxy: it accepts str or datetime,
handles the Z suffix on Python 3.10, and assumes naive values are UTC so
results always compare safely against datetime.now(timezone.utc).

Convert all 27 raw fromisoformat sites under litellm/proxy/ to the helper,
collapsing the hand-rolled tzinfo guards they each carried. This also fixes a
real bug in get_mcp_oauth_user_credential_status: a tz-naive expires_at raised
TypeError against the aware now(), the bare except swallowed it, and the
credential never read as expired.

Two semgrep rules enforce the pattern in CI: raw fromisoformat is banned under
litellm/proxy/, and a repo-wide taint rule flags comparing or subtracting an
unnormalized fromisoformat result.
2026-07-21 11:26:49 -07:00
..
python refactor(proxy): ban raw datetime.fromisoformat via parse_utc_datetime helper 2026-07-21 11:26:49 -07:00
security security: remove .claude/settings.json and add semgrep rule to prevent re-adding 2026-03-25 11:57:43 -07:00
README.md chore: improve Semgrep rules documentation and organization (#20978) 2026-02-11 09:39:44 -08:00

Custom Semgrep rules for LiteLLM

Add custom rule YAML files here. Semgrep loads all .yml/.yaml files under this directory.

Run only custom rules (CI / fail on findings):

semgrep scan --config .semgrep/rules . --error

Run with registry + custom rules:

semgrep scan --config auto --config .semgrep/rules .

Layout:

  • python/ – Python-specific rules (security, patterns)
  • Add more subdirs as needed (e.g. generic/ for language-agnostic rules)

See Semgrep rule syntax.