1. phases
Itinera API
  • ✈ Itinera API Documentation
  • Docs
    • legacy
      • Itinera — System Overview
      • Technology Stack & Architecture
      • Getting Started Guide
      • Infrastructure
      • Frontend Application
      • Architecture Overview
      • API Reference
      • Backend Services
      • Development Guidelines
    • phases
      • 01. Architecture Overview & Checkout Idempotency
      • Phase 2: Commerce & Checkout Engine
      • Phase 3: Webhooks & Asynchronous Fulfillment
      • Phase 4: Security Perimeter & Authentication
      • Phase 5: Database Schema & Entity Relationships
      • Phase 6: AI Quota & Telemetry Subsystems
      • Phase 7: API Route Matrix & FormRequests
      • Phase 8: Global Exception & Error Handling
      • Phase 9: Frontend Ecosystem & State Management
      • Phase 10: Design System & Component Library
      • Phase 11: Interactive GSAP Animations
      • Phase 12: Deployment & CI/CD Pipeline
      • Phase 13: Testing Strategies
      • Phase 14: Performance & Optimization
      • Phase 15: Developer Onboarding & Runbooks
      • 15-Phase Comprehensive Wiki & Documentation Plan
  • APIs
    • Auth
      • Register a new user
      • Log in a user
      • Log out user
      • Refresh JWT token
      • Forgot password request
      • Reset password verification
      • Get current user profile
      • Update user profile
      • Redirect to Google OAuth
      • Google OAuth Callback
      • Verify email via signed URL
    • Catalog
      • List all countries
      • Get country details
      • List all cities
      • List all regions
      • List all destinations
      • Get destination details
      • Get hotels by destination
      • List all hotels
      • Get hotel details
      • Get reviews for a hotel
      • List all flights
      • Get flight details
      • List all restaurants
      • Get restaurant details
      • List all attractions
      • Get current weather
      • Submit review for an entity
      • Delete review
      • Toggle favourite status for entity
      • List my submitted reviews
    • Bookings
      • Book a tour destination
    • V1 Aliases
      • V1 List all countries
      • V1 Get country details
      • V1 List all cities
      • V1 List all destinations
      • V1 Get destination details
      • V1 Get hotels by destination
      • V1 List all hotels
      • V1 Get hotel details
      • V1 Get reviews for a hotel
      • V1 List all flights
      • V1 Get flight details
      • V1 List all restaurants
      • V1 Get restaurant details
      • V1 List all attractions
      • V1 Get attraction details
      • V1 List all regions
      • V1 Get weather details
    • Trips
      • List user trips
      • Create a new trip
      • Get trip details
      • Update trip details
      • Delete a trip
      • Get creation metadata
      • Attach items to a trip
      • Update trip item
      • Detach items from a trip
      • Fork a trip
    • Conversations
      • List user conversations
      • Start a new conversation
      • Get conversation details
      • List messages in conversation
      • Send message to conversation
      • Mark conversation as read
    • Commerce Plans
      • List public plans
      • Get public plan details
    • Commerce Subscriptions
      • Subscribe to a plan
      • Upgrade active plan
      • Get active subscription info
      • Cancel active subscription
    • Commerce Checkout
      • Initiate Paymob payment checkout
    • Integrations
      • Paymob status webhook callback
      • Paymob redirect return callback
    • System Settings & Support
      • Submit public contact message
      • Subscribe to system newsletter
      • Get list of my reports
      • List all notifications
      • Mark single notification as read
      • List available surveys
      • Submit answers for survey
      • Get survey details
      • Update survey details
      • Delete survey response
    • AI Tools
      • Enhance itinerary details using AI
      • Request AI review of itinerary
      • Plan route using AI assistance
      • Get AI quota remaining details
      • Chat with AI Concierge assistant
      • Get AI Review progress by ID
    • Agency Integration
      • Request agency assignment
      • List agency active tasks
      • List agency managed trips
      • Get agency total earnings
      • Get agency profile details
      • Update agency profile details
    • Admin User Management
      • List users inside admin dashboard
      • Get user profile
      • Set user active status
      • Block user profile
    • Admin Catalog Moderation
      • Create new catalog category
      • Create new catalog destination
      • Create new hotel catalog record
      • Create new flight catalog record
      • Create new restaurant catalog record
      • Create new attraction catalog record
  • Schemas
    • User
    • ErrorResponse
    • Trip
    • Destination
    • Hotel
    • Flight
    • Restaurant
    • Attraction
    • Booking
    • Review
    • Agency
    • Survey
  1. phases

Phase 4: Security Perimeter & Authentication

This document details the multi-layered security architecture of the Itinera API. The system relies on a perimeter defense model: throttling brute-force at the edge, authenticating identities via JWT, validating email states, and enforcing fine-grained RBAC before business logic is executed.

1. Edge Defense: The Rate Limit Matrix#

The application does not rely on a single, global rate limit. Instead, AppServiceProvider registers 9 granular, context-aware sliding windows based on route expense and vulnerability.
LimiterLimitKeyPurpose / Justification
api_authenticated60 / minuser_id or IPGeneral API consumption for authenticated users (SEC-16).
login5 / minIP + emailPrevents credential stuffing. Keys on both IP and the targeted email account.
register5 / minIPPrevents mass account creation / spam bots.
aiDynamic / dayuser_id or IPControlled by config('ai.rate_limit_per_day'). Prevents burning expensive Groq/Llama tokens.
maps10 / minIPProtects the expensive Overpass/Mapbox fan-out endpoints.
weather30 / minIPProtects public external Open-Meteo fetches (SEC-03).
checkout5 / minuser_id or IPPrevents spamming order creation and Paymob Payment Intent exhaustion (SEC-08).
contacts5 / minIPPrevents spamming the public contact database (SEC-03).
newsletter5 / minuser_id or IPPrevents email subscription bombing (NEWS-01).

2. Authentication: The JWT Lifecycle#

Itinera utilizes stateless JSON Web Tokens (via tymon/jwt-auth) to verify identity without maintaining server-side sessions.
Issuance: Tokens are issued exclusively via /api/auth/login and /api/auth/register (using the auth:api guard).
Expiry: Bearer tokens expire strictly after 1 hour.
Rotation & Blacklisting: Users hit /api/auth/refresh to obtain a new token. When refreshed or when the user calls /api/auth/logout, the old token is explicitly Blacklisted in the database/cache. It cannot be used again, severely limiting the window for stolen token abuse.
Refresh Throttling: Token refreshing is implicitly bound to the api_authenticated limiter to prevent excessive token generation.

3. Email Verification Gate#

Before users can access premium resources or finalize agency profiles, they must verify their email.
The Gate: Routes are protected by the verified middleware (pointing to MustVerifyEmail).
Security Rules:
Signed URLs: Verification links are cryptographically signed.
Expiry: Links expire within a strict window (default 60 mins).
No Auto-Trust: Even users signing in via OAuth providers (if enabled) must pass explicit verification if the provider doesn't guarantee the email.
Resend Throttling: To prevent SMS/Email bombing, the /email/verification-notification endpoint is hard-throttled at 1 email per 60 seconds.

4. Authorization: Spatie RBAC Matrix#

Authorization logic is decoupled from Controllers via spatie/laravel-permission.

Roles#

The system operates on four strict roles:
1.
super_admin (Bypasses all Gates implicitly)
2.
admin
3.
agency
4.
user

The Super Admin Override#

In AppServiceProvider::boot(), we register a global Gate::before interceptor. This guarantees that super_admin can always execute actions without needing explicit permission assignments, reducing DB queries and configuration drift:

Route-Level Enforcement#

Permissions are enforced at the routing layer, completely isolating the business logic from authorization concerns. For example:
This guarantees that a standard user can never execute agency functions, even if they manipulate client-side routing.

5. Security Architecture Map#

Modified at 2026-08-25 22:41:45
Previous
Phase 3: Webhooks & Asynchronous Fulfillment
Next
Phase 5: Database Schema & Entity Relationships
Built with