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

Fix: Exclude devDependencies from attribution.txt #8862

Merged
merged 3 commits into from
Mar 13, 2024

Conversation

Gudahtt
Copy link
Member

@Gudahtt Gudahtt commented Mar 6, 2024

Description

The generated file attribution.txt was intended to exclude all devDependencies, but a few snuck their way in anyway. The build:attribution script we use to generate that file has been updated to ensure that devDependencies are excluded.

The old script was deleting devDependencies from package.json in an attempt to exclude them, but this wasn't working properly because the package we use to find all licenses was looking on-disk for them, not walking through the dependency graph starting at our manifest.

The script now explicitly deletes node_modules and re-installs with only production dependencies, so they are the only ones present on-disk for the license checker to find.

The script now leaves the project in a state where only production dependencies are installed, so a reminder to run yarn setup was added to the end of the script

Related issues

Fixes https://github.com/MetaMask/MetaMask-planning/issues/2182

Manual testing steps

  • Run yarn build:attribution
  • See that acorn-jsx is not included (this is an example dependency of a devDependency that was included previously)
  • Remember to re-run yarn setup after testing

Screenshots/Recordings

N/A

Pre-merge author checklist

  • I’ve followed MetaMask Coding Standards.
  • I've clearly explained what problem this PR is solving and how it is solved.
  • I've linked related issues
  • I've included manual testing steps
  • I've included screenshots/recordings if applicable
  • I’ve included tests if applicable
  • I’ve documented my code using JSDoc format if applicable
  • I’ve applied the right labels on the PR (see labeling guidelines). Not required for external contributors.
  • I’ve properly set the pull request status:
    • In case it's not yet "ready for review", I've set it to "draft".
    • In case it's "ready for review", I've changed it from "draft" to "non-draft".

Pre-merge reviewer checklist

  • I've manually tested the PR (e.g. pull and build branch, run the app, test code being changed).
  • I confirm that this PR addresses all acceptance criteria described in the ticket it closes and includes the necessary testing evidence such as recordings and or screenshots.

@Gudahtt Gudahtt force-pushed the fix-attribution-generation branch from 0487b0a to 602010f Compare March 6, 2024 14:09
Copy link

socket-security bot commented Mar 6, 2024

Copy link

socket-security bot commented Mar 6, 2024

👍 Dependency issues cleared. Learn more about Socket for GitHub ↗︎

This PR previously contained dependency changes with security issues that have been resolved, removed, or ignored.

Ignoring: npm/@lavamoat/aa@3.1.5, npm/@lavamoat/allow-scripts@2.5.1, npm/@lavamoat/preinstall-always-fail@2.0.0, npm/@npmcli/fs@2.1.2, npm/@npmcli/move-file@2.0.1, npm/cmd-shim@6.0.2, npm/dezalgo@1.0.4, npm/json-parse-even-better-errors@3.0.1, npm/node-gyp@9.4.1, npm/unique-slug@3.0.0

View full report↗︎

Next steps

Take a deeper look at the dependency

Take a moment to review the security alert above. Review the linked package source code to understand the potential risk. Ensure the package is not malicious before proceeding. If you're unsure how to proceed, reach out to your security team or ask the Socket team for help at support [AT] socket [DOT] dev.

Remove the package

If you happen to install a dependency that Socket reports as Known Malware you should immediately remove it and select a different dependency. For other alert types, you may may wish to investigate alternative packages or consider if there are other ways to mitigate the specific risk posed by the dependency.

Mark a package as acceptable risk

To ignore an alert, reply with a comment starting with @SocketSecurity ignore followed by a space separated list of ecosystem/package-name@version specifiers. e.g. @SocketSecurity ignore npm/foo@1.0.0 or ignore all packages with @SocketSecurity ignore-all

@Gudahtt Gudahtt force-pushed the fix-attribution-generation branch from 602010f to c40b13e Compare March 6, 2024 14:13
@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 6, 2024

@SocketSecurity ignore npm/@lavamoat/aa@3.1.5
@SocketSecurity ignore npm/@lavamoat/allow-scripts@2.5.1

These are our packages

@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 6, 2024

@SocketSecurity ignore npm/@npmcli/move-file@2.0.1

This deprecated package is used by an abandoned package, difficult to replace

@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 6, 2024

@SocketSecurity ignore npm/dezalgo@1.0.4
@SocketSecurity ignore npm/@npmcli/fs@2.1.2
@SocketSecurity ignore npm/unique-slug@3.0.0

These "new author" alerts are from releases ~2 years old, where the new author appears to be the current maintainer

@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 6, 2024

@SocketSecurity ignore npm/@lavamoat/preinstall-always-fail@2.0.0

This is our package

@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 6, 2024

@SocketSecurity ignore npm/cmd-shim@6.0.2
@SocketSecurity ignore npm/node-gyp@9.4.1
@SocketSecurity ignore npm/json-parse-even-better-errors@3.0.1

These new authors appear to be an npm bot and a maintainer

@Gudahtt Gudahtt marked this pull request as ready for review March 6, 2024 14:41
@Gudahtt Gudahtt requested a review from a team as a code owner March 6, 2024 14:41
@Gudahtt Gudahtt added the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Mar 6, 2024
@github-actions github-actions bot added the Run Smoke E2E Triggers smoke e2e on Bitrise label Mar 6, 2024
Copy link
Contributor

github-actions bot commented Mar 6, 2024

https://bitrise.io/ Bitrise

✅✅✅ pr_smoke_e2e_pipeline passed on Bitrise! ✅✅✅

Commit hash: c40b13e
Build link: https://app.bitrise.io/app/be69d4368ee7e86d/pipelines/c6e0cfac-6316-469c-b057-f92fde02fe61

Note

  • You can kick off another pr_smoke_e2e_pipeline on Bitrise by removing and re-applying the Run Smoke E2E label on the pull request

@codecov-commenter
Copy link

codecov-commenter commented Mar 6, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 43.27%. Comparing base (bdba039) to head (66ce82c).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #8862   +/-   ##
=======================================
  Coverage   43.27%   43.27%           
=======================================
  Files        1271     1271           
  Lines       30916    30916           
  Branches     3092     3092           
=======================================
  Hits        13378    13378           
  Misses      16765    16765           
  Partials      773      773           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

mcmire
mcmire previously approved these changes Mar 7, 2024
Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

When I run the script on my computer I see different results for attributions.txt. It seems that fsevents gets added, @parcel/watcher-linux-x64-glibc gets removed, and @parcel/watcher-linux-x64-musl is replaced with @parcel/watcher-darwin-arm64. This makes sense to be as these changes are most likely due to a different platform (macOS). If this script is only intended to be run in CI, then that seems fine.

Regardless, I did not see any dev dependencies.

scripts/generate-attributions.sh Outdated Show resolved Hide resolved
@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 8, 2024

This makes sense to be as these changes are most likely due to a different platform (macOS). If this script is only intended to be run in CI, then that seems fine.

Exactly, this script will only be run on CI typically, so I think having platform differences in output is OK in this case

Copy link
Contributor

@mcmire mcmire left a comment

Choose a reason for hiding this comment

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

LGTM!

Gudahtt and others added 3 commits March 13, 2024 14:49
The generated file `attribution.txt` was intended to exclude all
`devDependencies`, but a few snuck their way in anyway. The
`build:attribution` script we use to generate that file has been
updated to ensure that `devDependencies` are excluded.

The old script was deleting `devDependencies` from `package.json` in
an attempt to exclude them, but this wasn't working properly because
the package we use to find all licences was looking on-disk for them,
not walking through the dependency graph starting at our manifest.

The script now explicitly deletes `node_modules` and re-installs with
only production dependencies, so they are the only ones present on-disk
for the license checker to find.

The script now leaves the project in a state where only production
dependencies are installed, so a reminder to run `yarn setup` was added
to the end of the script

Fixes MetaMask/MetaMask-planning#2182
Co-authored-by: Elliot Winkler <elliot.winkler@gmail.com>
Copy link

sonarcloud bot commented Mar 13, 2024

Quality Gate Passed Quality Gate passed

Issues
0 New issues
0 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
No data about Duplication

See analysis details on SonarCloud

@Gudahtt
Copy link
Member Author

Gudahtt commented Mar 13, 2024

CI errors appear to be unrelated to this PR and are non-blocking

@Gudahtt Gudahtt merged commit 1f213b0 into main Mar 13, 2024
25 of 27 checks passed
@Gudahtt Gudahtt deleted the fix-attribution-generation branch March 13, 2024 17:42
@github-actions github-actions bot removed the needs-dev-review PR needs reviews from other engineers (in order to receive required approvals) label Mar 13, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Mar 13, 2024
@metamaskbot metamaskbot added the release-7.19.0 Issue or pull request that will be included in release 7.19.0 label Mar 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
release-7.19.0 Issue or pull request that will be included in release 7.19.0 Run Smoke E2E Triggers smoke e2e on Bitrise team-mobile-platform team-wallet-framework
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

5 participants