This project demonstrates a basic e-commerce website with an Express server and SQLite database, intentionally designed for teaching security vulnerabilities like SQL injection and XSS.
-
Install dependencies:
npm install
-
Initialize the database:
npm run init-db
-
Start the server:
npm start
-
Open your browser and navigate to:
http://localhost:3000
- Product Display: Products are loaded from a SQLite database instead of being hardcoded
- Search Functionality: Search products by name or description (intentionally vulnerable to SQL injection)
- Add Products: Form to add new products to the database (demonstrates POST requests)
- Delete Products: X buttons on each product to delete them (demonstrates DELETE requests)
- Interactive Banner: Click the banner to cycle through promotional messages
- Mixed JavaScript: Demonstrates both inline and external JavaScript files
- No Input Validation: Intentionally designed for teaching security concepts
- The search endpoint (
/api/products/search) is vulnerable to SQL injection - Try searching for:
' OR '1'='1to see all products - Try searching for:
'; DROP TABLE products; --to attempt table deletion
- Product names and descriptions are not sanitized when displayed
- The search functionality uses
encodeURIComponent()but the server doesn't validate input - The "Add Product" form displays user input without sanitization
- The "Add Product" form demonstrates how POST requests work
- Students can observe the request in browser developer tools (Network tab)
- Shows JSON payload structure and HTTP headers
- Demonstrates form data collection and API communication
- X buttons on each product demonstrate DELETE requests
- Students can observe DELETE requests in browser developer tools
- Shows URL parameters and HTTP DELETE method
- Demonstrates confirmation dialogs and error handling
- Inline JavaScript: Banner functionality and product loading in
<script>tags - External JavaScript: Product operations (add/delete) in
product-operations.js - Mixed Approach: Shows how both can work together in the same application
- File Organization: Demonstrates code separation and modularity concepts
GET /- Serves the main HTML pageGET /api/products- Returns all productsGET /api/products/search?q=<search_term>- Searches products (vulnerable to SQL injection)POST /api/products- Adds a new product (vulnerable to SQL injection)DELETE /api/products/:id- Deletes a product by ID (vulnerable to SQL injection)
CREATE TABLE products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
description TEXT NOT NULL,
price REAL NOT NULL
);This project is designed to teach:
- How SQL injection attacks work
- The importance of input validation and sanitization
- How to identify vulnerable code patterns
- Basic web application security concepts
To make this application secure, you would need to:
- Use parameterized queries instead of string concatenation
- Implement input validation and sanitization
- Add proper error handling
- Use a web application firewall
- Implement proper authentication and authorization