Skip to content

Commit 9d704fc

Browse files
duncanmccleanclaudejasonvarga
authored
[6.x] Prevent npm packages from executing malicious code via postinstall (#14417)
Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com> Co-authored-by: Jason Varga <jason@pixelfear.com>
1 parent a02fb12 commit 9d704fc

File tree

5 files changed

+7
-7
lines changed

5 files changed

+7
-7
lines changed

src/Console/Commands/Concerns/MakesVueComponents.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ private function wireUpAddonJs(string $addon): void
8181

8282
$this->files->makeDirectory($addonPath.'/resources/dist', 0777, true, true);
8383

84-
Process::path(base_path())->run('npm install', function (string $type, string $buffer) {
84+
Process::path(base_path())->run('npm install --ignore-scripts', function (string $type, string $buffer) {
8585
echo $buffer;
8686
});
8787

src/Console/Commands/SetupCpVite.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,14 @@ private function installDependencies(): self
6363

6464
File::put($packageJsonPath, json_encode($contents, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES));
6565

66-
return Process::path(base_path())->run('npm install');
66+
return Process::path(base_path())->run('npm install --ignore-scripts');
6767
},
6868
message: 'Installing dependencies...'
6969
);
7070

7171
if ($result->failed()) {
7272
$this->line($result->errorOutput() ?: $result->output());
73-
$this->components->error('Failed to install dependencies. You need to run "npm install" manually.');
73+
$this->components->error('Failed to install dependencies. You need to run "npm install --ignore-scripts" manually.');
7474

7575
return $this;
7676
}

tests/Console/Commands/MakeFieldtypeTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public function boot(): void
102102
->artisan('statamic:make:fieldtype', ['name' => 'KnightRider'])
103103
->expectsQuestion("It doesn't look like Vite is setup for the Control Panel. Would you like to run `php please setup-cp-vite`?", true);
104104

105-
Process::assertRan('npm install');
105+
Process::assertRan('npm install --ignore-scripts');
106106

107107
$this->assertFileExists($fieldtype = base_path('app/Fieldtypes/KnightRider.php'));
108108
$this->assertStringContainsString('namespace App\Fieldtypes;', $this->files->get($fieldtype));
@@ -167,7 +167,7 @@ public function it_can_make_a_fieldtype_into_an_addon()
167167

168168
$this->artisan('statamic:make:fieldtype', ['name' => 'Yoda', 'addon' => 'yoda/bag-odah']);
169169

170-
Process::assertRan('npm install');
170+
Process::assertRan('npm install --ignore-scripts');
171171

172172
$this->assertFileExists($fieldtype);
173173
$this->assertStringContainsString('namespace Yoda\BagOdah\Fieldtypes;', $this->files->get($fieldtype));

tests/Console/Commands/MakeWidgetTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function boot(): void
111111
->artisan('statamic:make:widget', ['name' => 'Sloth'])
112112
->expectsQuestion("It doesn't look like Vite is setup for the Control Panel. Would you like to run `php please setup-cp-vite`?", true);
113113

114-
Process::assertRan('npm install');
114+
Process::assertRan('npm install --ignore-scripts');
115115

116116
$this->assertFileExists($widget);
117117
$this->assertStringContainsString('namespace App\Widgets;', $this->files->get($widget));

tests/Console/Commands/SetupCpViteTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public function it_installs_dependencies()
5050
->artisan('statamic:setup-cp-vite')
5151
->expectsOutputToContain('Installed dependencies');
5252

53-
Process::assertRan('npm install');
53+
Process::assertRan('npm install --ignore-scripts');
5454

5555
$this->assertStringContainsString(<<<'JSON'
5656
"dependencies": {

0 commit comments

Comments
 (0)