Agentify Info
Agentify empowers AI agents to interact, adapt, and automate Web3 tasks using the Model Context Protocol (MCP). From DeFi to cross-chain operations, deploy agents that evolve and monetize as they work.
TrustNet Score
The TrustNet Score evaluates crypto projects based on audit results, security, KYC verification, and social media presence. This score offers a quick, transparent view of a project's credibility, helping users make informed decisions in the Web3 space.
Real-Time Threat Detection
Real-time threat detection, powered by Cyvers.io,
is currently not
activated
for this project.
This advanced feature provides continuous monitoring and instant alerts to safeguard your assets from potential security threats. Real-time detection enhances your project's security by proactively identifying and mitigating risks.
For more information, click here.
Security Assessments
Summary and Final Words
No crucial issues found
The contract does not contain issues of high or medium criticality. This means that no known vulnerabilities were found in the source code.
Contract is upgradeable
The contract uses a proxy pattern or similar mechanism, enabling future upgrades. This can introduce risks if the upgrade mechanism is not securely managed.
Scope of Work
This audit encompasses the evaluation of the files listed below, each verified with a SHA-1 Hash. The team referenced above has provided the necessary files for assessment.
The auditing process consists of the following systematic steps:
- Specification Review: Analyze the provided specifications, route documentation, and architectural context to fully understand the backend system's purpose, data flows, and API surface area.
- Manual Code Examination: Conduct a thorough, line-by-line review of the backend source code to identify security risks, access control weaknesses, logic flaws, and maintainability issues.
- Specification Alignment: Ensure that the implemented logic aligns with the intended specifications, particularly for critical operations such as authentication, authorization, data updates, and user-based access.
- Test Coverage Assessment: Review the presence and depth of test coverage (unit and integration), focusing on critical modules such as authentication, transaction processing, and user data handling.
- Configuration & Security Review: Examine configuration files, middleware, and startup logic to verify secure settings, proper environment variable usage, and safe third-party integrations (e.g., CORS, secrets, cookies, JWT).
- Best Practices Evaluation: Assess the codebase against established backend security and engineering best practices, including RBAC enforcement, input validation via Pydantic, structured error handling, and clean logging.
- Actionable Recommendations: Provide specific and prioritized recommendations to improve the backend’s security, reliability, and maintainability, with a focus on remediation of critical and high-severity findings.
A file with a different Hash has been intentionally or otherwise modified after the security review. A different Hash may indicate a changed condition or potential vulnerability that was not within the scope of this review.
Final Words
The following provides a concise summary of the audit report, accompanied by insightful comments from the auditor. This overview captures the key findings and observations, offering valuable context and clarity.
This security audit of the Agentify-AI backend codebase focused on evaluating the FastAPI-based application for vulnerabilities in access control, configuration, input validation, logging, and data handling. The goal was to identify risks that could impact data confidentiality, integrity, or system reliability and to ensure that the application meets production-grade security expectations.
The backend is modular and logically organized, but the audit uncovered multiple security and maintainability issues. Most issues have been successfully addressed, with only three remaining items requiring attention before production deployment.
Technical Summary
- Authorization & Access Control: Critical progress has been made in user endpoint security. Most user operations now include proper ownership validation. However, POST /users/ still allows arbitrary user_id creation and GET /users/ exposes all user data to any authenticated user without role restrictions. STATUS: PARTIALLY RESOLVED
- Input Validation: Routes handling agent creation and updates have been updated to use proper Pydantic models instead of accepting raw
dictobjects, eliminating the risk of malformed or malicious payloads. STATUS: RESOLVED - Authentication Integration: User preference endpoints have been secured to derive user identity from JWT tokens rather than accepting manipulatable
user_idparameters. Transaction retrieval now properly validates user authorization. STATUS: RESOLVED - Secrets & Configuration Management: Hardcoded sensitive data including JWT verification keys and API cookies have been externalized to environment variables, improving security and deployment flexibility. STATUS: RESOLVED
- Endpoint Exposure & CORS Policy: CORS configuration has been restricted from permissive wildcard settings to trusted domains. However, the /api/v1/agents/list-agents/ endpoint remains unauthenticated due to EXCLUDED_PATHS configuration, potentially exposing agent metadata. STATUS: PARTIALLY RESOLVED
- Runtime Logic & Agent Loading: Agent loading has been optimized with primary loading occurring at startup. Fallback loading logic has been streamlined to reduce potential race conditions and inefficiencies. STATUS: RESOLVED
- Error Handling & Logging: Print statements have been replaced with proper logging frameworks across utility and route files. However, some endpoints still use overly broad exception handling and inconsistent error response formats. STATUS: PARTIALLY RESOLVED
- Data Integrity & Storage Consistency: MongoDB operations have been standardized to use consistent key names (agentId) for agent operations. Checkpoint collection naming has been corrected to match MongoDBSaver configuration. STATUS: RESOLVED
- Code Quality & Maintainability: Dead code, commented sections, and redundant function names have been cleaned up across multiple files. Complex checkpoint handling logic has been simplified and utility functions with hardcoded values have been removed or refactored. STATUS: RESOLVED
Remediation Roadmap
- Complete user access control implementation: Restrict POST /users/ to use token-derived user_id and implement role-based access for GET /users/ endpoint (CRITICAL - PARTIALLY RESOLVED).
- Secure agent listing endpoint: Evaluate whether /api/v1/agents/list-agents/ should remain public or be moved to authenticated access (MEDIUM - UNRESOLVED).
- Standardize error handling: Replace remaining broad exception handlers with specific exception types and ensure consistent error response formats across all endpoints (LOW - PARTIALLY RESOLVED).
- Maintain security standards: Continue regular dependency audits and version pinning in requirements.txt.
Note: This audit covers only the backend Python FastAPI implementation. Frontend code and smart contract logic were not part of this review. The remaining unresolved issues should be addressed according to severity and re-tested before deployment to production environments handling sensitive user data or transactions.
Files and details
Findings and Audit result
critical Issues | 1 findings
Resolved
#1 critical Issue
Missing Authorization / Insufficient Access Control on User Endpoints
While user endpoints are authenticated, any authenticated user can perform CRUD operations on any user's data due to lack of authorization checks.
high Issues | 4 findings
Resolved
#1 high Issue
Lack of Input Validation
Endpoints /create-agent and /update-agent/{agent_id} accept 'agent_data: dict' without schema enforcement or validation, risking errors or malicious input.
Resolved
#2 high Issue
User ID as Query Parameter Allowing Unauthorized Updates
The /agents/preferences/ endpoint accepts 'user_id' as a query parameter, potentially allowing users to update preferences for other users if not strictly validated server-side against the authenticated user.
Resolved
#3 high Issue
Potential Missing Authorization Check in Transaction Retrieval
The GET /transactions/{transaction_id} endpoint doesn't seem to use the authenticated user's ID when calling 'get_transaction', potentially allowing any authenticated user to retrieve any transaction.
Resolved
#4 high Issue
Hardcoded Cookie in API Request
The 'get_advanced_routes' function includes a hardcoded cookie in its API request headers, which is a security risk.
medium Issues | 12 findings
Resolved
#1 medium Issue
Hardcoded Cryptographic Key
The JWT public verification key (VERIFICATION_KEY) is hardcoded in 'privy_utils.py' and duplicated in 'main.py'.
Resolved
#2 medium Issue
Duplicate Route Definition
The route /list-agents is defined twice in agents.py; the second definition will overwrite the first.
Resolved
#3 medium Issue
Potentially Risky Endpoint Exposed
The /load-agents endpoint calls 'load_agents_on_startup()'. Exposing this as an API might lead to unintended re-initializations or side effects.
Resolved
#4 medium Issue
Complex Agent Loading Logic in Request Path
The chat endpoint has logic to load agents if not found in AGENT_REGISTRY by calling load_agents_on_startup(), which could be inefficient and lead to side effects.
Resolved
#5 medium Issue
Redundant User ID Path Parameter
Endpoints in threads.py take 'user_id' as a path parameter but then use the 'user_id' from the authenticated token, making the path parameter redundant.
Resolved
#6 medium Issue
Potentially Unauthenticated Statistics Endpoint
The /statistics/ endpoint does not appear to have authentication, which could expose sensitive aggregate data if not intended for public view.
Resolved
#7 medium Issue
Agent Loading Strategy
Agent loading via 'load_agents_on_startup()' could be inefficient if called multiple times. 'main.py' calls it once, which is good. Concerns in 'chat.py' and 'agents.py' about calling it should be reviewed to ensure they don't cause reloads.
Resolved
#8 medium Issue
Inconsistent Key for Agent Database Updates
'save_agent_to_db' uses 'agentName' for upserting, while 'update_agent_to_db' uses 'agentId'. This inconsistency can lead to data issues.
Resolved
#9 medium Issue
Potential Incorrect Collection Name for Deleting Checkpoints
'delete_messages_by_thread_id' uses 'db["checkpoints"]', but 'MongoDBSaver' uses 'checkpoint_ns="AGY"'. The actual collection name might differ.
Resolved
#10 medium Issue
Silent Error Handling Obscuring Failures
The 'get_advanced_routes' function returns an empty dictionary '{}' on API request failure, which can hide the error from the caller.
Resolved
#11 medium Issue
Overly Permissive CORS Policy
CORS is configured with 'allow_origins=["*"]', which is too permissive for a production environment.
Acknowledged
#12 medium Issue
Unauthenticated Agent Listing Endpoints
The path '/api/v1/agents' is excluded from authentication, making agent listing endpoints public.
low Issues | 8 findings
Resolved
#1 low Issue
Potential Dead or Commented-Out Code
Multiple files contain commented-out code sections or unused variables (e.g., 'ALLOWED_CHAINS' in lifi_utils.py) that should be removed.
Resolved
#2 low Issue
Redundant User ID Query/Body Parameter
Several endpoints accept 'user_id' as a query or body parameter which is then overwritten by the 'user_id' from the auth token.
Resolved
#3 low Issue
Use of 'print' for Logging
Extensive use of 'print()' for logging/debugging in multiple utility and route files. This should be replaced with a dedicated logging library.
Acknowledged
#4 low Issue
Inconsistent Error Response Format
Error response structures vary between different endpoints in threads.py.
Acknowledged
#5 low Issue
Overly Broad Exception Handling
Generic 'except Exception' clauses are used, which can mask specific error types and make debugging harder.
Resolved
#6 low Issue
Reused Python Function Names for Different Routes
Some Python function names (e.g., 'create_new_transaction', 'agentUsage') are reused for different API routes. While FastAPI handles this, it's not a best practice.
Resolved
#7 low Issue
Complex Checkpoint Handling Logic
The logic for handling chat history checkpoints in 'fetch_user_history' and 'update_last_tool_message' is complex and could be streamlined.
Resolved
#8 low Issue
Unused Utility Function with Hardcoded Values
The 'read_from_contract' function seems to be a standalone test script with hardcoded values and is likely unused by the main application.