CSRF attacks using JSON payloads
This lab demonstrates CSRF vulnerabilities that can be exploited using JSON payloads. Many modern web applications accept JSON data, and attackers can craft malicious JSON payloads to perform unauthorized actions.
Objective: Use JSON payloads to perform CSRF attacks and bypass traditional form-based protections.
// Vulnerable: No CSRF protection on JSON API
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['json_api'])) {
$json_data = $_POST['json_data'] ?? '';
$decoded_data = json_decode($json_data, true);
// Process JSON data without CSRF validation
$_SESSION['api_data'][] = [
'data' => $decoded_data,
'timestamp' => date('Y-m-d H:i:s')
];
}
// Vulnerable: Profile update via JSON
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['json_profile_update'])) {
$json_profile = $_POST['json_profile'] ?? '';
$decoded_profile = json_decode($json_profile, true);
// Update profile without CSRF validation
$_SESSION['user_profile'] = array_merge($user_profile, $decoded_profile);
}
Username: victim_user
Email: victim@example.com
Role: user
Balance: $1,000.00
No API requests yet.
json_csrf.html - Basic JSON CSRF attackjson_profile_csrf.html - Profile update via JSONjson_transfer_csrf.html - Money transfer via JSONCreate these malicious HTML files to test JSON CSRF attacks: