How appsecco/dvcsharp-api works
Project type and purpose
• This is a .NET Core 2.x RESTful API (“Damn Vulnerable C# Application – API Only”) designed to demonstrate common web-app vulnerabilities.
• It provides user registration, authentication (tokens), password-resets, product CRUD, and import endpoints. It is explicitly meant for security testing (not production).
File structure
• Top-level:
• Controllers/ – ASP.NET Core MVC controllers (entry points for HTTP).
• Models/ – DTOs and EF Core entity classes (User, Product, AuthorizationRequest/Response, etc.).
• Data/ – GenericDataContext.cs (EF Core DbContext).
• Migrations/ – EF Core migration files for schema evolution.
• Startup.cs & Program.cs – host & middleware configuration.
• appsettings*.json – configuration for database, logging, etc.
• Dockerfile & docker-compose.yml – container definitions (API + backing database).
• documentation-dvcsharp-book/ – static documentation and attack guides (external to core runtime).
• test/ & Postman collections – integration/testing assets.
README for additional insights
• The API runs on Kestrel (dotnet run or in Docker).
• Database migrations via dotnet ef database update.
• Docker Compose brings up the API and likely a SQL database.
• There are explicit Postman collections and sample data under documentation.
Main components & interactions
a. Components
1. Client(s)
– REST clients (Postman, browser-based API client, automated tests).
2. API Layer (ASP.NET Core)
– Kestrel web server hosting
– Startup & Middleware (Routing, Authentication, CORS, Logging)
– Controllers (Authorization, Registrations, Tokens, PasswordResets, Users, Products, Imports)
3. Business/Data Layer
– Models (Entity definitions)
– GenericDataContext (DbContext)
– EF Core Migrations
4. Database
– SQL Server/MySQL/PostgreSQL (configured via appsettings.json)
5. External/Infrastructure
– Docker Engine & Docker Compose
– Volume mounts for data persistence
– CI/CD or local tooling (dotnet watch, Postman collection for tests)
b. Relationships & Interactions
• Clients → HTTP(S) → Kestrel/API Layer
• Controllers use Dependency-Injected DbContext → SQL Database
• Startup configures middlewares (JWT bearer auth, error handling)
• Docker Compose networks “api” and “db” containers
• EF Core Migrations manage schema in the Database
c. Architectural patterns & principles
• Layered architecture: Presentation (Controllers) → Business/Data (Services can be added) → Data Access (DbContext) → Persistence (Database)
• Dependency Injection for DbContext and configuration
• RESTful resource design
• Immutable configuration via appsettings.json & environment overrides
• Containerization for environment parity
d. Key technologies
• ASP.NET Core 2.x (Kestrel)
• Entity Framework Core (Code-First Migrations)
• Docker & Docker Compose
• SQL Database of choice (through EF Core provider)
• Postman for API testing
Detailed step-by-step for the principal software engineer
• Middleware (JWT auth, error handling)
• Controllers (list key controllers)
• Data Access (GenericDataContext + Migrations)
5. Configuration files (appsettings.json) feeding into Startup.
6. Optionally, off to the side, show “documentation-dvcsharp-book” as a static GitBook/Markdown site consumed by security testers.
• Client hits /registrations → RegistrationController → DbContext.Add(User) → SQL INSERT.
• Client logs in → TokensController → returns JWT → Client uses JWT in Authorization header on protected endpoints.