42a388cbe1
- User::login() locks an account for 15 min after 5 failed attempts - CORS now restricted to an explicit origin whitelist instead of * - display_errors disabled in production (errors still logged server-side) - webhook.php now checks Gitea's actual signature header (X-Gitea-Signature, raw hex) instead of GitHub's format, which never matched on this Gitea instance Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
36 lines
1.3 KiB
PHP
Executable File
36 lines
1.3 KiB
PHP
Executable File
<?php
|
|
// webhook.php
|
|
// Déclenché par un webhook GitHub (push sur main) pour resynchroniser le serveur.
|
|
|
|
chdir(__DIR__);
|
|
require_once __DIR__ . '/config/database.php';
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
http_response_code(405);
|
|
exit('Method not allowed');
|
|
}
|
|
|
|
$database = new Database();
|
|
$secret = $database->webhook_secret;
|
|
|
|
$payload = file_get_contents('php://input');
|
|
// Gitea (auto-hébergé) envoie un hex brut dans X-Gitea-Signature, sans préfixe "sha256="
|
|
// (contrairement à GitHub qui utilise X-Hub-Signature-256 avec le préfixe)
|
|
$signatureHeader = $_SERVER['HTTP_X_GITEA_SIGNATURE'] ?? '';
|
|
$expectedSignature = hash_hmac('sha256', $payload, $secret);
|
|
|
|
// Comparaison en temps constant pour éviter les attaques par timing
|
|
if (!$signatureHeader || !hash_equals($expectedSignature, $signatureHeader)) {
|
|
http_response_code(403);
|
|
file_put_contents('webhook.log', date('Y-m-d H:i:s') . " - Tentative refusée (signature invalide)\n", FILE_APPEND);
|
|
exit('Forbidden');
|
|
}
|
|
|
|
// On récupère les modifs et on force l'écrasement pour éviter les conflits
|
|
$output = shell_exec('git fetch origin && git reset --hard origin/main 2>&1');
|
|
|
|
// On logue ça pour vérifier si ça marche (tu pourras voir le contenu dans webhook.log)
|
|
file_put_contents('webhook.log', date('Y-m-d H:i:s') . "\n" . $output . "\n---\n", FILE_APPEND);
|
|
|
|
echo "Sync done.";
|