# amribrahiim/xss-csrf-lab architecture

> Architecture diagram of the GitHub repository amribrahiim/xss-csrf-lab, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-10-05). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/amribrahiim/xss-csrf-lab
- Repository: https://github.com/amribrahiim/xss-csrf-lab

## Overview

This is a local PHP security-training lab demonstrating stored XSS, CSRF protection, and how same-origin script execution can undermine that protection. The principal flow is a user storing a Bio on their profile, another authenticated user viewing it, and the documented script-driven email-change chain; the app also offers a vulnerable email-change comparison. Source excerpts show profile, session, endpoint, and JSON-store behavior. The browser-side attack script is documented but not present in the tree, so that link is shown as unverified.

Main entry points: [`db.php`](https://github.com/amribrahiim/xss-csrf-lab/blob/main/db.php) (User Data Access), [`profile.php`](https://github.com/amribrahiim/xss-csrf-lab/blob/main/profile.php) (Profile View and Edit), [`session.php`](https://github.com/amribrahiim/xss-csrf-lab/blob/main/session.php) (Session and CSRF), [`change_email.php`](https://github.com/amribrahiim/xss-csrf-lab/blob/main/change_email.php) (Protected Email Change)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_identity["Identity and Sessions"]
  node_login["Login<br/>[login.php]"]
  node_session["Session and CSRF<br/>[session.php]"]
end

subgraph group_profile["Profiles and XSS"]
  node_profile["Profile View and Edit<br/>[profile.php]"]
end

subgraph group_email["Email Change"]
  node_protected["Protected Email Change<br/>[change_email.php]"]
  node_unprotected["Unprotected Email Change"]
end

subgraph group_storage["User Storage"]
  node_db["User Data Access<br/>[db.php]"]
  node_users[("User Records<br/>[users.json]")]
end

node_visitor(("User Browser"))
node_attacker(("Attacker"))

node_visitor -->|"submits credentials"| node_login
node_login -->|"sets login session"| node_session
node_login -->|"looks up user"| node_db
node_visitor -->|"views or edits"| node_profile
node_profile -->|"requires login"| node_session
node_profile -->|"reads and updates"| node_db
node_session -->|"loads current user"| node_db
node_db -->|"reads and writes"| node_users
node_visitor -->|"submits email form"| node_protected
node_protected -->|"checks login and token"| node_session
node_protected -->|"updates email"| node_db
node_visitor -->|"submits email form"| node_unprotected
node_unprotected -->|"requires login"| node_session
node_unprotected -->|"updates email"| node_db
node_attacker -->|"stores Bio payload"| node_profile
node_profile -->|"renders raw Bio"| node_visitor
node_visitor -.->|"script obtains token and submits"| node_protected

click node_login "https://github.com/amribrahiim/xss-csrf-lab/blob/main/login.php"
click node_session "https://github.com/amribrahiim/xss-csrf-lab/blob/main/session.php"
click node_profile "https://github.com/amribrahiim/xss-csrf-lab/blob/main/profile.php"
click node_protected "https://github.com/amribrahiim/xss-csrf-lab/blob/main/change_email.php"
click node_unprotected "https://github.com/amribrahiim/xss-csrf-lab/blob/main/change_email_vuln.php"
click node_db "https://github.com/amribrahiim/xss-csrf-lab/blob/main/db.php"
click node_users "https://github.com/amribrahiim/xss-csrf-lab/blob/main/data/users.json"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_login,node_session,node_visitor toneBlue
class node_profile toneAmber
class node_protected,node_unprotected toneMint
class node_db,node_users toneRose
class node_attacker toneIndigo
```

## Components

### Identity and Sessions

- [Login](https://github.com/amribrahiim/xss-csrf-lab/blob/main/login.php): `login.php`
- [Session and CSRF](https://github.com/amribrahiim/xss-csrf-lab/blob/main/session.php): `session.php`

### Profiles and XSS

- [Profile View and Edit](https://github.com/amribrahiim/xss-csrf-lab/blob/main/profile.php): `profile.php`

### Email Change

- [Protected Email Change](https://github.com/amribrahiim/xss-csrf-lab/blob/main/change_email.php): `change_email.php`
- [Unprotected Email Change](https://github.com/amribrahiim/xss-csrf-lab/blob/main/change_email_vuln.php): `change_email_vuln.php`

### User Storage

- [User Data Access](https://github.com/amribrahiim/xss-csrf-lab/blob/main/db.php): `db.php`
- [User Records](https://github.com/amribrahiim/xss-csrf-lab/blob/main/data/users.json): `data/users.json`

### Other components

- **User Browser**
- **Attacker**

## Connections

- User Browser → Login: submits credentials (evidence: `login.php`)
- Login → Session and CSRF: sets login session (evidence: `login.php`)
- Login → User Data Access: looks up user (evidence: `login.php`)
- User Browser → Profile View and Edit: views or edits (evidence: `profile.php`)
- Profile View and Edit → Session and CSRF: requires login (evidence: `profile.php`)
- Profile View and Edit → User Data Access: reads and updates (evidence: `profile.php`)
- Session and CSRF → User Data Access: loads current user (evidence: `session.php`)
- User Data Access → User Records: reads and writes (evidence: `db.php`)
- User Browser → Protected Email Change: submits email form (evidence: `change_email.php`)
- Protected Email Change → Session and CSRF: checks login and token (evidence: `change_email.php`)
- Protected Email Change → User Data Access: updates email (evidence: `change_email.php`)
- User Browser → Unprotected Email Change: submits email form (evidence: `change_email_vuln.php`)
- Unprotected Email Change → Session and CSRF: requires login (evidence: `change_email_vuln.php`)
- Unprotected Email Change → User Data Access: updates email (evidence: `change_email_vuln.php`)
- Attacker → Profile View and Edit: stores Bio payload (evidence: `README.md`)
- Profile View and Edit → User Browser: renders raw Bio (evidence: `profile.php`)
- User Browser → Protected Email Change: script obtains token and submits (evidence: `README.md`)
