From c6ec81174ce04edc2a8ac396e1ef2489e809130a Mon Sep 17 00:00:00 2001 From: Jonas Kohl Date: Thu, 7 Nov 2024 16:19:33 +0100 Subject: CSRF tokens --- public/index.php | 101 +++++++++++++++---------------------------------------- public/site.js | 80 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 107 insertions(+), 74 deletions(-) create mode 100644 public/site.js diff --git a/public/index.php b/public/index.php index 6e0a8fb..0b3cabc 100644 --- a/public/index.php +++ b/public/index.php @@ -1,5 +1,12 @@ false, + "message" => "CSRF token mismatch", + "csrf" => csrf_token(), + ]); + exit; + } $srcDir = __DIR__ . "/../_runners/$id/src"; @@ -44,17 +63,21 @@ if (isset($_POST["code"]) && strlen($_POST["code"]) <= 16383) { $resultStr = shell_exec("./compile-and-run.sh '$id' Program 2>/dev/null"); chdir(__DIR__); + $csrf = csrf_token(); + if (is_string($resultStr)) { $result = json_decode($resultStr, true); $result["runner"] = $id; + $result["ok"] = true; + $result["csrf"] = $csrf; } - - header("Content-Type: application/json"); echo json_encode($result); exit; } +$csrf = csrf_token(); + ?> @@ -68,6 +91,7 @@ if (isset($_POST["code"]) && strlen($_POST["code"]) <= 16383) { +