Harden JWT secret handling and replace eval() in examples

fix: harden JWT secret handling and replace eval() in examples (#1793)
Harden JWT secret handling and replace eval() in examplese0fb8e-fix-harden-jwt-secret-handling-and-replace-cve-2026-47391fixharden jwt secret handling replace eval

Committed by ulsreall

commit message
fix: harden JWT secret handling and replace eval() in examples (#1793)

Addresses remaining attack surface from security advisories:
 
GHSA-3qg8-5g3r-79v5 (JWT signing key - CRITICAL):
  auth_service.py: PLATFORM_ENV no longer defaults to 'dev' when unset.
  When PLATFORM_JWT_SECRET is not set and PLATFORM_ENV is not explicitly
  'dev', an ephemeral random secret is auto-generated with a warning.
  This prevents production deployments from silently using the well-known
  'dev-secret-change-me' key.
 
GHSA-vg22-4gmj-prxw (unauthenticated eval - CRITICAL):
  Replaced all eval() calls in official examples and benchmarks with an
  AST-based safe math evaluator that only allows numeric literals and
  arithmetic operators. Files fixed:
  - examples/python/a2a/a2a-server.py (the primary advisory target)
  - examples/mcp/multi_server.py
  - examples/python/mcp/mcp-tools-server.py
  - examples/python/mcp/mcp-tools-server-sse.py
  - examples/mcp_server/custom_tools_server.py
  - examples/python/mcp_server_example.py
  - examples/python/custom_tools/tools_with_latency.py
  - examples/eval/reliability_example.py
  - src/praisonai-agents/benchmarks/real_benchmark.py
 
The character-filter approach (allowlist '0123456789+-*/.()') was
insufficient because () enables attribute access chains. AST-based
evaluation only permits numeric literals and binary/unary arithmetic.
 
GHSA-hvhp-v2gc-268q and GHSA-9cr9-25q5-8prj (file read/write):
  Already fixed in prior commits via _resolve_rule_path() and
  _resolve_cwd_yaml_path() containment helpers.
 
Co-authored-by: ulsreall <[email protected]>

Editor assessment

This commit patches CVE-2026-57147 and CVE-2026-57148. The body is genuinely strong: it maps each advisory to the code change, explains the JWT default-secret fix, and justifies the AST evaluator by showing why the character allowlist was insufficient. The subject is clean and the type fits. What it lacks is a scope and a one-paragraph summary at the top, so a reader must parse a long advisory-by-advisory body. Adding those two elements would make it exemplary. The nine-file list is useful evidence; a short index of which advisories map to which files would make the body navigable.

Browse categories

More fix examples · Back to search