Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes security issue with upload and limits filetypes accepted #18

Merged
merged 2 commits into from
Oct 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions scormcloud/admin/file_upload_parser.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@
mkdir($uploadDirectoryName, 0755);
}

$token = $_POST["token"];
if (!$token || $token !== $_SESSION['token']) {
// show an error message
echo '<p class="error">Error: invalid form submission </p>';
// 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
Expand Down
8 changes: 5 additions & 3 deletions scormcloud/admin/uploadpif.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@
}
require_once ABSPATH . 'wp-admin/includes/admin.php';

// define( 'SCORMCLOUD_BASE', '../' );

require_once SCORMCLOUD_BASE . 'scormcloudplugin.php';
$scorm_service = ScormCloudPlugin::get_cloud_service();

Expand All @@ -24,6 +22,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));

?>
<link rel="stylesheet" href="../css/scormcloud.admin.css" />
<script>
Expand All @@ -36,6 +36,7 @@ function uploadFile(){
var formdata = new FormData();
formdata.append("file1", file);
formdata.append("courseid", "<?=$id?>");
formdata.append("token", "<?= $_SESSION['token'] ?? '' ?>");
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.addEventListener("load", completeHandler, false);
Expand Down Expand Up @@ -66,10 +67,11 @@ function abortHandler(event){
<td>
<form id="upload_form" enctype="multipart/form-data" method="post">
<h5>Choose ZIP/MP3/MP4/PDF File</h5>
<input type="file" name="file1" id="file1" ><br>
<input type="file" name="file1" id="file1" accept="application/zip, video/mp4, audio/mp3, application/pdf"><br>
<input type="button" id="submit" value="Upload File" onclick="uploadFile()">
<input type="hidden" value="<?=$id?>" name="courseId" id="courseId">
<span class="importMessage" style="display:none;"><?=__("Importing Package......", "scormcloud")?></span>
<input type="hidden" name="token" value="<?= $_SESSION['token'] ?? '' ?>">
<h3 id="status"></h3>
<p id="loaded_n_total"></p>
</form>
Expand Down
10 changes: 9 additions & 1 deletion scormcloud/readme.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Contributors: troyef, stuartchilds, timedwards, brianrogers
Tags: elearning, learning, scorm, aicc, education, training, cloud
Requires at least: 4.3
Tested up to: 5.8
Stable tag: 2.0.1
Stable tag: 2.0.2

Tap the power of SCORM to deliver and track training right from your WordPress-powered site.

Expand Down Expand Up @@ -48,6 +48,9 @@ The SCORM Cloud For WordPress basic functionality works with BuddyPress without


== Changelog ==
= 2.0.2 =
* Fixes security issues with upload form.

= 2.0.1 =
* Fixes bug with updating Learner info.

Expand All @@ -56,6 +59,7 @@ The SCORM Cloud For WordPress basic functionality works with BuddyPress without

= 1.2.3 =
* Fixed bug in course catalog widget
* Final update for v1 API

= 1.2.2 =
* Fixed bug in anonymous registrations
Expand Down Expand Up @@ -159,6 +163,9 @@ The SCORM Cloud For WordPress basic functionality works with BuddyPress without
* Original Release.

== Upgrade Notice ==
= 2.0.2 =
* Fixes security issues with upload form.

= 2.0.1 =
* Fixes bug with updating Learner info.

Expand All @@ -171,6 +178,7 @@ The SCORM Cloud For WordPress basic functionality works with BuddyPress without
* Updates Training View
* Updates to synching learner information
* Updates to shortcode management
* Last update with v1 API

= 1.1.8 =
* Adding proxy support
Expand Down
2 changes: 1 addition & 1 deletion scormcloud/scormcloud.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
Plugin URI: http://scorm.com/wordpress
Description: Tap the power of SCORM to deliver and track training right from your WordPress-powered site. Just add the SCORM Cloud widget to the sidebar or use the SCORM Cloud button to add a link directly in a post or page.
Author: Rustici Software
Version: 2.0.1
Version: 2.0.2
Author URI: http://www.scorm.com
*/

Expand Down
7 changes: 7 additions & 0 deletions scormcloud/scormcloudcontenthandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -232,4 +232,11 @@ public static function update_learner_info( $user_id ) {
write_log( "profile update skipped for {$user_data->user_email} due to missing first or last name" );
}
}

/**
* Make sure the session is started and available
*/
public static function boot_session() {
session_start();
}
}
6 changes: 4 additions & 2 deletions scormcloud/scormcloudplugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,10 @@ public static function initialize() {

add_action( 'save_post', array( 'ScormCloudContentHandler', 'update_post_invite' ) );
add_action( 'profile_update', array( 'ScormCloudContentHandler', 'update_learner_info' ) );

add_action('wp_loaded',array( 'ScormCloudContentHandler','boot_session'));
}

/**
* Check for updates.
*/
Expand Down Expand Up @@ -95,7 +97,7 @@ public static function get_cloud_service( $force_network_settings = false ) {
$proxy = get_option( 'proxy' );
}

$origin = ScormEngineUtilities::getCanonicalOriginString( 'Rustici Software', 'WordPress', '2.0.1' );
$origin = ScormEngineUtilities::getCanonicalOriginString( 'Rustici Software', 'WordPress', '2.0.2' );

if ( strlen( $engine_url ) < 1 ) {
$engine_url = 'https://cloud.scorm.com/api/v2';
Expand Down