-
Notifications
You must be signed in to change notification settings - Fork 447
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
pkp/pkp-lib#9753 [stable-3_3_0] Update jquery, jquery-ui and chart.js to address security vulnerability reports #10167
Conversation
|
7d25292
to
9dbfc07
Compare
9952819
to
454635a
Compare
454635a
to
07913a6
Compare
classes/dev/ComposerScript.php
Outdated
function copyDir($src, $dst) { | ||
$dir = opendir($src); | ||
@mkdir($dst, 0755, true); | ||
while (false !== ($file = readdir($dir))) { | ||
if ($file != '.' && $file != '..') { | ||
if (is_dir($src . '/' . $file)) { | ||
copyDir($src . '/' . $file, $dst . '/' . $file); | ||
} else { | ||
copy($src . '/' . $file, $dst . '/' . $file); | ||
} | ||
} | ||
} | ||
closedir($dir); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you might use existing code to copy the directory, it will also have better permission defaults:
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$fileManager->copyDir($source, $destiny);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @jonasraoni , thanks for checking this. I tried to implement your suggestion, but I'm running to lots of issues with importing the FileManager. When I run the composer install
, I'm getting lots of "not found" errors so I did something like this when testing the use of FileManager:
require_once './includes/bootstrap.inc.php';
require_once './tools/core/Core.inc.php';
require_once './classes/core/Core.inc.php';
require_once './classes/config/Config.inc.php';
require_once './classes/file/FileManager.inc.php';
$fileManager = new \FileManager();
Finally, I run to an issue where the constant "INDEX_FILE_LOCATION" is undefined. As I check, this is defined on the app level of OJS/OMP/OPS.
I noticed a comment from this file ComposerScript.php from the main branch, that we did not use "Core::getBaseDir()" because the script is being called directly by composer and that "INDEX_FILE_LOCATION" is expected to be undefined. Would you be able to provide further guidance on this? Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably work:
require_once './tools/bootstrap.inc.php';
import('lib.pkp.classes.file.FileManager');
$fileManager = new FileManager();
$fileManager->copyDir('source', 'destiny');
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This worked, thank you! I updated the script to use FileManager, please check. Thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To not cause side-effects, the return true;
should be probably modified to return false;
.
Or modified to return $this->setMode($dirPath, DIRECTORY_MODE_MASK);
to honor the expectations of the caller.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually think it would be better not to use FileManager
, since this is code that's run upon Composer dependency installation, long before there's a config.inc.php
configuration file. FileManager
expects the OJS bootstrapping process to be present, and it won't be.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks both, I updated the script to not use FileManager.
classes/dev/ComposerScript.php
Outdated
} catch (Exception $e) { | ||
error_log($e->getMessage()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's better to let the code fail, it's important that the user get this working properly and a simple warning might be ignored.
classes/dev/ComposerScript.php
Outdated
// jQuery UI | ||
if (!file_exists($vendorComponents . '/jqueryui')) { | ||
mkdir($vendorComponents . '/jqueryui', 0755, true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed if you use the FileManager
.
classes/dev/ComposerScript.php
Outdated
if (!file_exists($jqueryPluginsDir . '/validate')) { | ||
mkdir($jqueryPluginsDir . '/validate', 0755, true); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can be removed if you use the FileManager
.
composer.lock
Outdated
@@ -7746,5 +7686,5 @@ | |||
"platform-overrides": { | |||
"php": "7.3.0" | |||
}, | |||
"plugin-api-version": "2.3.0" | |||
"plugin-api-version": "2.6.0" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if this might cause compatibility issues, it sounds safer to leave the old value.
classes/dev/ComposerScript.php
Outdated
copy($jqueryUiDist . '/jquery-ui.js', $vendorComponents . '/jqueryui/jquery-ui.js'); | ||
copy($jqueryUiDist . '/jquery-ui.min.js', $vendorComponents . '/jqueryui/jquery-ui.min.js'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's a FileManager::copyFile()
too, which will also setup permissions.
…n to composer dependencies
…validation paths
…unning composer install
07913a6
to
d1d12c0
Compare
classes/dev/ComposerScript.php
Outdated
]; | ||
|
||
// jQuery UI | ||
$fileManager->copyFile($source['jquery-ui.js'], $dest['jquery-ui.js']) || throw new Exception('Failed to copy jquery-ui.js to destination folder'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just tagging @asmecher to confirm if it's ok this breaking change, regarding the required permissions (https://docs.pkp.sfu.ca/admin-guide/en/troubleshooting#configuring-file-permissions).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This script is run by Composer during dependency installation, not when OJS is installed and in production. For the most part, it'll be run from the package build script when I build a release, and for folks that host OJS from git it'll be run early in the installation process from the same terminal that's used to e.g. clone the code into place. I don't think the production file permission document is relevant. (This is also why I recommended not using FileManager
-- it's intended for execution in the bootstrapped PKP environment, not elsewhere.)
For v3.3.0, we need to:
Notes:
components/jquery
and removedcomponents/jqueryui
since the newer version is not available through Composer. We then added jquery-ui and jquery-validate as custom repositories in Composer, sourcing them from npm registry tar files.