Skip to content
Merged
Show file tree
Hide file tree
Changes from 119 commits
Commits
Show all changes
127 commits
Select commit Hold shift + click to select a range
839187f
run on update
alii Aug 27, 2025
4392a48
fix: run on update
alii Aug 27, 2025
09d4f8a
part 1 bun pm scan
alii Aug 27, 2025
ee3b579
style changes to security scanner
alii Aug 27, 2025
389530f
impl
alii Aug 27, 2025
550ae07
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 27, 2025
79d6300
refactor security scanner to be more portable
alii Aug 27, 2025
e8fb755
remove --json from help menu
alii Aug 27, 2025
249dcca
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 27, 2025
2888af2
polish with some warnings
alii Aug 27, 2025
d04311f
fix: shellenv should support NodeJS.Dict<string> as env()
alii Aug 27, 2025
edeb4b0
some basic generated tests
alii Aug 28, 2025
a73ebae
Start implementing a lot of the partial install step
alii Aug 28, 2025
fc22cac
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 28, 2025
23ef819
implement isolated installer backend
alii Aug 28, 2025
928ed86
works but we need to move this
alii Aug 28, 2025
9ea78bd
move install specific package id logic to hoisted install, some error…
alii Aug 28, 2025
bf1460b
Enhance security scanner installation process with improved output me…
alii Aug 28, 2025
d9c0056
always find security_scanner_pkg_id from top level
alii Aug 28, 2025
550d9a1
dont overreport errors (all cases should have a log)
alii Aug 28, 2025
d4512ff
clean it up a bunch
alii Aug 28, 2025
31a7162
rm
alii Aug 28, 2025
35f22e6
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 28, 2025
2a610fc
slightly better error messages
alii Aug 28, 2025
edf3f7c
Refactor security scanner functions to include retry logic and improv…
alii Aug 28, 2025
c378276
Add security scanner entry point and update build configuration
alii Aug 28, 2025
db9feb9
save
alii Aug 28, 2025
cff611a
nicer
alii Aug 28, 2025
5f47bb4
Improve error handling in security scanner
alii Aug 28, 2025
4a652ea
fix the failing main bun-install-security-provider test expectations
alii Aug 28, 2025
e4b6b3d
fix `bun update` security scanner edge cases test
alii Aug 28, 2025
64ab3c8
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 28, 2025
aa5b22a
tty stuff
alii Aug 28, 2025
5fb5b26
rm tty tests
alii Aug 28, 2025
5a49bd3
fix
alii Aug 28, 2025
9fdfb2b
fix test cases
alii Aug 28, 2025
2c134ab
matrix
alii Aug 28, 2025
2f0324f
big test matrix
alii Aug 28, 2025
6ebc8cc
update snaps
alii Aug 28, 2025
dd72d37
run on remove/uninstall
alii Aug 28, 2025
536edcc
more snaps
alii Aug 28, 2025
4aca86d
debloat
alii Aug 28, 2025
c8ffd06
better err message
alii Aug 28, 2025
27b4b50
changes
alii Aug 29, 2025
be0b9e2
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 29, 2025
6790981
fix
alii Aug 29, 2025
e1422f5
update failure expectations
alii Aug 29, 2025
49c4d44
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 29, 2025
3304508
update snaps
alii Aug 29, 2025
38d0c6f
fix expectation for failure
alii Aug 29, 2025
79ac245
update more snaps
alii Aug 29, 2025
de7d6b4
update snaps and enable(!) some other tests
alii Aug 29, 2025
5b16ea3
serve test security scanners
alii Aug 29, 2025
92694c6
move snapshots
alii Aug 29, 2025
0f6fde0
changes
alii Aug 29, 2025
7ba10cc
fix module resolver
alii Aug 29, 2025
87166be
changes in the tests
alii Aug 29, 2025
6440892
fix args each
alii Aug 29, 2025
e408af7
remove
alii Aug 29, 2025
befdac0
broken
alii Aug 29, 2025
f0a5b35
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 29, 2025
216fa64
changes
alii Aug 29, 2025
8f84d12
update failing other test cases (impl changed for message strings)
alii Aug 29, 2025
407365c
more failure cases
alii Aug 29, 2025
ceafa36
this is wrong
alii Aug 29, 2025
e29d3f2
rm
alii Aug 29, 2025
da7ef19
try fix the resolution prefetch problem?
alii Aug 29, 2025
988957a
[autofix.ci] apply automated fixes
autofix-ci[bot] Aug 29, 2025
a038908
remove force_install_skip_prefetch_check
alii Aug 29, 2025
4c14c9d
fix compiler error
alii Aug 29, 2025
436c057
fix
alii Aug 29, 2025
0a3613a
add force_install_skip_prefetch_check to manage installation behavior…
alii Aug 30, 2025
ed23e95
refactor isolated_install.zig and update bun-security-scanner-matrix …
alii Aug 30, 2025
3ba754c
empty clean snapshot for now since one test is failing
alii Aug 30, 2025
8e3ccdb
typescript it
alii Aug 30, 2025
4dab80a
test changes
alii Aug 30, 2025
2c429c6
update snaps
alii Aug 30, 2025
d45f68e
label formatting
alii Aug 30, 2025
10f6023
testing changes
alii Aug 30, 2025
29d767b
chagnes
alii Aug 30, 2025
f14f206
clean → none
alii Aug 30, 2025
d863f13
test changes
alii Aug 30, 2025
05b632a
debug helpers
alii Aug 30, 2025
25c2125
updates
alii Aug 30, 2025
fd00f64
change
alii Aug 30, 2025
60f19f7
update snaps
alii Aug 30, 2025
17ffbd5
fixes
alii Aug 30, 2025
cb25629
fix: we resolve the security scanner during both update and scenarios…
alii Aug 30, 2025
8d9ae8a
we don't resolve the security scanner in an update unless it's specif…
alii Aug 30, 2025
982cb66
fix tests + sorted snapshorts
alii Aug 30, 2025
619d9de
unifiy env() args for shell
alii Aug 30, 2025
4ca8046
fix test globals
alii Aug 30, 2025
248018a
review comments
alii Aug 30, 2025
c5d4a69
fix: failing pm scan test
alii Aug 30, 2025
9ce0bc0
fix: workspace tests shouldnt be failing
alii Aug 30, 2025
6142641
dont panic on scan command error
alii Aug 30, 2025
0fcb5c3
fix some safety & memory problems in the scan command and scanner itself
alii Aug 30, 2025
fc7bac7
undo
alii Aug 30, 2025
7a67da7
rm with node:fs
alii Aug 30, 2025
06ea19b
test the path on windows
alii Aug 30, 2025
ab78fb4
dont include dir
alii Aug 30, 2025
f2fba92
do much less io, skip some tests
alii Aug 31, 2025
8696ca3
regenerate snapshots
alii Aug 31, 2025
201936d
use `await using`
alii Sep 1, 2025
f478355
reduce noise in test matrix
alii Sep 4, 2025
defacdf
pass the flag
alii Sep 4, 2025
7a2301f
split security scanner matrix into two files to prevent hard ci time …
alii Sep 4, 2025
6e9c11e
cleanup skipped ids
alii Sep 4, 2025
506d7c2
update snaps
alii Sep 4, 2025
3e081bf
regenerate with new test name
alii Sep 4, 2025
3e9387d
redo snaps
alii Sep 4, 2025
85a1d66
changes
alii Sep 4, 2025
a229051
only sample 10 percent of tests in ci
alii Sep 4, 2025
32309ae
add broken bun uninstall skipped test ids + ignore install_packages f…
alii Sep 4, 2025
43782e0
regenerate snaps
alii Sep 4, 2025
02723aa
revert this
alii Sep 4, 2025
9e0b5ee
Merge branch 'main' into scan-on-update
dylan-conway Sep 8, 2025
2fc0d91
filter packages in `filter`
dylan-conway Sep 9, 2025
3da5ddc
remove some old code
alii Sep 9, 2025
601a495
partial pr comments
alii Sep 9, 2025
b3f7824
fix compilation err
alii Sep 9, 2025
9c17f79
Clear peer dependency IDs before processing isolated package installa…
alii Sep 9, 2025
5f5efee
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 9, 2025
c8e7514
update
dylan-conway Sep 9, 2025
f33e33e
Merge branch 'main' into scan-on-update
alii Sep 9, 2025
4b79868
fix: build on windows
alii Sep 9, 2025
b30c1ed
oopsies
dylan-conway Sep 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion cmake/Sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
},
{
"output": "JavaScriptSources.txt",
"paths": ["src/js/**/*.{js,ts}"]
"paths": [
"src/js/**/*.{js,ts}",
"src/install/PackageManager/scanner-entry.ts"
]
},
{
"output": "JavaScriptCodegenSources.txt",
Expand Down
1 change: 1 addition & 0 deletions cmake/targets/BuildBun.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -636,6 +636,7 @@ register_command(
SOURCES
${BUN_ZIG_SOURCES}
${BUN_ZIG_GENERATED_SOURCES}
${CWD}/src/install/PackageManager/scanner-entry.ts # Is there a better way to do this?
Comment thread
alii marked this conversation as resolved.
Resolved
)

set_property(TARGET bun-zig PROPERTY JOB_POOL compile_pool)
Expand Down
4 changes: 2 additions & 2 deletions packages/bun-types/shell.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ declare module "bun" {
* // "bun"
* ```
*/
function env(newEnv?: Record<string, string | undefined>): $;
function env(newEnv?: Record<string, string | undefined> | NodeJS.Dict<string> | undefined): $;

/**
*
Expand Down Expand Up @@ -106,7 +106,7 @@ declare module "bun" {
* expect(stdout.toString()).toBe("LOL!");
* ```
*/
env(newEnv: Record<string, string> | undefined): this;
env(newEnv: Record<string, string | undefined> | NodeJS.Dict<string> | undefined): this;
Comment thread
alii marked this conversation as resolved.
Resolved

/**
* By default, the shell will write to the current process's stdout and stderr, as well as buffering that output.
Expand Down
7 changes: 6 additions & 1 deletion src/cli/package_manager_command.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const NodeModulesFolder = Lockfile.Tree.Iterator(.node_modules).Next;
pub const PackCommand = @import("./pack_command.zig").PackCommand;
pub const ScanCommand = @import("./scan_command.zig").ScanCommand;

const ByName = struct {
dependencies: []const Dependency,
Expand Down Expand Up @@ -92,6 +93,7 @@ pub const PackageManagerCommand = struct {
\\
\\<b>Commands:<r>
\\
\\ <b><green>bun pm<r> <blue>scan<r> scan all packages in lockfile for security vulnerabilities
Comment thread
alii marked this conversation as resolved.
Resolved
\\ <b><green>bun pm<r> <blue>pack<r> create a tarball of the current workspace
\\ <d>├<r> <cyan>--dry-run<r> do everything except for writing the tarball to disk
\\ <d>├<r> <cyan>--destination<r> the directory the tarball will be saved in
Expand Down Expand Up @@ -157,7 +159,10 @@ pub const PackageManagerCommand = struct {
try pm.setupGlobalDir(ctx);
}

if (strings.eqlComptime(subcommand, "pack")) {
if (strings.eqlComptime(subcommand, "scan")) {
try ScanCommand.execWithManager(ctx, pm, cwd);
Global.exit(0);
} else if (strings.eqlComptime(subcommand, "pack")) {
try PackCommand.execWithManager(ctx, pm);
Global.exit(0);
} else if (strings.eqlComptime(subcommand, "whoami")) {
Expand Down
74 changes: 74 additions & 0 deletions src/cli/scan_command.zig
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);
Comment thread
alii marked this conversation as resolved.
Resolved
return; // sanity? lol
Comment thread
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;
2 changes: 2 additions & 0 deletions src/install/PackageInstaller.zig
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ pub const PackageInstaller = struct {
manager: *PackageManager,
lockfile: *Lockfile,
progress: *Progress,
force_install_skip_prefetch_check: bool = false,

// relative paths from `next` will be copied into this list.
node_modules: NodeModulesFolder,
Expand Down Expand Up @@ -982,6 +983,7 @@ pub const PackageInstaller = struct {
resolution.value.npm.url.slice(this.lockfile.buffers.string_bytes.items),
context,
patch_name_and_version_hash,
this.force_install_skip_prefetch_check,
) catch |err| switch (err) {
error.OutOfMemory => bun.outOfMemory(),
error.InvalidURL => this.failWithInvalidUrl(
Expand Down
7 changes: 5 additions & 2 deletions src/install/PackageManager.zig
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
cache_directory_: ?std.fs.Dir = null,

cache_directory_path: stringZ = "",
temp_dir_: ?std.fs.Dir = null,
temp_dir_path: stringZ = "",
Expand Down Expand Up @@ -155,6 +154,7 @@ pub const Subcommand = enum {
audit,
info,
why,
scan,

// bin,
// hash,
Expand Down Expand Up @@ -580,7 +580,10 @@ pub fn init(
if (comptime Environment.isWindows) {
_ = Path.pathToPosixBuf(u8, top_level_dir_no_trailing_slash, &cwd_buf);
} else {
@memcpy(cwd_buf[0..top_level_dir_no_trailing_slash.len], top_level_dir_no_trailing_slash);
// Avoid memcpy alias when source and dest are the same
if (cwd_buf[0..].ptr != top_level_dir_no_trailing_slash.ptr) {
@memcpy(cwd_buf[0..top_level_dir_no_trailing_slash.len], top_level_dir_no_trailing_slash);
}
Comment thread
alii marked this conversation as resolved.
Resolved
}

var original_package_json_path_buf = bun.handleOom(std.ArrayListUnmanaged(u8).initCapacity(ctx.allocator, top_level_dir_no_trailing_slash.len + "/package.json".len + 1));
Expand Down
30 changes: 30 additions & 0 deletions src/install/PackageManager/CommandLineArguments.zig
Original file line number Diff line number Diff line change
Expand Up @@ -702,6 +702,35 @@ pub fn printHelp(subcommand: Subcommand) void {
Output.pretty(outro_text, .{});
Output.flush();
},
.scan => {
const intro_text =
\\
\\<b>Usage<r>: <b><green>bun pm scan<r> <cyan>[flags]<r>
\\
\\ Scan all packages in lockfile for security vulnerabilities.
\\
\\<b>Flags:<r>
;

const outro_text =
\\
\\
\\<b>Examples:<r>
\\ <d>Scan all packages for vulnerabilities<r>
\\ <b><green>bun pm scan<r>
\\
\\ <d>Output results as JSON<r>
\\ <b><green>bun pm scan<r> <cyan>--json<r>
\\
\\Full documentation is available at <magenta>https://bun.com/docs/cli/pm#scan<r>.
\\
;

Output.pretty(intro_text, .{});
clap.simpleHelp(pm_params);
Output.pretty(outro_text, .{});
Output.flush();
},
}
}

Expand All @@ -727,6 +756,7 @@ pub fn parse(allocator: std.mem.Allocator, comptime subcommand: Subcommand) !Com
// are not included in the help text
.audit => shared_params ++ audit_params,
.info => info_params,
.scan => pm_params, // scan uses the same params as pm command
};
Comment thread
alii marked this conversation as resolved.
Resolved

var diag = clap.Diagnostic{};
Expand Down
3 changes: 2 additions & 1 deletion src/install/PackageManager/PackageManagerEnqueue.zig
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ pub fn enqueuePackageForDownload(
url: []const u8,
task_context: TaskCallbackContext,
patch_name_and_version_hash: ?u64,
force_install_skip_prefetch_check: bool,
) EnqueuePackageForDownloadError!void {
Comment thread
alii marked this conversation as resolved.
Resolved
const task_id = Task.Id.forNPMPackage(name, version);
var task_queue = try this.task_queue.getOrPut(this.allocator, task_id);
Expand All @@ -254,7 +255,7 @@ pub fn enqueuePackageForDownload(
if (task_queue.found_existing) return;

// Skip tarball download when prefetch_resolved_tarballs is disabled (e.g., --lockfile-only)
if (!this.options.do.prefetch_resolved_tarballs) return;
if (!this.options.do.prefetch_resolved_tarballs and !force_install_skip_prefetch_check) return;

Comment thread
alii marked this conversation as resolved.
Resolved
const is_required = this.lockfile.buffers.dependencies.items[dependency_id].behavior.isRequired();

Expand Down
Loading