diff --git a/api/add_comment.php b/api/add_comment.php index d78be47..33362a7 100644 --- a/api/add_comment.php +++ b/api/add_comment.php @@ -52,9 +52,15 @@ try { if (!CsrfMiddleware::validateToken($csrfToken)) { http_response_code(403); header('Content-Type: application/json'); - echo json_encode(['success' => false, 'error' => 'Invalid CSRF token']); + echo json_encode([ + 'success' => false, + 'error' => 'Invalid CSRF token', + 'csrf_token' => CsrfMiddleware::getToken() + ]); exit; } + // Rotate token after successful validation + $newCsrfToken = CsrfMiddleware::rotateToken(); } $currentUser = $_SESSION['user']; @@ -208,6 +214,9 @@ try { if ($result['success']) { $result['user_name'] = $currentUser['display_name'] ?? $currentUser['username']; $result['user_id'] = $userId; + if (isset($newCsrfToken)) { + $result['csrf_token'] = $newCsrfToken; + } } // Discard any unexpected output diff --git a/api/update_ticket.php b/api/update_ticket.php index c172ec3..de210be 100644 --- a/api/update_ticket.php +++ b/api/update_ticket.php @@ -48,9 +48,14 @@ try { if (!CsrfMiddleware::validateToken($csrfToken)) { http_response_code(403); header('Content-Type: application/json'); - echo json_encode(['success' => false, 'error' => 'Invalid CSRF token']); + echo json_encode([ + 'success' => false, + 'error' => 'Invalid CSRF token', + 'csrf_token' => CsrfMiddleware::getToken() + ]); exit; } + $GLOBALS['newCsrfToken'] = CsrfMiddleware::rotateToken(); } $currentUser = $_SESSION['user']; @@ -279,7 +284,8 @@ try { 'status' => $updateData['status'], 'priority' => $updateData['priority'], 'updated_at' => date('Y-m-d H:i:s'), - 'message' => 'Ticket updated successfully' + 'message' => 'Ticket updated successfully', + 'csrf_token' => $GLOBALS['newCsrfToken'] ?? null ]; } } diff --git a/assets/js/markdown.js b/assets/js/markdown.js index 27bc63a..7bba4ee 100644 --- a/assets/js/markdown.js +++ b/assets/js/markdown.js @@ -41,10 +41,22 @@ function parseMarkdown(markdown) { .replace(/"/g, '"') .replace(/'/g, '''); - // Code blocks (```code```) - preserve content and don't process further + // Code blocks (```lang\ncode\n```) - preserve content and don't process further const codeBlocks = []; - html = html.replace(/```([\s\S]*?)```/g, function(match, code) { - codeBlocks.push('
' + code + '');
+ html = html.replace(/```([a-zA-Z0-9_+-]*)\n?([\s\S]*?)```/g, function(match, lang, code) {
+ lang = lang ? lang.trim() : '';
+ const displayLang = lang || 'text';
+
+ // Build header with optional copy button if one exists in your UI, otherwise just lang
+ const header = '' + code + '