Changes between Initial Version and Version 1 of P9APISecurity


Ignore:
Timestamp:
01/13/26 18:37:15 (7 days ago)
Author:
193284
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • P9APISecurity

    v1 v1  
     1= P9 – API Security (Input Validation, Rate Limiting, Auth Basics) =
     2
     3== Overview ==
     4In real systems, the database is accessed through an API (backend). Because of that, protecting the API is just as important as designing the database correctly.
     5In Wedding Planner, endpoints such as RSVP updates and booking availability must be protected from invalid input and abuse.
     6
     7== Input validation ==
     8Input validation means checking all user input before using it in SQL queries or inserting it in the database.
     9
     10Why it matters:
     11 * prevents incorrect data from being stored
     12 * avoids broken constraints and invalid formats
     13 * reduces risk of attacks (SQL injection, malicious payload)
     14
     15Example connected to our project:
     16When calling:
     17{{{
     18/availability/venue?venue_id=1&date=2026-06-20&start=15:00&end=21:00
     19}}}
     20
     21The API should validate:
     22 * venue_id is numeric
     23 * date is valid YYYY-MM-DD
     24 * start/end are valid HH:MM
     25 * end_time > start_time
     26
     27Pseudo-code example:
     28{{{
     29if not venue_id.isdigit(): return error("Invalid venue_id")
     30if not valid_date(date): return error("Invalid date format")
     31if end <= start: return error("Invalid interval")
     32}}}
     33
     34== Rate limiting ==
     35Rate limiting protects the system from too many requests in a short time (spam / brute force).
     36
     37Why it matters in Wedding Planner:
     38 * availability checks can be called many times
     39 * attacker can overload API by repeatedly calling /availability/venue
     40 * database performance becomes worse under heavy traffic
     41
     42Example rule:
     43 * max 60 requests per minute per user/IP
     44
     45Pseudo-config (conceptual):
     46{{{
     47limit_requests("/availability/venue", 60 per minute)
     48}}}
     49
     50== Authentication basics ==
     51Authentication means verifying who the user is (login/session/token).
     52
     53Even though our P4 prototype is minimal and REST-based, in a real system:
     54 * only logged-in users should manage weddings
     55 * only wedding owner should edit guests / RSVP
     56 * users should not access other people’s weddings
     57
     58Example access rule (connected to our project):
     59{{{
     60GET /weddings/1/guests
     61}}}
     62
     63Should return data only if:
     64 * user is logged in
     65 * user owns wedding_id = 1
     66
     67Pseudo-code:
     68{{{
     69if not authenticated(): return 401
     70if wedding.user_id != current_user.id: return 403
     71}}}
     72
     73== Conclusion ==
     74API security protects the database by ensuring that only valid and allowed requests reach the data layer.
     75For Wedding Planner, input validation is critical for correctness (dates/times/IDs), rate limiting protects frequent endpoints like availability checks, and authentication ensures users can only access their own weddings.
     76These practices would be mandatory in a real production implementation of the system.