Skip to content

Commit

Permalink
Uploads: add sanitization
Browse files Browse the repository at this point in the history
  • Loading branch information
dasgarner committed Mar 25, 2024
1 parent 5cea948 commit e4046d8
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lib/Controller/Library.php
Original file line number Diff line number Diff line change
Expand Up @@ -2489,7 +2489,7 @@ public function uploadFromUrl(Request $request, Response $response)
}

// if we were provided with optional Media name set it here, otherwise get it from download info
$name = empty($optionalName) ? $downloadInfo['filename'] : $optionalName;
$name = empty($optionalName) ? htmlspecialchars($downloadInfo['filename']) : $optionalName;

// double check that provided Module Type and Extension are valid
if (!Str::contains($module->getSetting('validExtensions'), $ext)) {
Expand Down
5 changes: 4 additions & 1 deletion lib/Entity/Media.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -575,6 +575,9 @@ private function add()
$fileName = substr(basename($fileName), 0, strpos(basename($fileName), '?'));
}

// Sanitize what we have left.
$fileName = htmlspecialchars($fileName);

$this->mediaId = $this->getStore()->insert('
INSERT INTO `media` (`name`, `type`, duration, originalFilename, userID, retired, moduleSystemFile, released, apiRef, valid, `createdDt`, `modifiedDt`, `enableStat`, `folderId`, `permissionsFolderId`, `orientation`, `width`, `height`)

Check warning on line 582 in lib/Entity/Media.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 246 characters
VALUES (:name, :type, :duration, :originalFileName, :userId, :retired, :moduleSystemFile, :released, :apiRef, :valid, :createdDt, :modifiedDt, :enableStat, :folderId, :permissionsFolderId, :orientation, :width, :height)

Check warning on line 583 in lib/Entity/Media.php

View workflow job for this annotation

GitHub Actions / phpcs

Line exceeds 120 characters; contains 233 characters
Expand Down
6 changes: 3 additions & 3 deletions lib/Helper/LayoutUploadHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -60,9 +60,9 @@ protected function handle_form_data($file, $index)
$params = $sanitizerService->getSanitizer($_REQUEST);

// Parse parameters
$name = $params->getArray('name')[$index];
$name = htmlspecialchars($params->getArray('name')[$index]);
$tags = $controller->getUser()->featureEnabled('tag.tagging')
? $params->getArray('tags')[$index]
? htmlspecialchars($params->getArray('tags')[$index])
: '';
$template = $params->getCheckbox('template', ['default' => 0]);
$replaceExisting = $params->getCheckbox('replaceExisting', ['default' => 0]);
Expand Down
6 changes: 3 additions & 3 deletions lib/Helper/XiboUploadHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright (C) 2023 Xibo Signage Ltd
* Copyright (C) 2024 Xibo Signage Ltd
*
* Xibo - Digital Signage - https://xibosignage.com
*
Expand Down Expand Up @@ -74,9 +74,9 @@ protected function handle_form_data($file, $index)
$controller->getUser()->isQuotaFullByUser(true);

// Get some parameters
$name = $this->getParam($index, 'name', $fileName);
$name = htmlspecialchars($this->getParam($index, 'name', $fileName));
$tags = $controller->getUser()->featureEnabled('tag.tagging')
? $this->getParam($index, 'tags', '')
? htmlspecialchars($this->getParam($index, 'tags', ''))
: '';

// Guess the type
Expand Down

0 comments on commit e4046d8

Please sign in to comment.