mirror of
https://git.hexahost.dev/smueller/HexaHost-Frontend.git
synced 2026-06-02 06:58:43 +00:00
Implement CSRF protection in contact form: Added session management and CSRF token validation to enhance security. Updated AJAX response handling in JavaScript to reset button state after submission.
This commit is contained in:
@@ -77,6 +77,10 @@
|
|||||||
})
|
})
|
||||||
.then(response => response.json())
|
.then(response => response.json())
|
||||||
.then(data => {
|
.then(data => {
|
||||||
|
// Reset button state
|
||||||
|
submitBtn.textContent = originalText;
|
||||||
|
submitBtn.disabled = false;
|
||||||
|
|
||||||
if (data.success) {
|
if (data.success) {
|
||||||
// Reset form
|
// Reset form
|
||||||
form.reset();
|
form.reset();
|
||||||
|
|||||||
@@ -4,12 +4,22 @@
|
|||||||
* E-Mail-Verarbeitung mit SMTP-Integration und Spam-Schutz
|
* E-Mail-Verarbeitung mit SMTP-Integration und Spam-Schutz
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Session starten für CSRF-Validierung
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
// Konfiguration laden
|
// Konfiguration laden
|
||||||
require_once 'config.php';
|
require_once 'config.php';
|
||||||
|
|
||||||
// Konfiguration verwenden
|
// Konfiguration verwenden
|
||||||
$config = getHexaHostConfig();
|
$config = getHexaHostConfig();
|
||||||
|
|
||||||
|
// CSRF-Token validieren
|
||||||
|
function validateCSRFToken($token) {
|
||||||
|
return isset($_SESSION['csrf_token']) && hash_equals($_SESSION['csrf_token'], $token);
|
||||||
|
}
|
||||||
|
|
||||||
// CORS Headers für AJAX-Requests
|
// CORS Headers für AJAX-Requests
|
||||||
header('Access-Control-Allow-Origin: *');
|
header('Access-Control-Allow-Origin: *');
|
||||||
header('Access-Control-Allow-Methods: POST');
|
header('Access-Control-Allow-Methods: POST');
|
||||||
@@ -329,6 +339,16 @@ function generateEmailText($data) {
|
|||||||
|
|
||||||
// Hauptverarbeitung
|
// Hauptverarbeitung
|
||||||
try {
|
try {
|
||||||
|
// CSRF-Token validieren
|
||||||
|
if (empty($_POST['csrf_token']) || !validateCSRFToken($_POST['csrf_token'])) {
|
||||||
|
http_response_code(403);
|
||||||
|
echo json_encode([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Ungültige Sitzung. Bitte laden Sie die Seite neu und versuchen Sie es erneut.'
|
||||||
|
]);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Rate Limiting Check
|
// Rate Limiting Check
|
||||||
$client_ip = $_SERVER['REMOTE_ADDR'];
|
$client_ip = $_SERVER['REMOTE_ADDR'];
|
||||||
if (!checkRateLimit($client_ip)) {
|
if (!checkRateLimit($client_ip)) {
|
||||||
|
|||||||
@@ -3,6 +3,11 @@
|
|||||||
* Helper functions for HexaHost.de
|
* Helper functions for HexaHost.de
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
// Start session for CSRF token
|
||||||
|
if (session_status() === PHP_SESSION_NONE) {
|
||||||
|
session_start();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set page configuration and include header
|
* Set page configuration and include header
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user