Repository navigation
fix(backend): validate inputs and add resilience guards in database mcp api key ( proposed) - #19816
Alphaxiaoteng wants to merge 1 commit into
Conversation
|
Thanks @Alphaxiaoteng — solid, well-tested hardening of the MCP API-key module. What I verified (isolated worktree at your head 527d3b1):
Two non-blocking notes:
One heads-up: this module is the MCP API-key validation/revocation surface, so it needs a maintainer sign-off on the auth-path behavior before merge. The bounty proposal in the description is a maintainer decision, not something this review can rule on. by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with |
|
Hi @Git-on-my-level need human response Thanks for the thorough review and validation (43/43 new tests + 6/6 existing auth-context tests passing, black-clean). Re your non-blocking note on Two asks for a human maintainer:
Settlement details are already on the linked bounty issue. Appreciate the quick turnaround so far. |
|
@Alphaxiaoteng this conflicts with |
|
Hey @Alphaxiaoteng 👋 Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request. After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:
Before your next PR, please skim:
If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing. Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out. Thank you for being part of the Omi community! |
Summary
Hardens
backend/database/mcp_api_key.pyagainst path traversal, empty input allocations, and unexpected type crashes:• Input Sanitization & Path Traversal Guard:
• Adds
_clean_user_id(user_id)rejecting empty strings, non-string types, and path traversal characters (/,\\,..), protecting Firestore user document collections.• Adds
_clean_key_name(name)validating non-empty names, normalizing whitespace, capping length at 255 characters, and guarding against raw token leakage.• Early Validation & Fast Fail-Safe:
• In
get_mcp_keys_for_user_with_repair_info(), malformed or empty user IDs return fast([], frozenset())without issuing unnecessary remote Firestore stream queries.• In
delete_mcp_key(), invalid or malformed user IDs and key IDs no-op cleanly rather than provoking Firestore document path traversal errors.• In
get_api_key_auth_result(), validates thatapi_keyis a string before calling.startswith(), preventingAttributeErrorcrashes on non-string inputs.• Hermetic Unit Tests:
• Added 43 comprehensive unit tests in
backend/tests/unit/test_mcp_api_key_resilience.pycovering valid paths, invalid types, traversal attacks, length boundaries, and mock database operations (100% pass in 0.78s).Failure-Class: none
Proposed Bounty
• Suggested reward: $50
• Contributor payout: PayPal
chenpaiteng@gmail.comVerification
•
pytest backend/tests/unit/test_mcp_api_key_resilience.py(43 passed in 0.78s)•
pytest backend/tests/unit/test_mcp_api_key_auth_context.py(6 passed in 1.15s)•
black --line-length 120 --skip-string-normalization backend/database/mcp_api_key.py backend/tests/unit/test_mcp_api_key_resilience.py(clean)