From 8969eb4071dd80ce13b822e3b7267c3e05ee8b14 Mon Sep 17 00:00:00 2001 From: Floorb <132411956+Neetpone@users.noreply.github.com> Date: Wed, 14 Jun 2023 03:00:04 -0400 Subject: [PATCH] fix: better fix for encryption issue --- public/index.php | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/public/index.php b/public/index.php index 38ae4ae..a5a36a2 100644 --- a/public/index.php +++ b/public/index.php @@ -126,17 +126,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { $paste_password = password_hash($paste_password, PASSWORD_DEFAULT); } - // If it's a new paste or the existing paste is encrypted, encrypt the paste - // This is to prevent legacy pastes from getting weird - if ($editing && !$paste->encrypt) { - $paste_content = $_POST['paste_data']; - } else { - $paste_content = openssl_encrypt( - $_POST['paste_data'], - PP_ENCRYPTION_ALGO, - PP_ENCRYPTION_KEY - ); - } + $paste_content = openssl_encrypt( + $_POST['paste_data'], + PP_ENCRYPTION_ALGO, + PP_ENCRYPTION_KEY + ); // Set expiry time $expires = calculatePasteExpiry($p_expiry); @@ -145,6 +139,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { if ($editing) { $paste = Paste::find($_POST['paste_id']); if (can('edit', $paste)) { + $paste_content = $paste->encrypt ? $paste_content : $_POST['paste_data']; $paste->update([ 'title' => $paste_title, 'content' => $paste_content, @@ -153,7 +148,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') { 'expiry' => $expires, 'password' => $paste_password, 'updated_at' => date_create(), - 'ip' => $ip + 'ip' => $ip, + 'encrypt' => true ]); $paste->replaceTags($tags);