Skip to content

Commit 48cc4f5

Browse files
swissspidyclaude
andauthored
Use 0755 instead of 0700 for the packages directory (#244)
Co-authored-by: Claude Opus 5 <noreply@anthropic.com> Co-authored-by: Claude <noreply@anthropic.com>
1 parent 168a224 commit 48cc4f5

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

‎src/Package_Command.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ private function create_default_composer_json( $composer_path ) {
12831283

12841284
$composer_dir = pathinfo( $composer_path, PATHINFO_DIRNAME );
12851285
if ( ! is_dir( $composer_dir ) ) {
1286-
if ( ! @mkdir( $composer_dir, 0700, true ) ) { // @codingStandardsIgnoreLine
1286+
if ( ! @mkdir( $composer_dir, 0755, true ) ) { // @codingStandardsIgnoreLine
12871287
$error = error_get_last();
12881288
WP_CLI::error( sprintf( "Composer directory '%s' for packages couldn't be created: %s", $composer_dir, $error['message'] ) );
12891289
}

‎tests/phpunit/ComposerJsonTest.php‎

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,15 @@ public function test_create_default_composer_json() {
8888
$this->assertSame( $this->mac_safe_path( realpath( $expected ) ?: $expected ), $this->mac_safe_path( realpath( $actual ) ?: $actual ) );
8989
$this->assertTrue( false !== strpos( file_get_contents( $actual ), 'wp-cli/wp-cli' ) );
9090
if ( ! Utils\is_windows() ) {
91-
$this->assertSame( '0700', substr( sprintf( '%o', fileperms( dirname( $actual ) ) ), -4 ) );
91+
// The invariant that matters is that no other local user can write into the packages
92+
// directory, whose `vendor/autoload.php` is required on every WP-CLI run. The exact
93+
// mode depends on the umask, so assert the write bits rather than the literal mode.
94+
$perms = fileperms( dirname( $actual ) ) & 0777;
95+
$this->assertSame(
96+
0,
97+
$perms & 0022,
98+
sprintf( 'Packages directory must not be group- or world-writable, got %o.', $perms )
99+
);
92100
}
93101
unlink( $actual );
94102
rmdir( dirname( $actual ) );

0 commit comments

Comments
 (0)