Security hardening: logging, cost protection, SSRF, model validation#248
Merged
neuromechanist merged 3 commits intodevelopfrom Mar 4, 2026
Merged
Conversation
- Wire up SecureFormatter in app startup (#65): call configure_secure_logging() before any logging occurs - Add cost manipulation protection (#67): block models above $15/1M input tokens on platform/community keys, warn above $5/1M; BYOK users unrestricted - Verified SSRF protection (#66) and model validation (#68) already have comprehensive test coverage Closes #65, closes #66, closes #67, closes #68
- Fix misleading "fallback rate" comment in _check_model_cost - Add logging for unknown models (operator visibility) - Extract _models_by_cost() test helper to reduce duplication - Add boundary test at exact block threshold - Add BYOK + unknown model test - Assert BYOK guidance in error message - Fix module docstring wording
Split the catch-all Exception handler into specific expected errors (ValueError, TypeError, KeyError) that include context for debugging, and unexpected errors that re-raise after printing to stderr. Matches the pattern already used in SecureFormatter.format().
Member
Author
PR Review FindingsRan comprehensive review with 5 agents (code-reviewer, silent-failure-hunter, pr-test-analyzer, comment-analyzer, code-simplifier). All findings addressed in follow-up commits. Critical (1 found, fixed)
Important (3 found, fixed)
Suggestions (5 found, 4 addressed)
|
This was referenced Mar 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Addresses four security issues:
configure_secure_logging()in app startup (src/api/main.py) soSecureFormatteris active before any logging occurs. The formatter and tests already existed but were never called.validate_source_url()inDocSourcewith comprehensive test coverage (localhost, private IPs, AWS metadata, non-HTTP schemes). No gaps found._check_model_cost()guard increate_community_assistant()that blocks models above $15/1M input tokens on platform/community keys (HTTP 403), warns above $5/1M. BYOK users are unrestricted. Unknown models are allowed._validate_model_id()with pattern+length validation and comprehensive tests. No gaps found.Closes #65, closes #66, closes #67, closes #68
Test plan
uv run pytest tests/test_api/test_cost_protection.py -v-- 6 passed, 1 skipped (no models between warn/block thresholds)uv run pytest tests/test_core/test_config/test_community.py -v-- SSRF + model validation tests passuv run ruff check . && uv run ruff format --check .-- clean