From 45a6c50783c8843f19c3007fe6b6d901eb075aa3 Mon Sep 17 00:00:00 2001 From: Brian Rogers Date: Tue, 19 Oct 2021 12:35:25 -0700 Subject: [PATCH 1/2] fixes security issue with upload and limits filetypes accepted --- scormcloud/admin/file_upload_parser.php | 10 ++++++++++ scormcloud/admin/uploadpif.php | 5 ++++- scormcloud/readme.txt | 10 +++++++++- scormcloud/scormcloud.php | 2 +- scormcloud/scormcloudplugin.php | 2 +- 5 files changed, 25 insertions(+), 4 deletions(-) diff --git a/scormcloud/admin/file_upload_parser.php b/scormcloud/admin/file_upload_parser.php index 956a017..c7d388e 100644 --- a/scormcloud/admin/file_upload_parser.php +++ b/scormcloud/admin/file_upload_parser.php @@ -21,6 +21,16 @@ mkdir($uploadDirectoryName, 0755); } +$token = filter_input(INPUT_POST, 'token', FILTER_SANITIZE_STRING); + +if (!$token || $token !== $_SESSION['token']) { + // show an error message + echo '

Error: invalid form submission

'; + // return 405 http status code + header($_SERVER['SERVER_PROTOCOL'] . ' 405 Method Not Allowed'); + exit; +} + $fileName = $_FILES["file1"]["name"]; // The file name $fileTmpLoc = $_FILES["file1"]["tmp_name"]; // File in the PHP tmp folder $fileType = $_FILES["file1"]["type"]; // The type of file it is diff --git a/scormcloud/admin/uploadpif.php b/scormcloud/admin/uploadpif.php index 34c4fb2..0d8eadf 100644 --- a/scormcloud/admin/uploadpif.php +++ b/scormcloud/admin/uploadpif.php @@ -24,6 +24,8 @@ $basepath = $protocol . '://' . $_SERVER['HTTP_HOST'] . substr($_SERVER['REQUEST_URI'], 0, strpos($_SERVER['REQUEST_URI'], 'scormcloud')) . 'scormcloud/'; $import_callback = $basepath . '/importcallback.php'; +$_SESSION['token'] = bin2hex(random_bytes(35)); + ?>