Changes between Version 2 and Version 3 of P9APISecurity
- Timestamp:
- 01/13/26 20:03:41 (7 days ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
P9APISecurity
v2 v3 2 2 3 3 === Overview === 4 In a real Wedding Planner web application, the API is the main entry point for all user actions (view weddings, RSVP, guest management, availability checks).5 If API endpoints are not protected, attackers can abuse them to read private data, spam requests, or modify bookings.4 In a real Wedding Planner web application, the REST API is the main entry point for all actions (view weddings, manage guests, RSVP, bookings, availability checks). 5 If API endpoints are not protected, malicious users can read private data, spam requests, or attempt to modify reservations. 6 6 7 Even though our P4 prototype is minimal (Flask REST + SQLite), the same security principles would apply in a production version.7 Even though our P4 prototype is minimal (Flask REST + SQLite), the same security principles apply in a production environment. 8 8 9 9 === Main risks for our API === 10 If security is missing, possible problems include:11 * Unauthorized access to wedding data (guests, RSVPs, bookings)12 * Fake RSVP s / attendance spam13 * Availability endpoint abuse (hundreds of calls per second)10 If API security is missing, common risks include: 11 * Unauthorized access to private wedding data (guests, RSVP responses, attendance info) 12 * Fake RSVP/attendance spam (polluting the database) 13 * Endpoint abuse (especially availability checks) 14 14 * SQL injection attempts through query parameters 15 15 16 In Wedding Planner, the most sensitive resources are: 17 * Guest lists (Guest table) 18 * RSVP responses (Event_RSVP table) 19 * Bookings (Venue_booking, Band_booking, Photographer_booking) 20 16 21 === Input validation (most important rule) === 17 Input validation means checking every value that comes from the user before using it. 18 In our system, this applies especially to parameters such as: 19 * wedding_id, event_id, guest_id (must be integer) 20 * date and time intervals for bookings (must be valid and logical) 21 * RSVP status (must be only allowed values) 22 Input validation means checking every parameter received from the user before using it in business logic or database queries. 23 This prevents invalid requests, inconsistent data, and accidental crashes. 22 24 23 Example validation rules in our project: 24 * wedding_id must be a positive integer 25 * end_time must be greater than start_time 26 * RSVP status must be one of: accepted / declined / pending 25 In our project, validation is especially important for: 26 * wedding_id, event_id, guest_id (must be positive integers) 27 * date, start_time, end_time (must be valid formats) 28 * RSVP status (must be an allowed value) 29 30 Example validation rules: 31 * wedding_id > 0 32 * end_time > start_time 33 * RSVP status ∈ {accepted, declined, pending} 27 34 28 35 Example (pseudo-code): 29 36 {{{ 30 37 if wedding_id <= 0: 31 return error"Invalid wedding_id"38 return 400 "Invalid wedding_id" 32 39 33 40 if end_time <= start_time: 34 return error"Invalid time interval"41 return 400 "Invalid time interval" 35 42 }}} 36 43 37 44 Why this matters: 38 Without validation, invalid input can crash the API or create inconsistent data (wrong bookings, duplicates, broken rows).45 Without validation, we can store broken bookings (wrong times) or invalid RSVP values that affect attendance logic. 39 46 40 === Parameterized queries ( protection from SQL injection) ===41 SQL injection happens when attacker input becomes part of theSQL query.42 The safe way is to use parameterized queries, never string concatenation.47 === Parameterized queries (SQL injection prevention) === 48 SQL injection happens when untrusted input becomes part of an SQL query. 49 The correct protection is to always use parameterized queries (never string concatenation). 43 50 44 51 Unsafe example: … … 47 54 }}} 48 55 49 Safe example :56 Safe example (conceptual): 50 57 {{{ 51 SELECT * FROM wedding WHERE wedding_id = %s;58 SELECT * FROM wedding WHERE wedding_id = ?; 52 59 }}} 53 60 54 In Wedding Planner this is importantfor endpoints like:61 This is critical for endpoints like: 55 62 * /weddings/<wedding_id>/events 56 63 * /weddings/<wedding_id>/guests 57 * /availability/venue?venue_id=...&date=... 64 * /availability/venue?venue_id=...&date=...&start=...&end=... 58 65 59 === Basic authentication & authorization === 60 In a full production application, not everyone should access everything. 66 If these endpoints use unsafe query building, attackers can try inputs like: 67 {{{ 68 wedding_id = "1 OR 1=1" 69 }}} 70 which can expose data from multiple weddings. 71 72 === Authentication & Authorization (access control basics) === 73 In a full system, not every user should have access to all weddings. 61 74 62 75 Authentication = who is the user? … … 64 77 65 78 Example rules in Wedding Planner: 66 * Only the wedding owner (User) can view/edit that wedding67 * Guests can only RSVP via invitation link (limited access)68 * Admin can manage venue data79 * Only the owner of the wedding (User.user_id) can view/edit that wedding 80 * Guests can only RSVP for events they are invited to 81 * Only wedding owner can view full guest list 69 82 70 Example check (conceptual):83 Example authorization check (pseudo-code): 71 84 {{{ 72 85 if current_user.user_id != wedding.user_id: … … 74 87 }}} 75 88 76 This prevents a user from accessing another user's wedding details just by changing the wedding_id in the URL.89 This prevents the common issue where a user changes the wedding_id in the URL to access another person’s data. 77 90 78 === Rate limiting (prevent abuse) ===79 Rate limiting limits the number of requests per user/IP per minute.80 This is crucial for endpoints that can be abused.91 === Rate limiting (prevent endpoint abuse) === 92 Rate limiting controls the number of requests per user/IP per time window. 93 This prevents spam, brute-force attempts, and performance degradation. 81 94 82 In our system the most "abusable"endpoint is:95 In Wedding Planner, the most “abusable” endpoint is: 83 96 * /availability/venue 84 97 85 98 Attack scenario: 86 Someone sends thousands of availability checks -> server slows down or crashes.99 An attacker sends thousands of availability checks per minute which may overload the server. 87 100 88 101 Example policy: 89 * max 60 requests per minute per IP for /availability/venue 102 * 60 requests/minute per IP for /availability/venue 103 * 30 requests/minute for RSVP-related endpoints 90 104 91 This keeps the API stable evenunder heavy traffic.105 This keeps the system responsive and stable under heavy traffic. 92 106 93 === How this connects to our project === 94 For Wedding Planner, API security should focus on: 95 * Validating booking parameters (date/time overlap) 96 * Protecting RSVP and attendance updates from spam 97 * Ensuring only wedding owners can view guest lists 98 * Preventing abuse of availability checks with rate limiting 107 === Practical examples connected to Wedding Planner === 108 The following protections directly apply to our system: 109 * Validate time interval and date format for venue bookings 110 * Reject RSVP status outside allowed values 111 * Limit repeated calls to availability endpoint 112 * Ensure wedding owner can access guest list and attendance overview 113 114 Example: protect guest list endpoint 115 * /weddings/<wedding_id>/guests 116 Rules: 117 * wedding_id must be valid integer 118 * current_user must be wedding owner 119 * SQL query must be parameterized 99 120 100 121 === Conclusion === 101 API security is essential even for a minimal prototype, because it demonstrates how the system would behave in real-world conditions.102 For our Wedding Planner application, the most important protections are input validation, parameterized queries, basic access control, and rate limiting.103 These practices prevent common attacks (SQL injection, data leaks, endpoint abuse) and ensure the systemremains stable and trustworthy.122 API security is essential because it protects the database and prevents abuse of the core system functionalities. 123 For the Wedding Planner system, the most important measures are strict input validation, parameterized queries, access control (auth/authorization), and rate limiting. 124 These practices prevent the most common attacks (SQL injection, data leaks, spam) and ensure the application remains stable and trustworthy.
