Skip to content

Commit

Permalink
Validate PDF files with dangerous content
Browse files Browse the repository at this point in the history
  • Loading branch information
danloa committed Sep 3, 2024
1 parent 05b7b6a commit 2beddf2
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions ProcessMaker/Http/Controllers/Api/ProcessRequestFileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,12 @@ public function store(Request $laravel_request, FileReceiver $receiver, ProcessR
*/
private function saveUploadedFile(UploadedFile $file, ProcessRequest $processRequest, Request $laravelRequest)
{
$errors = [];
$this->validateFile($file, $errors);
if (count($errors) > 0) {
return abort(response($errors , 422));
}

$parentId = $processRequest->parent_request_id;
$parentRequest = $processRequest;

Expand Down Expand Up @@ -411,4 +417,29 @@ public function destroy(Request $laravel_request, ProcessRequest $request, $file

return response([], 204);
}

private function validateFile(UploadedFile $file, &$errors)
{
if (strtolower($file->getClientOriginalExtension() === 'pdf')) {
$this->validatePDFFile($file, $errors);
}

return $errors;
}

private function validatePDFFile(UploadedFile $file, &$errors)
{
$text = $file->get();

$jsKeywords = ['/JavaScript', '/JS', '<< /S /JavaScript'];

foreach ($jsKeywords as $keyword) {
if (strpos($text, $keyword) !== false) {
$errors[] = __('Dangerous PDF file content.');
break;
}
}

return $errors;
}
}

0 comments on commit 2beddf2

Please sign in to comment.