Introduction
We express our gratitude to the CratD2C team for the collaborative engagement that enabled the execution of this dApp Security Assessment.
CratD2C is a decentralized blockchain platform designed to provide a robust, secure, and scalable infrastructure for various decentralized applications (dApps) across industries.
Document | |
|---|---|
| Name | dApp Code Review and Security Analysis Report for CratD2C |
| Audited By | Stephen Ajayi |
| Approved By | Stephen Ajayi |
| Website | https://cratd2csmartchain.io/→ |
| Changelog | 16/10/2024 - Preliminary Report |
| 15/11/2024 - Final Report | |
| Platform | Django, WSGI, Docker, PostgrSQL, Celery, CratD2C |
| Language | Python |
| Tags | Backend, API |
| Methodology | https://hackenio.cc/dApp_methodology→ |
Document
- Name
- dApp Code Review and Security Analysis Report for CratD2C
- Audited By
- Stephen Ajayi
- Approved By
- Stephen Ajayi
- Changelog
- 16/10/2024 - Preliminary Report
- 15/11/2024 - Final Report
- Platform
- Django, WSGI, Docker, PostgrSQL, Celery, CratD2C
- Language
- Python
- Tags
- Backend, API
- Methodology
- https://hackenio.cc/dApp_methodology→
Review Scope | |
|---|---|
| Repository 1 and Commit | https://github.com/CratD2C-SmartChain/CratD2C-validator→ |
| Repository 2 and Commit | https://github.com/CratD2C-SmartChain/CratD2C_staking_manager_backend→ |
Review Scope
- Repository 1 and Commit
- https://github.com/CratD2C-SmartChain/CratD2C-validator→
- Repository 2 and Commit
- https://github.com/CratD2C-SmartChain/CratD2C_staking_manager_backend→
Audit Summary
The system users should acknowledge all the risks summed up in the risks section of the report
Documentation quality
The backend project provides a
README.mdthat outlines project setup, including commands for initializing the project usingMakefile, and key steps such as migrations, static file collection, and creating a superuser. This ensures that users can get started relatively easily.The validator project includes a
README.mdwith a link to additional setup instructions, ensuring that users know where to find further information. It provides a starting point for setting up a validator node.The backend
README.mdhighlights important features such as Pre-Commit hooks and usage of Makefile for automation, making the development workflow efficient and structured.Both projects use Docker and provide Dockerfiles, which simplify the deployment process and allow for containerization of the application, aiding consistency across environments.
The validator documentation lacks detailed information about setup and configuration, deferring entirely to an external link. It would benefit from more in-depth instructions directly in the
README.md, especially regarding environment variables and specific commands needed to configure the node locally.Include API Documentation: Use tools like Swagger or Postman to automatically generate and host API documentation. Include sample requests and responses.
Expand the
README.mdfor the validator with step-by-step setup instructions, environment configuration examples, and key operations like syncing or troubleshooting.
Code quality
The backend project makes effective use of a Makefile for key tasks such as initializing the project, running migrations, and collecting static files. This helps streamline development and maintenance processes.
The backend project utilizes Pre-Commit hooks (
.pre-commit-config.yaml), which enforces coding standards and catches errors before they are committed to the repository. This enhances the maintainability and reliability of the codebase.Both projects include Dockerfiles and docker-compose.yml, which ensure the projects are containerized and easily deployable across different environments. This reduces configuration drift and aids in development.
The Dockerfiles in both projects should be improved to avoid using root privileges, implement version pinning for dependencies, and reduce the image size. There are also improvements to be made regarding health checks and multi-stage builds to ensure secure and efficient containerization.
System Overview
CratD2C is a decentralized blockchain platform designed to provide a robust, secure, and scalable infrastructure for various decentralized applications (dApps) across industries. Built on a Delegated Proof of Stake (DPoS) consensus mechanism and leveraging Layer-1 blockchain architecture, CratD2C ensures high security, fast transaction processing, and low fees. It also focuses on enhanced privacy features to create a versatile and transparent digital ecosystem.
The platform is built to address the needs of industries such as manufacturing, logistics, real estate, intellectual property, content creation, and agriculture. Its primary objective is to streamline operations in these sectors by providing an efficient, decentralized, and secure digital framework.
Key Features of CratDC
High Scalability: The platform supports up to 100,000 transactions per second (TPS), which is significantly higher than traditional blockchains like Ethereum and Bitcoin.
Low Transaction Costs: By employing the DPoS model, CratD2C minimizes transaction fees while ensuring high throughput.
Governance and Security: Validators play a key role in maintaining consensus and security, while delegators can stake their tokens to participate in the network’s governance and earn rewards.
Industrial Focus: The blockchain infrastructure is designed to support various sectors, including real estate, intellectual property, and supply chain management.
Project Overview CratDC Staking Manager Backend
The CratD2C Staking Manager Backend is a core component of the CratD2C ecosystem, which operates as a decentralized blockchain platform designed to support staking operations and validator management in a Delegated Proof of Stake (DPoS) model. The application serves as the backend service for managing validator nodes, user staking, reward distribution, and various blockchain interactions, while ensuring a scalable, secure, and efficient system.
This project is built using the Django framework and is containerized using Docker to ensure smooth deployment across various environments. The backend interacts with smart contracts on the CratD2C blockchain via the Web3.py library, facilitating key blockchain operations such as staking, validator registration, and transaction tracking.
Key Features and Responsibilities
Validator Management: Facilitates the operation and maintenance of validator nodes, ensuring the CratD2C network's consensus mechanism functions efficiently.
Staking Operations: Handles user staking actions, rewards distribution, and performance monitoring for validators and delegators.
Asynchronous Task Handling: Employs Celery for background jobs, ensuring high availability and scalability by offloading long-running tasks like reward calculations and blockchain syncing.
Key Components
**accounts/**: Manages user authentication and account-related operations.**validators/**: Handles validator operations and staking mechanisms in the DPoS model.**statistic/**: Provides tracking and analytics for staking activities and validator performance.**abi/**: Stores ABI files for interacting with blockchain smart contracts.**tasks.py**: Runs background tasks such as reward distribution and validator performance monitoring.**serializers.py**: Converts complex data into API-friendly formats.**models.py**: Defines the database structure for validators, accounts, and staking operations.**docker-compose.yml**: Sets up the containerized environment for running the application.
Findings
Code ― | Title | Status | Severity | |
|---|---|---|---|---|
| F-2024-6483 | Replay Attack Vulnerability | fixed | Critical | |
| F-2024-6531 | Improper Handling of ALLOWED_HOSTS Configuration | fixed | High | |
| F-2024-6491 | Improper Input Validation for Hexadecimal Signatures in WalletConnectView | fixed | High | |
| F-2024-6609 | Missing Permission Check in SetUpValidatorView | fixed | High | |
| F-2024-6596 | Insecure API Key Authentication via Header | fixed | Medium | |
| F-2024-6594 | Unvalidated Image File Upload | fixed | Medium | |
| F-2024-6497 | Insecure Handling of Blockchain Block Numbers and Timestamps | fixed | Medium | |
| F-2024-6610 | Insecure Handling of Sensitive Data in Configuration Files | fixed | Medium | |
| F-2024-6608 | Race Condition in Validator Creation and Deletion | fixed | Medium | |
| F-2024-6605 | Potential Replay Attack in depositasvalidator Function | fixed | Medium |
Appendix 1. Severity Definitions
Severity | Description |
|---|---|
Critical | These issues present a major security vulnerability that poses a severe risk to the system. They require immediate attention and must be resolved to prevent a potential security breach or other significant harm. |
High | These issues present a significant risk to the system, but may not require immediate attention. They should be addressed in a timely manner to reduce the risk of the potential security breach. |
Medium | These issues present a moderate risk to the system and cannot have a great impact on its function. They should be addressed in a reasonable time frame, but may not require immediate attention. |
Low | These issues present no risk to the system and typically relate to the code quality problems or general recommendations. They do not require immediate attention and should be viewed as a minor recommendation. |
Severity
- Critical
Description
- These issues present a major security vulnerability that poses a severe risk to the system. They require immediate attention and must be resolved to prevent a potential security breach or other significant harm.
Severity
- High
Description
- These issues present a significant risk to the system, but may not require immediate attention. They should be addressed in a timely manner to reduce the risk of the potential security breach.
Severity
- Medium
Description
- These issues present a moderate risk to the system and cannot have a great impact on its function. They should be addressed in a reasonable time frame, but may not require immediate attention.
Severity
- Low
Description
- These issues present no risk to the system and typically relate to the code quality problems or general recommendations. They do not require immediate attention and should be viewed as a minor recommendation.
Appendix 2. Scope
The scope of the project includes the following files from the provided repository:
Scope Details | |
|---|---|
| Repository 1 and Commit | https://github.com/CratD2C-SmartChain/CratD2C-validator→ |
| Repository 2 and Commit | https://github.com/CratD2C-SmartChain/CratD2C_staking_manager_backend→ |
| Documentation | https://github.com/CratD2C-SmartChain___CratD2C_staking_manager_backend/blob/main/README.md,→ |
Scope Details
- Repository 1 and Commit
- https://github.com/CratD2C-SmartChain/CratD2C-validator→
- Repository 2 and Commit
- https://github.com/CratD2C-SmartChain/CratD2C_staking_manager_backend→