Missing CSRF protection on sensitive actions
This lab demonstrates a basic CSRF vulnerability where sensitive actions like profile updates, money transfers, and password changes lack proper CSRF protection. An attacker can trick a user into performing these actions without their knowledge.
Objective: Create malicious HTML forms or use other techniques to perform unauthorized actions on behalf of the victim user.
// Vulnerable: No CSRF protection
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['update_profile'])) {
$username = $_POST['username'] ?? $user_profile['username'];
$email = $_POST['email'] ?? $user_profile['email'];
// Update profile without CSRF token validation
$_SESSION['user_profile'] = [
'username' => $username,
'email' => $email,
// ... other fields
];
}
// Vulnerable: Money transfer without CSRF protection
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['transfer_money'])) {
$amount = (float)($_POST['amount'] ?? 0);
$recipient = $_POST['recipient'] ?? '';
// Process transfer without CSRF validation
$_SESSION['user_profile']['balance'] -= $amount;
}
Username: victim_user
Email: victim@example.com
Role: user
Balance: $1,000.00
Phone: +1-555-0123
Address: 123 Main St, City, State
Create these malicious HTML files to test CSRF:
profile_csrf.html - Profile update attacktransfer_csrf.html - Money transfer attackpassword_csrf.html - Password change attackCreate these malicious HTML files to test CSRF attacks: