fix(a2a): add type validation for email extraction in list_agents_for_user#4699
Open
bogdanmariusc10 wants to merge 4 commits into
Conversation
…_user Root cause fix for issue #4670. The deprecated list_agents_for_user() method was extracting email from user_info dict without validating it was a string. If the 'email' key contained a nested dict or other object, it would be passed directly to SQL queries, causing: Error binding parameter 1: type 'dict' is not supported This fix adds type validation immediately after email extraction, logging a warning and using empty string (public-only access) if a non-string is detected. This complements the defensive fix in PR #4637 which added validation at the get_rpc_filter_context() level. Both layers of validation follow defense-in-depth security principles. Closes #4670 Signed-off-by: Bogdan-Marius-Catanus <[email protected]>
1 task
Signed-off-by: Bogdan-Marius-Catanus <[email protected]>
added 2 commits
May 11, 2026 14:18
Signed-off-by: Bogdan-Marius-Catanus <[email protected]>
Signed-off-by: Bogdan-Marius-Catanus <[email protected]>
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.
🔗 Related Issue
Closes #4670
📝 Summary
Root Cause Fix: Adds type validation for email extraction in the deprecated
list_agents_for_user()method to prevent passing dict objects to SQL queries.Problem: The method was extracting email from
user_infodict without validating it was a string. When the"email"key contained a nested dict or other object, it was passed directly to SQL queries, causing:Solution: Added type validation immediately after email extraction (lines 1118-1126). If a non-string is detected:
Defense-in-Depth: This fix complements the defensive validation added in PR #4637 at the
get_rpc_filter_context()level. Both layers follow security best practices.Why Other Code Paths Are Safe:
user_email: strparameters, not dictsget_user_email()helper already has proper type validationget_current_user_with_permissions()🏷️ Type of Change
🧪 Verification
make lintmake testmake coverage✅ Checklist
make black isort pre-commit)📓 Notes
Investigation Methodology:
TeamManagementService.get_user_teams()back through call chainget_user_teams()across the codebase.get("email")patternslist_agents_for_user()as the only vulnerable code pathCode Change (lines 1118-1126):
Security Consideration: Setting
user_emailto empty string when type validation fails results in public-only access, which is the secure default per the two-layer security model documented inAGENTS.md.Test Coverage: PR #4637 added comprehensive test coverage for the symptom at the
get_rpc_filter_context()level. This root cause fix ensures those tests continue to pass, but warning logs should not fire in normal operation since the issue is now prevented at the source.Added tests for type validation logic:
/tests/unit/mcpgateway/services/test_a2a_service.py::TestListAgentsForUserTypeValidation