Skip to content

fix: comprehensive framework security audit and hardening#29

Merged
ancongui merged 1 commit into
mainfrom
develop
Feb 21, 2026
Merged

fix: comprehensive framework security audit and hardening#29
ancongui merged 1 commit into
mainfrom
develop

Conversation

@ancongui
Copy link
Copy Markdown
Contributor

Summary

  • Full security audit and hardening across 16 framework modules (42 files, 42 findings fixed)
  • Eliminates command injection, path traversal, timing attacks, ReDoS, SQL injection, CORS misconfig, and internal error exposure
  • Adds thread safety to 4 previously unprotected concurrent data structures
  • Fixes middleware protocol conformance, reasoning registry auto-registration, pipeline engine correctness, asyncio.run crashes in async contexts, and queue consumer resilience
  • Adds 15+ missing public API exports
  • Updates CHANGELOG, security docs, and tools docs

Test plan

  • All 1,273 tests pass (pytest tests/ -q — 0 failures)
  • Frontend builds cleanly (npm run build — 0 errors)
  • No regressions in existing functionality

Address 42 findings across 16 modules from a full framework audit covering
security, thread safety, correctness, and API completeness.

Security:
- ShellTool: create_subprocess_exec instead of create_subprocess_shell
- FileSystemTool/FileStore: Path.is_relative_to() for path traversal
- CORS: disable credentials with wildcard origins
- Auth: hmac.compare_digest for timing-safe comparison
- PostgreSQLStore: schema name SQL injection validation
- RBAC: no closure mutation, positional args via inspect.signature
- REST: generic error messages, no internal detail exposure
- TextTool: 5s timeout for user-supplied regex (ReDoS protection)
- Encryption: random per-call salt via os.urandom(16)

Thread safety:
- Added threading.Lock to CachedTool, RateLimitGuard, InMemoryStore,
  ConversationMemory (6 previously unprotected methods)

Correctness:
- PromptCacheMiddleware/CircuitBreakerMiddleware: before/after renamed
  to before_run/after_run to match AgentMiddleware protocol
- CircuitBreakerMiddleware: added on_error hook for failure recording
- Reasoning registry: auto-registers 6 built-in patterns at import
- Pipeline engine: _gather_inputs respects output_key, started_at init
- asyncio.run crashes: ThreadPoolExecutor fallback in database stores
- Queue consumers: try/except per message prevents crash on bad input
- Content chunking: fixed source position and offset tracking
- Compression: O(1) eviction with deque + running token count
- Prompt template: sentinel value allows None as legitimate default
- LogRecord: copy before mutation prevents handler corruption
- ConversationMemory: clear/clear_all now remove stale summaries
- MemoryError renamed to FireflyMemoryError (deprecated alias kept)

API completeness:
- Added BatchLLMStep, RetryMiddleware, PromptCacheMiddleware,
  CacheStatistics, FireflyMemoryError, QuotaManager, RateLimiter,
  OutputGuard, PromptGuard, and trace functions to public exports

Docs:
- CHANGELOG.md: documented all changes under [Unreleased]
- docs/security.md: updated encryption section for random salt
- docs/tools.md: updated ShellTool description
@ancongui ancongui enabled auto-merge February 21, 2026 23:41

if loop is not None:
# Already inside an event loop -- offload to a background thread.
import concurrent.futures
@ancongui ancongui merged commit 85d2037 into main Feb 21, 2026
23 of 28 checks passed
ancongui added a commit that referenced this pull request May 31, 2026
fix: comprehensive framework security audit and hardening
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant