How erev0s/vampi works
Project Type & Purpose
• VAmPI is a Flask-based API intentionally designed with vulnerabilities (e.g., SQL Injection, Broken Object Level Authorization, etc.) for the purpose of testing and evaluating security tools, as well as for educational demonstrations.
• The README explains that it offers a token-based authentication mechanism and includes endpoints for user registration, login, book management, and a debug endpoint.
Analyzing the File Structure
• Key directories/files:
• Root-level files: app.py (main entry point), config.py, Dockerfile, docker-compose.yaml, and requirements.txt.
• api_views/ directory: Contains the definitions for endpoints (books.py, users.py, main.py, and json_schemas.py) that define the API’s behavior.
• models/ directory: Holds the data models (books_model.py, user_model.py) representing business logic and database entities.
• database/ directory: Contains database initialization/population code. A specific endpoint (/createdb) in the API is used to trigger these routines.
• openapi_specs/ directory: Provides OpenAPI 3 specifications and a Postman collection for API documentation and testing.
• Presence of Docker-related files (.dockerignore, Dockerfile, docker-compose.yaml) which indicate container-based deployment, including two different configurations (secure and insecure) as mentioned in the README.
Main Components & Their Relationships
• Web Server / Application Layer: Represented by app.py running the Flask application.
• API Views: Group the endpoints defined in the api_views/ directory. This separates endpoints concerning users, books, and any shared schemas.
• Models & Database: The models/ directory encapsulates the data layer. The database/ directory then initializes and populates (via the /createdb endpoint) the actual database used by these models.
• Configuration & Environment: The config.py along with environment variables (controlled via Dockerfile and docker-compose) govern security aspects such as vulnerability mode (switching between vulnerable and secure) and token time-to-live settings.
• Documentation & Developer Tools: OpenAPI specs and available Swagger UI (/ui endpoint) provide the interactive documentation interface.
• Containerization: Dockerfile and docker-compose configurations illustrate the application packaging and deployment, including the ability to run different instances (secure/insecure) on different ports.
Important Architectural Patterns & Design Principles
• Separation of concerns: The API endpoints (in api_views) are clearly separated from data models (in models) and the database schema/logic.
• Configuration management: Environmental variable configuration (especially regarding security settings) is centralized in the Dockerfile/app.py.
• API-centric design: Emphasize RESTful API principles with clear endpoint definitions and use of an OpenAPI specification for standardization.
• Containerization: Use of Docker enhances consistency across environments, making it easier to switch modes (vulnerable vs. secure).
• Clear Labels:
• “Flask Application (app.py)”
• “API Views (Users, Books, Main, JSON Schemas)”
• “Data Models (books_model, user_model)”
• “Database (Initialization and population via /createdb)”
• “Configuration (env vars, config.py, vulnerability switch, token TTL)”
• “Deployment Container (Docker/Docker Compose)”
• “API Documentation (Swagger UI, OpenAPI Specs)”
• Client request flows to the Flask App.
• Internal routing from API Views to Models/Database.