Skip to content

kavyashreeshah/secure-input-demo

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PulseClinic Intake API

⚠️ WARNING: This is an intentionally vulnerable demo project for teaching input validation and injection defense. DO NOT USE IN PRODUCTION.

Overview

PulseClinic.IntakeApi is a demo ASP.NET Core Web API (.NET 10) built for Udemy Section 8: "Input Validation & Injection Defense". This is the Start project that contains various security vulnerabilities for educational purposes.

Purpose

This project demonstrates common security vulnerabilities:

  • Missing input validation
  • SQL injection attacks
  • Cross-Site Scripting (XSS)
  • Path traversal vulnerabilities
  • Unrestricted file upload issues
  • Regular Expression Denial of Service (ReDoS)
  • Information disclosure through error messages

Each vulnerability is clearly marked with // VULNERABLE (Lecture XX) comments for easy reference during course recordings.

Quick Start

Prerequisites

  • .NET 10 SDK
  • Any code editor (Visual Studio 2025, VS Code, JetBrains Rider)

Build and Run

# Clone or navigate to the repository
cd PulseClinic.IntakeApi

# Restore dependencies
dotnet restore

# Build the solution
dotnet build

# Run the API
dotnet run --project src/PulseClinic.Api

# Or run from the API directory
cd src/PulseClinic.Api
dotnet run

The API will start on:

Access Swagger UI

Open your browser to: https://localhost:5001/swagger

Database

  • Type: SQLite
  • Location: ./src/PulseClinic.Api/app_data/pulseclinic.db
  • Migrations: Auto-applied on startup
  • Seed Data: Automatically populated with sample records

Run Tests

dotnet test

Project Structure

PulseClinic.IntakeApi/
├── src/
│   ├── PulseClinic.Api/              # Main Web API project
│   │   ├── Controllers/              # API controllers (all vulnerable)
│   │   ├── Models/                   # DTOs (minimal validation)
│   │   └── Program.cs                # Startup configuration
│   │
│   └── PulseClinic.Data/             # Data access layer
│       ├── Entities/                 # EF Core entities
│       ├── Migrations/               # EF Core migrations
│       ├── PulseClinicDbContext.cs   # DbContext
│       └── DatabaseSeeder.cs         # Sample data seeder
│
├── tests/
│   └── PulseClinic.Api.IntegrationTests/  # Basic integration tests
│
├── docs/
│   └── Section8-Runbook.md           # Detailed attack demo guide
│
├── PulseClinic.IntakeApi.sln         # Solution file
└── README.md                         # This file

API Endpoints

Patient Intakes

  • POST /api/intakes - Create new patient intake
  • GET /api/intakes/{id} - Get single intake by ID
  • GET /api/intakes/search?q={query}&sort={field} - Search intakes (⚠️ SQL Injection)

Appointments

  • POST /api/appointments - Create appointment request
  • GET /api/appointments/{id} - Get single appointment
  • GET /api/appointments/search?q={query} - Search appointments (⚠️ SQL Injection)

Staff Notes

  • POST /api/staffnotes - Create staff note (⚠️ Stores XSS payloads)
  • GET /api/staffnotes/{id} - Get staff note as JSON
  • GET /api/staffnotes/preview/{id} - Preview note as HTML (⚠️ XSS vulnerability)
  • GET /api/staffnotes/patient/{patientId} - List notes for patient

File Operations

  • POST /api/files/upload - Upload file (⚠️ Path traversal, no validation)
  • GET /api/files/{id}/download - Download file (⚠️ No scan check)
  • GET /api/files/{id} - Get file metadata
  • GET /api/files - List all uploaded files

Domain Model

PatientIntake

Patient intake record with personal and medical information.

AppointmentRequest

Appointment booking linked to a patient intake.

StaffNote

Clinical notes written by medical staff about patients.

UploadedFile

Metadata for uploaded files (lab results, medical images, etc.).

Key Vulnerabilities

See docs/Section8-Runbook.md for detailed attack demos and remediation strategies.

Summary of Vulnerabilities:

  1. Missing Input Validation - DTOs lack validation attributes
  2. ReDoS - Regex patterns with catastrophic backtracking
  3. SQL Injection - Raw SQL with string concatenation in search endpoints
  4. Stored XSS - Staff notes preview renders unsanitized HTML
  5. Path Traversal - File upload uses original filenames without sanitization
  6. Unrestricted Upload - No file size, type, or malware checks
  7. Information Disclosure - Error messages expose stack traces
  8. Semantic Validation Gaps - Status fields accept any string value

Each vulnerability is tagged with lecture numbers for easy cross-reference during course development.

Sample Data

The database seeds with:

  • 3 sample patients
  • 2 appointment requests
  • 3 staff notes
  • 2 uploaded file records

All records use deterministic GUIDs (11111111-1111-..., 22222222-2222-..., etc.) for predictable testing.

Technologies

  • .NET 10 - Latest .NET version
  • ASP.NET Core Web API - RESTful API framework
  • Entity Framework Core 10 - ORM for data access
  • SQLite - Embedded database for easy setup
  • Swagger/OpenAPI - API documentation and testing
  • xUnit - Testing framework

Learning Objectives

After working through this project, students will understand:

  1. How to identify common input validation vulnerabilities
  2. The mechanics of injection attacks (SQL, XSS, path traversal)
  3. Performance attacks using ReDoS
  4. File upload security risks
  5. Proper error handling without information leakage
  6. Defense-in-depth validation strategies
  7. Secure coding practices in .NET 10

Next Steps

This is the Start project. During the course, you'll:

  1. Identify each vulnerability using tools and manual testing
  2. Learn the security principles behind each issue
  3. Implement proper fixes using modern .NET security features
  4. Build a Finished version with all vulnerabilities remediated

Contributing

This is a teaching project. If you're a student taking this course:

  • Practice exploiting these vulnerabilities in a safe environment
  • Document your findings
  • Try creating additional test cases
  • Do not fix the vulnerabilities in this "Start" project - that's for the course!

License

This project is for educational purposes only. Use at your own risk.

Support

For questions about the course content, please refer to:


Remember: This code is intentionally insecure. Never use these patterns in real applications! 🛡️

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C# 99.4%
  • HTML 0.6%