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

pkp/pkp-lib#9753 [stable-3_3_0] Update jquery, jquery-ui and chart.js to address security vulnerability reports #10167

Merged
merged 24 commits into from
Sep 5, 2024

Conversation

blesildaramirez
Copy link
Contributor

@blesildaramirez blesildaramirez commented Jul 5, 2024

For v3.3.0, we need to:

Notes:

  1. My investigation indicates that there are no breaking changes in the upgrades for jQuery, jQuery UI, and jQuery Validation.
  2. In Composer, we updated the version of components/jquery and removed components/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.
  3. We copied these Composer repository installs to the existing paths for the mentioned dependencies, so changing the paths when adding these scripts in the frontend is NOT necessary for pkp:v3.3.0
  4. Usage statistics that use Chart JS is not yet implemented in v3.3, so there's no need to do a version upgrade of this on the frontend.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Comment on lines 28 to 41
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);
}
Copy link
Contributor

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);

Copy link
Contributor Author

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!

Copy link
Contributor

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');

Copy link
Contributor Author

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!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I needed to update the FileManager file for 3.3 - specifically on the mkdir function:
image

I added this because when I re-run the composer install (with already copied files), I get an error from php saying:
image

Weirdly, I don't get this error on 3.4 so I didn't change the FileManager file for 3.4.

Copy link
Contributor

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.

Copy link
Member

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.

Copy link
Contributor Author

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.

Comment on lines 66 to 58
} catch (Exception $e) {
error_log($e->getMessage());
}
Copy link
Contributor

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.

composer.json Show resolved Hide resolved
Comment on lines 53 to 89
// jQuery UI
if (!file_exists($vendorComponents . '/jqueryui')) {
mkdir($vendorComponents . '/jqueryui', 0755, true);
}
Copy link
Contributor

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.

Comment on lines 61 to 97
if (!file_exists($jqueryPluginsDir . '/validate')) {
mkdir($jqueryPluginsDir . '/validate', 0755, true);
}
Copy link
Contributor

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"
Copy link
Contributor

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.

Comment on lines 57 to 58
copy($jqueryUiDist . '/jquery-ui.js', $vendorComponents . '/jqueryui/jquery-ui.js');
copy($jqueryUiDist . '/jquery-ui.min.js', $vendorComponents . '/jqueryui/jquery-ui.min.js');
Copy link
Contributor

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.

];

// jQuery UI
$fileManager->copyFile($source['jquery-ui.js'], $dest['jquery-ui.js']) || throw new Exception('Failed to copy jquery-ui.js to destination folder');
Copy link
Contributor

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).

Copy link
Member

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.)

@asmecher asmecher merged commit b12d2ef into pkp:stable-3_3_0 Sep 5, 2024
1 check was pending
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants