Problem/Motivation
yarn audit shows the following numbers of vulnerabilities on each branch:
- 10.0.x, 9.4.x, and 9.3.x: 18 Moderate | 3 High
- 9.2.x: 24 Moderate | 4 High
Steps to reproduce
- cd core
- yarn install
- yarn audit
Proposed resolution
Not all of the dependency updates can be addressed without increasing our constraints. However, running a yarn upgrade without modifying the constraints gets rid of some of the vulnerabilities, reducing it to:
- 10.0.x, 9.4.x, 9.3.x: 16 Moderate | 1 High
- 9.2.x: 12 Moderate
Let's fix those first (after reviewing that the upgraded versions are safe and testing). Then, let's handle whatever increases we need to make to constraints in followup issues.
Remaining tasks
Address remaining vulnerabilities that require changes to constraints in followup issues.
Followup issue for the acorn/terser dependency workaround: #3264520: Remove acorn from package.json
User interface changes
TBD
API changes
TBD
Data model changes
TBD
Release notes snippet
Drupal core's JavaScript development dependencies have been updated to the latest allowed minor and patch versions to address a few security issues in those dependencies. This should have minimal impact on contributed or custom code and CI workflows. Core developers should completely remove their node_modules directory and re-run yarn install from within the core/ directory.
Additionally, Acorn has temporarily been added as a direct development dependency of core to work around an upstream bug in Terser. Acorn will be removed as a direct dependency again once Terser creates a new release with a fix for the bug.
Issue fork drupal-3262573
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
xjmComment #3
xjmStarting with the 10.0.x version MR...
Comment #4
xjmComment #5
longwaveMaybe a duplicate of
#3258933: [meta] Update JavaScript dependencies for Drupal 10
#3246148: [meta] Update JavaScript dev dependencies to latest major releases before 9.4.0
Comment #7
xjmNot quite a duplicate; the scope in this issue is only ugprades within current constraints (which fixes a few vulns). We're also going to be backporting this all the way to at least 9.3.x and possibly 9.2.x.
Those issues are logical followups though. @lauriii will also be posting individual issues for dealing with a couple of specific dependencies constraining us to insecure versions.
Here's the
yarn-lock-difffor the MR for 10.0.x:Comment #8
xjmComment #9
xjmThe MR is failing with:
...which, like. I have to do that on the CLI all the time, but I don't know how to make Testbot do that.
Comment #10
longwaveOn mobile so can't check for sure but it seems likely this is the same issue as @alexpott had in #3258933: [meta] Update JavaScript dependencies for Drupal 10 as there doesn't seem to have been a new release of terser yet, which has some dependency warning with acorn.
Comment #11
xjmI confirmed that I can reproduce this with the MR:
If I run
yarn check -son 10.0.x HEAD, it outputs even more stuff:... But I guess those are all warnings and not errors.
If I run:
core/scripts/dev/commit-code-check.sh --drupalci...it passes on 10.0.x, but says this on the MR branch:
I guess it's just very catch-all error handling? The
yarn buildfailed, and whatever the reason it failed, it just assumes that it's becauseyarn installwas not run?...Yep, that is exactly what's happening:
So if that upstream issue is what will fix it, are we forced to wait on them to make an upstream release in order to resolve the shelljs vuln etc.? (As far as I can tell, yarn lacks anything like Composer's
--with-dependencies, so I can never get anything to upgrade unless I hit it with the firehose of a fullyarn upgrade.)Comment #12
xjmAdding the acorn issue to the IS.
Comment #13
xjmI was also surprised by just how many files were changed by rerunning
yarn buildafter these upgrades. However, it turns out that the changes also happen on 10.0.x HEAD! My hypothesis is that it's because we dropped support for IE11, but have not yet implemented #3238497: What to do with assets build step?.Of course, that won't apply to 9.4.x, 9.3.x, and 9.2.x, all of which also need to be fixed. And we wouldn't want to commit the updates to 9.4.x before 10.0.x, because that would violate the backport policy... I don't want to block fixing those security vulns on removing the build step, either.
Comment #14
longwaveAdding
acornas an explicit dependency seems to solve the issue, we should be able to remove it again when a new version ofterseris released.Comment #15
longwaveI think the JS changes noted in #13 are due to a bug fix in Babel 7.16, possibly https://github.com/babel/babel/pull/13842 - the input/output in the tests there look similar to the changes here where destructuring is rewritten to go through _ref, and if I take Safari and iOS out of our browser support list, the changes go away.
Comment #16
longwaveAn update to Stylelint also caused a new error: Expected "currentColor" to be "currentcolor" value-keyword-case
Solved with
"camelCaseSvgKeywords": trueas per https://github.com/stylelint/stylelint/issues/5863Comment #20
alexpottI've opened the following issue on github to ask terser for a release - https://github.com/terser/terser/issues/1143 - as I think they've already fixed the issue.
Comment #21
xjmThanks @longwave. Looks like you're right about the Babel bugfix; I must've had a stale
node_modulesand forgotten toyarn installagain after switching branches. Can't reproduce it now.Adding an explicit dependency until there's an upstream release is a great workaround; +1.
Comment #22
alexpottThis looks great. Nice work on explaining why the changes are occurring and keeping the CSS the same.
Comment #23
nod_+1 for RTBC
Changes to the JS are mostly whitespace. Setting the prototype as unwrittable for
Drupal.MessageandDrupal.DatepickerPolyfilldoesn't impact contrib (that I can see) so the change is safe.Comment #24
lauriiiDo we need dependency evaluation for
acorngiven that it's now a direct dev dependency?Comment #25
longwaveUpgrading CSpell means we need to rebuild the dictionary for all branches.
Comment #26
longwaveDictionaries updated.
Comment #27
longwave> Do we need dependency evaluation for acorn given that it's now a direct dev dependency?
I would suggest not, as it was an indirect dependency before, we don't use it directly, and this is hopefully only temporary - once the next version of terser is released we should be able to remove it again.
Comment #28
xjmYeah, in lieu of a dep evaluation, let's file a followup to remove the dep again when upstream is updated.
Comment #29
nod_Babel release a new patch release last week https://github.com/babel/babel/releases/tag/v7.17.2 so MRs needs to be updated. There are a couple of other releases to other dependencies as well but nothing major. I updated the different MRs
Other than that I checked that the compiled js/css didn't change in any meaningful way and that all the commands in the package.json were still working.
9.2 : OK - yarn audit 12 Moderate vulnerabilities (all about regex)
9.3 : OK - yarn audit 16 Moderate | 1 High (same regex stuff as 9.2 + 5 more regex issues from ckeditor deps)
9.4 : OK - yarn audit 16 Moderate | 1 High (same as 9.3)
10.0 : OK - yarn audit 16 Moderate | 1 High (same as 9.3)
I pushed some code but this is RTBC for me.
Comment #30
longwaveI opened #3264520: Remove acorn from package.json as a followup.
I checked each of @nod_'s "yarn upgrade" commits and they all look OK to me with minor/patch level versions only, so I am marking this RTBC alongside the comment above.
Comment #31
xjmUpdated the IS remaining tasks section with the followup issue.
Comment #32
xjmAdded a release note.
Comment #33
longwaveMerged in the head of each branch so the patches apply cleanly.
Comment #34
bnjmnmOn 10.0.x (and perhaps others) Running
yarn vendor-updateresults in changes that should be part of the MR. Setting back to NW for this + rebase will likely be needed due to #3228464: API for contrib projects to load CKEditor translations.Comment #35
longwaveRan
yarn vendor-updateon 9.3.x, 9.4.x and 10.0.x (it doesn't exist in 9.2.x).Comment #37
bnjmnmThanks @longwave! With a small cspell adjustment due to a recent commit, this is good for 10.0.x. I'm committing via Gitlab merge and will continue reviewing for potential commit in descending order.
Comment #39
bnjmnmI made a similar tiny cspell adjustment, which makes 9.4.x fine to commit. On to 9.3!
Comment #40
alexpott@terser is going to get a release on Monday so we should be able to clean this bit of this up quite soon.
Comment #41
xjmWe have #3264520: Remove acorn from package.json for what's already gone in, but it might be worth updating the 9.3.x and 9.2.x MRs before commit so they never have the direct dependency.
Comment #42
alexpott#3264520: Remove acorn from package.json has landed so adding the acorn dependency is no longer necessary.
Comment #43
catchBumping to critical. It would be good to get this in before the next 9.3 patch release.
Comment #45
spokjeTried _really_ hard, but doing a
yarn remove acornonly resulted in the removal of acorn frompackage.jsonon both9.3.xand9.2.x.Comment #46
longwaveAre we allowed to do a
vendor-updatein a patch release? This is end-user-facing JavaScript and here will bump the version of popperjs from 2.10.2 to 2.11.2, and underscore from 1.13.1 to 1.13.2.Comment #47
spokjeAs far as I'm aware I only did a rebase using the GitLab GUI and a
yarn remove acornas shown here.I normally prefer merging the branch into the MR, but was told here #3264122-20: Move all non migration aggregator tests to the module in preparation of removal in d10 rebasing was preferred.
No clue where the updates come from or what I could have done wrong.
Comment #48
longwaveSorry, #46 wasn't a response/question directly to you, more an observation that we upgraded these packages for 9.4.x/10.0.x, but can we safely do that in 9.3.x seeing as we already released 9.3.0 - or should we be more conservative if we aren't fixing security issues? We treat all JS deps as dev dependencies, but popper, underscore, etc are used in the front end of sites, they are only dev dependencies because they are part of our build process.
Comment #49
spokjeAh, no problem, love questions that aren't (directly) directed at me ;)
Comment #50
xjmRebase vs. merge is somewhat moot in an issue like this where we have to re-run build scripts anyway; I would do neither really. The acorn dependency was also never committed to 9.3.x nor 9.2.x, so we should just be able to recreate the MR cleanly without it. Carrying around a bunch of previous commits for it isn't really helpful in this case.
We should be restricting production vendor updates to patch versions in patch releases, but the scope of this issue was intended to include only the dev dependencies and not the vendor update. If the vendor update is happening as part of
yarn run build:js, then that's something we need to file an issue about, I think.Comment #51
xjmDiscussed this with @lauriii and he suggested that we add a constraint in this issue for Popper to keep it restricted to a patch-level update for 9.3.x, and then to re-run the yarn upgrade and the vendor build. (I think it doesn't matter for 9.2.x since the vendor update script wasn't in 9.2 anyway.)
Then, we'll file a followup to add constraints on the production dependencies so we can keep the vendor update consistent but locked to patch versions unless we make an explicit decision to do a minor update in a patch release. Going forward, each minor, we'll deliberately increase constraints to the latest minor version for the production vendor dependencies prior to beta/RC.
Comment #52
xjmWe should probably expand the frontend tools dependency management docs to add more detailed instructions equivalent to the various sections of the core Composer dependency update instructions. There are four total scenarios:
I think it's something like:
HEADof the applicable branch.core/package.json(for production deps) orpackage.json(for dev deps) as appropriate.node_modulesfolder.yarn installfrom within the core directory.yarn build.yarn vendor-update.yarn run spellcheck:make-drupal-dict.Comment #53
xjmI force-pushed the 9.3.x MR with that pattern. Note that I explicitly set the Popper.js constraint to be less than the next minor:
...rather than using
~or similar because this seems the least disruptive: The current constraint is^2.9.2, but the locked/vendor version is2.10.2. We can fix this in a better way in the proposed followup.Comment #54
lauriiiOpened #3266912: Review version constraints for production yarn dependencies to review version constraints for all production dependencies.
Comment #55
catchMR is failing with:
Comment #56
lauriiiLooks like the 9.3.x MR still needs some work. There's a problem with the latest version of
eslint-plugin-reactsince they introduced stricter validation constraints for React version configuration which is currently set to "latest" which isn't a valid semver version. We might have to pin that to 7.29.0 until we have that sorted out.On top of that, there's some changes after running
yarn build:jswhich seem incorrect. For some reason some files are not being built correctly because I can see that the built files haveconst, arrow functions andclasssyntax.Comment #57
longwave#55 seems to be a false positive in
eslint-plugin-react7.29.1 and fixed in 7.29.2. Pushed an upgrade commit to the MR.Also switched from
latesttodetectin the React version, which falls back to latest while emitting a warning that we can hopefully ignore for now.I don't see the changes @lauriii mentions in #56,
yarn buildis clean for me, so back to NR for another look.Comment #58
nod_Same for me build is clean, probably something in the cache that messes things up? to be safe I delete the node_modules directory pretty frequently :)
Backbone has been bumped to 1.4.1 (from 1.4.0) since they had a release a few days ago. Either need to stay on 1.4 or run vendor-update.
Comment #59
longwaveBackbone updated to 1.4.1 in 9.3.x.
Comment #60
nod_let's keep it at 1.4.0 then, and create a new issue to update all the branches at the same time.
Comment #61
longwavePinned Backbone to 1.4.0, ran
yarn vendor-updateagain.Comment #62
longwaveOpened #3267339: Update Backbone to 1.4.1
Comment #63
alexpottRe #61 I think the test fail for backbone 1.4.1 is because we've not updated core/core.libraries.yml to have the correct version - I think to get 9.3.x tests passing on backbone 1.4.1 all we need to do is make similar changes like we're doing for underscore.
Comment #64
nod_The version is hardcoded in a test, backbone was chosen because it doesn't release new versions often i think, so we wouldn't need to update the test often.
Comment #65
longwaveYeah the test fail was this hardcoded in AttachedAssetsTest:
However IMO we should not upgrade Backbone on 9.3.x before we have done 9.4.x/10.0.x so I think deferring to a separate issue where it can be committed to all branches together is better.
Comment #66
nod_Comment #68
bnjmnmCommitted to 9.3.x. 9.2.x currently "Custom commands failed".
Also needs followup per #51 before this can be marked fixed.
Comment #69
longwaveIn the 9.2.x branch we are back to this problem:
Running
yarn upgrade tersermakes it worse somehow:Not sure what the next steps are here.
Comment #70
bnjmnmFrom looking at the terser release notes it seems like it should be safe to lock terser into staying on 5.7.0 in Drupal 9.2 and not concern ourselves with dependency headaches on the version that will be unsupported soonest.
Comment #71
longwaveterser 5.10.0 and above seem to cause the issue so I set package.json to
^5.3.4 <5.10.0which has solved it locally for me.Comment #72
nod_yarn audit returns 9 Moderate vulnerabilites on 9.2.x, there is a babel update but it doesn't change the number of vulnerabilites, so RTBC :)
Thanks!
Comment #73
xjmPosted #3267705: Fix error message when 'yarn check -s' fails in the commit check script for the debug difficulty documented in #11.
Comment #75
bnjmnmCommitted to 9.2.x. I can't mark this fixed until the followup requested in #51 is filed:
Comment #76
longwaveWasn't the followup created in #54? #3266912: Review version constraints for production yarn dependencies
Comment #77
bnjmnmRe #76 @longwave you are correct! Looks like the tag just wasn't removed. Thanks and FIXED!