Repository navigation
fix: scanner on update, install, remove, uninstall and add, and introduce the pm scan command
#22193
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
Merged
Merged
fix: scanner on update, install, remove, uninstall and add, and introduce the pm scan command
#22193
Changes from 119 commits
Commits
Show all changes
127 commits
Select commit
Hold shift + click to select a range
839187f
run on update
alii 4392a48
fix: run on update
alii 09d4f8a
part 1 bun pm scan
alii ee3b579
style changes to security scanner
alii 389530f
impl
alii 550ae07
[autofix.ci] apply automated fixes
autofix-ci[bot] 79d6300
refactor security scanner to be more portable
alii e8fb755
remove --json from help menu
alii 249dcca
[autofix.ci] apply automated fixes
autofix-ci[bot] 2888af2
polish with some warnings
alii d04311f
fix: shellenv should support NodeJS.Dict<string> as env()
alii edeb4b0
some basic generated tests
alii a73ebae
Start implementing a lot of the partial install step
alii fc22cac
[autofix.ci] apply automated fixes
autofix-ci[bot] 23ef819
implement isolated installer backend
alii 928ed86
works but we need to move this
alii 9ea78bd
move install specific package id logic to hoisted install, some error…
alii bf1460b
Enhance security scanner installation process with improved output me…
alii d9c0056
always find security_scanner_pkg_id from top level
alii 550d9a1
dont overreport errors (all cases should have a log)
alii d4512ff
clean it up a bunch
alii 31a7162
rm
alii 35f22e6
[autofix.ci] apply automated fixes
autofix-ci[bot] 2a610fc
slightly better error messages
alii edf3f7c
Refactor security scanner functions to include retry logic and improv…
alii c378276
Add security scanner entry point and update build configuration
alii db9feb9
save
alii cff611a
nicer
alii 5f47bb4
Improve error handling in security scanner
alii 4a652ea
fix the failing main bun-install-security-provider test expectations
alii e4b6b3d
fix `bun update` security scanner edge cases test
alii 64ab3c8
[autofix.ci] apply automated fixes
autofix-ci[bot] aa5b22a
tty stuff
alii 5fb5b26
rm tty tests
alii 5a49bd3
fix
alii 9fdfb2b
fix test cases
alii 2c134ab
matrix
alii 2f0324f
big test matrix
alii 6ebc8cc
update snaps
alii dd72d37
run on remove/uninstall
alii 536edcc
more snaps
alii 4aca86d
debloat
alii c8ffd06
better err message
alii 27b4b50
changes
alii be0b9e2
[autofix.ci] apply automated fixes
autofix-ci[bot] 6790981
fix
alii e1422f5
update failure expectations
alii 49c4d44
[autofix.ci] apply automated fixes
autofix-ci[bot] 3304508
update snaps
alii 38d0c6f
fix expectation for failure
alii 79ac245
update more snaps
alii de7d6b4
update snaps and enable(!) some other tests
alii 5b16ea3
serve test security scanners
alii 92694c6
move snapshots
alii 0f6fde0
changes
alii 7ba10cc
fix module resolver
alii 87166be
changes in the tests
alii 6440892
fix args each
alii e408af7
remove
alii befdac0
broken
alii f0a5b35
[autofix.ci] apply automated fixes
autofix-ci[bot] 216fa64
changes
alii 8f84d12
update failing other test cases (impl changed for message strings)
alii 407365c
more failure cases
alii ceafa36
this is wrong
alii e29d3f2
rm
alii da7ef19
try fix the resolution prefetch problem?
alii 988957a
[autofix.ci] apply automated fixes
autofix-ci[bot] a038908
remove force_install_skip_prefetch_check
alii 4c14c9d
fix compiler error
alii 436c057
fix
alii 0a3613a
add force_install_skip_prefetch_check to manage installation behavior…
alii ed23e95
refactor isolated_install.zig and update bun-security-scanner-matrix …
alii 3ba754c
empty clean snapshot for now since one test is failing
alii 8e3ccdb
typescript it
alii 4dab80a
test changes
alii 2c429c6
update snaps
alii d45f68e
label formatting
alii 10f6023
testing changes
alii 29d767b
chagnes
alii f14f206
clean → none
alii d863f13
test changes
alii 05b632a
debug helpers
alii 25c2125
updates
alii fd00f64
change
alii 60f19f7
update snaps
alii 17ffbd5
fixes
alii cb25629
fix: we resolve the security scanner during both update and scenarios…
alii 8d9ae8a
we don't resolve the security scanner in an update unless it's specif…
alii 982cb66
fix tests + sorted snapshorts
alii 619d9de
unifiy env() args for shell
alii 4ca8046
fix test globals
alii 248018a
review comments
alii c5d4a69
fix: failing pm scan test
alii 9ce0bc0
fix: workspace tests shouldnt be failing
alii 6142641
dont panic on scan command error
alii 0fcb5c3
fix some safety & memory problems in the scan command and scanner itself
alii fc7bac7
undo
alii 7a67da7
rm with node:fs
alii 06ea19b
test the path on windows
alii ab78fb4
dont include dir
alii f2fba92
do much less io, skip some tests
alii 8696ca3
regenerate snapshots
alii 201936d
use `await using`
alii f478355
reduce noise in test matrix
alii defacdf
pass the flag
alii 7a2301f
split security scanner matrix into two files to prevent hard ci time …
alii 6e9c11e
cleanup skipped ids
alii 506d7c2
update snaps
alii 3e081bf
regenerate with new test name
alii 3e9387d
redo snaps
alii 85a1d66
changes
alii a229051
only sample 10 percent of tests in ci
alii 32309ae
add broken bun uninstall skipped test ids + ignore install_packages f…
alii 43782e0
regenerate snaps
alii 02723aa
revert this
alii 9e0b5ee
Merge branch 'main' into scan-on-update
dylan-conway 2fc0d91
filter packages in `filter`
dylan-conway 3da5ddc
remove some old code
alii 601a495
partial pr comments
alii b3f7824
fix compilation err
alii 9c17f79
Clear peer dependency IDs before processing isolated package installa…
alii 5f5efee
[autofix.ci] apply automated fixes
autofix-ci[bot] c8e7514
update
dylan-conway f33e33e
Merge branch 'main' into scan-on-update
alii 4b79868
fix: build on windows
alii b30c1ed
oopsies
dylan-conway File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| pub const ScanCommand = struct { | ||
| pub fn exec(ctx: Command.Context) !void { | ||
| const cli = try PackageManager.CommandLineArguments.parse(ctx.allocator, .scan); | ||
|
|
||
| const manager, const cwd = PackageManager.init(ctx, cli, .scan) catch |err| { | ||
| if (err == error.MissingPackageJSON) { | ||
| Output.errGeneric("No package.json found. 'bun pm scan' requires a lockfile to analyze dependencies.", .{}); | ||
| Output.note("Run \"bun install\" first to generate a lockfile", .{}); | ||
| Global.exit(1); | ||
| } | ||
| return err; | ||
| }; | ||
| defer ctx.allocator.free(cwd); | ||
|
|
||
| try execWithManager(ctx, manager, cwd); | ||
| } | ||
|
|
||
| pub fn execWithManager(ctx: Command.Context, manager: *PackageManager, original_cwd: []const u8) !void { | ||
| if (manager.options.security_scanner == null) { | ||
| Output.prettyErrorln("<r><red>error<r>: no security scanner configured", .{}); | ||
| Output.prettyln("", .{}); | ||
| Output.prettyln("To use 'bun pm scan', configure a security scanner in bunfig.toml:", .{}); | ||
| Output.prettyln(" [install.security]", .{}); | ||
| Output.prettyln(" scanner = \"<cyan>package_name<r>\"", .{}); | ||
| Output.prettyln("", .{}); | ||
| Output.prettyln("Security scanners can be npm packages that export a scanner object.", .{}); | ||
| Global.exit(1); | ||
|
alii marked this conversation as resolved.
Resolved
|
||
| return; // sanity? lol | ||
|
alii marked this conversation as resolved.
Resolved
|
||
| } | ||
|
|
||
| Output.prettyError(comptime Output.prettyFmt("<r><b>bun pm scan <r><d>v" ++ Global.package_json_version_with_sha ++ "<r>\n", true), .{}); | ||
| Output.flush(); | ||
|
|
||
| const load_lockfile = manager.lockfile.loadFromCwd(manager, ctx.allocator, ctx.log, true); | ||
| if (load_lockfile == .not_found) { | ||
| Output.errGeneric("Lockfile not found. Run 'bun install' first to generate a lockfile.", .{}); | ||
| Global.exit(1); | ||
| } | ||
| if (load_lockfile == .err) { | ||
| Output.errGeneric("Error loading lockfile: {s}", .{@errorName(load_lockfile.err.value)}); | ||
| Global.exit(1); | ||
| } | ||
|
|
||
| const security_scan_results = security_scanner.performSecurityScanForAll(manager, ctx, original_cwd) catch |err| { | ||
| Output.errGeneric("Could not perform security scan (<d>{s}<r>)", .{@errorName(err)}); | ||
| Global.exit(1); | ||
| }; | ||
|
|
||
| if (security_scan_results) |results| { | ||
| defer { | ||
| var results_mut = results; | ||
| results_mut.deinit(); | ||
| } | ||
|
|
||
| security_scanner.printSecurityAdvisories(manager, &results); | ||
|
|
||
| if (results.hasAdvisories()) { | ||
| Global.exit(1); | ||
| } else { | ||
| Output.pretty("<green>No advisories found<r>\n", .{}); | ||
| } | ||
| } | ||
|
|
||
| Global.exit(0); | ||
| } | ||
| }; | ||
|
|
||
| const security_scanner = @import("../install/PackageManager/security_scanner.zig"); | ||
| const Command = @import("../cli.zig").Command; | ||
| const PackageManager = @import("../install/install.zig").PackageManager; | ||
|
|
||
| const bun = @import("bun"); | ||
| const Global = bun.Global; | ||
| const Output = bun.Output; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.