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

[cve] Migrate jquery.cookie to js.cookie for CVE-2022-23395 #4054

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jsj1001
Copy link

@jsj1001 jsj1001 commented Mar 14, 2025

What changes were proposed in this pull request?

How was this patch tested?

  • Added unit test (desktop/core/src/desktop/js/jest/jsCookieMigration.test.js)
  • Also manually checked js.cookie.js is loaded and works
스크린샷 2025-03-14 오후 12 33 37

Please Remove #4053 PR as it duplicates this PR.

Please review Hue Contributing Guide before opening a pull request.

Copy link

⚠️ No unit test files modified. Please ensure that changes are properly tested. ⚠️

Copy link

github-actions bot commented Mar 14, 2025

Backend Codecov

Backend Code Coverage Report •
FileStmtsMissCoverMissing
TOTAL533132612451% 
report-only-changed-files is enabled. No files were changed during this commit :)

Pytest Report

Tests Skipped Failures Errors Time
1090 107 💤 0 ❌ 0 🔥 5m 53s ⏱️

@jsj1001 jsj1001 changed the title [cve] Migrate jquery jquery.cookie to js.cookie for CVE-2022-23395 [cve] Migrate jquery.cookie to js.cookie for CVE-2022-23395 Mar 16, 2025
Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

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

Looks good! Thanks for contributing to Hue, we always appreciate it :-)

@@ -168,10 +168,10 @@ $(document).ready(function () {
});
});

$("#updateSkipWizard").prop('checked', $.cookie("hueLandingPage", { path: "/" }) == "home");
$("#updateSkipWizard").prop('checked', Cookies.set("hueLandingPage", { path: "/" }) == "home");
Copy link
Collaborator

Choose a reason for hiding this comment

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

This looks incorrect, but so was the old code even before the inline js migration. Lets leave it for this PR.

@jsj1001 jsj1001 force-pushed the jquery-cookie-migration-to-js-cookie branch from 6e3b0ae to 468d0d9 Compare March 19, 2025 08:19
@jsj1001
Copy link
Author

jsj1001 commented Mar 19, 2025

Fixed failed js lint

@jsj1001 jsj1001 requested a review from bjornalm March 19, 2025 08:32
Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

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

This PR installs the js-cookie using the package.json file but also includes it as a static source and load that one as a global variable in hue.mako. I assume the static resource was added since the mako files js are not under webpack control. But I don't think we should be adding two different dependencies for the same library.

Can you try to drop the static import and only use the webpack version if you also import that in hue.js and add it to the global window object? You can look at how we handle legacy usage of lodash (_) there. Then in the mako file you can use window.Cookies and in the js files you can import as normal to avoid the linter errors.

@@ -72,7 +72,8 @@ class DownloadResultModal {

params.executable.toContext(id).then(jsonContext => {
this.cookieId = 'download-' + id;
$.cookie(this.cookieId, null, { expires: -1, path: '/' });
// eslint-disable-next-line no-undef
Cookies.set(this.cookieId, null, { expires: -1, path: '/' });
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing import statement (import Cookies from 'js-cookie'). Once the import is in place you can remove the eslint-disable lines

@@ -0,0 +1,34 @@
import $ from 'jquery';
import 'jquery.cookie';
Copy link
Contributor

Choose a reason for hiding this comment

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

Isn't the goal to remove jquery.cookie?

Comment on lines 1 to 8
/*!
* Javascript Cookie v1.5.1
* https://github.com/js-cookie/js-cookie
*
* Copyright 2006, 2014 Klaus Hartl
* Released under the MIT license
*/
(function (factory) {
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 no need for the static file,

If Cookies needs to be in the global js scope you can import it and set it on the window object in hue.js.

@@ -98,6 +98,7 @@

% if not conf.DEV.get():
<script src="${ static('desktop/js/hue.errorcatcher.js') }"></script>
<script src="${ static('desktop/js/js.cookie.js') }"></script>
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be removed.

package.json Outdated
@@ -162,7 +161,9 @@
"webpack": "5.94.0",
"webpack-bundle-analyzer": "4.10.2",
"webpack-bundle-tracker": "3.1.0",
"webpack-cli": "5.1.4"
"webpack-cli": "5.1.4",
"jquery.cookie": "1.4.1",
Copy link
Contributor

Choose a reason for hiding this comment

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

Remove.

package.json Outdated
"webpack-cli": "5.1.4"
"webpack-cli": "5.1.4",
"jquery.cookie": "1.4.1",
"js-cookie": "1.5.1"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not use the latest? (3.0.5)

@jsj1001 jsj1001 force-pushed the jquery-cookie-migration-to-js-cookie branch from 468d0d9 to 76edd33 Compare March 19, 2025 23:59
Copy link

⚠️ No unit test files modified. Please ensure that changes are properly tested. ⚠️

@jsj1001
Copy link
Author

jsj1001 commented Mar 20, 2025

@bjornalm @JohanAhlen Thank you for reveiw:)
I removed all parts of jquery.cookie and the js.cookie.js static file, using only the Webpack version of js-cookie.
I also updated the js-cookie version.

@jsj1001 jsj1001 requested review from JohanAhlen and bjornalm March 20, 2025 01:55
Copy link
Collaborator

@bjornalm bjornalm left a comment

Choose a reason for hiding this comment

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

This looks good now, thanks!

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.

3 participants