How 78778443/swallow works
Project Type & Purpose
• This is a web-based code auditing tool that combines the static analysis power of CodeQL with the natural language processing of ChatGPT. Its goal is to automate vulnerability detection by scanning codebases (via CodeQL), processing the results (SARIF files), augmenting the analysis with AI-generated explanations and remediation suggestions, and finally presenting these results via a web user interface.
Analyzing the File Structure
• The top-level “web” directory indicates that the project is packaged as a web application.
• “controller”: Handles routing and the core HTTP request logic.
• “model”: Contains classes like ChatGPT, CodeQlModel and others to interact with the database and business logic.
• “admin”: A dedicated section with its own controllers, models, views, and middleware, which suggests that there is a web-based admin console.
• “config”: Configuration files for application settings, routing, middleware, database, and more.
• “public”: The web root that delivers static resources and the main entry script.
• The presence of scripts like “scan.sh” and files such as “swallow.sql” indicate database setup and code scanning execution logic.
Key Architectural Components
A. Code Scanning Module:
• Executes the CodeQL tool on a target codebase.
• Generates SARIF format files that include vulnerability details.
B. Data Processing Module:
• Parses the SARIF files to extract and format vulnerability data for further processing.
• Prepares a prompt (as seen in the sample code) for the AI analysis.
C. AI Analysis Module:
• Integrates with ChatGPT. It sends prompts (vulnerability details) to generate human-readable descriptions and remediation suggestions.
• Updates the database with AI responses.
D. Database Layer:
• Stores the results from the scanning process along with AI analysis outputs (e.g., “codeql” table).
E. Web Presentation Layer (MVC-Style):
• Controllers (both admin and general) fetch processed data from models.
• Views present details (vulnerability descriptions, reports, and remediation suggestions) to users.
• Routing files and view templates dictate the navigation and rendering of information.
Relationships & Interactions
• The process begins when the scanning module executes CodeQL (invoked perhaps via a command or admin action).
• The resulting SARIF file is parsed by the data processing module.
• Extracted data is used to create prompts that are sent to ChatGPT in the AI analysis module.
• The output from ChatGPT is then saved into the database.
• Finally, web controllers retrieve both raw and AI-enhanced data from the database to display on various web pages (both admin and public views).
• Configuration files manage these interactions, and the routing system (located under “web/route”) ensures proper data flow and request handling.
Architectural Patterns
• MVC Pattern: Evident from distinct directories for controllers, models, and views.
• Modular Design: Separation between admin functionalities and the main application.
• Service-Oriented approach: Individual services for scanning, data processing, and AI analysis interact through clearly defined boundaries.
• Integration of external tools: CodeQL for static analysis and ChatGPT for natural language processing.
Technologies and Frameworks
• PHP (likely with a framework such as thinkPHP, suggested by the “think” folder and typical PHP structure).
• CodeQL as the static code scanning tool.
• ChatGPT via an API wrapper or custom integration (as seen in the ChatGPT class usage).
• A SQL-based database, deduced from the “swallow.sql” file and database configuration in “web/config/database.php”.
• Docker (docker-compose.yaml) could be used for environment setup and deployment.