Skip to content

Commit

Permalink
Merge branch 'master' into custom-files-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
igorhrcek authored Mar 21, 2022
2 parents 9487f18 + 2c935ac commit bdc4003
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/SubCommands/AddSecurityHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public function getTemplateVars() : array {
'X-XSS-Protection' => '"1; mode=block"'
];

$headers = isset( $this->commandArguments['headers'] ) ? $this->commandArguments['headers'] : array_keys( $default_headers );
$headers = $this->commandArguments['headers'] ?? array_keys($default_headers);
if ( ! empty( $headers ) ) {
if ( is_string( $headers ) ) {
$headers = explode( ',', $headers );
Expand All @@ -45,6 +45,7 @@ public function getTemplateVars() : array {
}
return $headers_array;
}

return [];
}
}
32 changes: 32 additions & 0 deletions src/SubCommands/BlockAccessToSensitiveFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,36 @@ class BlockAccessToSensitiveFiles extends SubCommand {
public string $ruleName = 'BLOCK ACCESS TO SENSITIVE FILES';
public string $successMessage = 'Block Access to Sensitive Files rule has been deployed.';
public string $removalMessage= 'Block Access to Sensitive Files rule has been removed.';


/**
* @var string List of files that we are protecting by default
*/
private string $protectedFiles = 'readme.html,readme.txt,wp-config.php,nginx.conf,/wp-admin/install.php,/wp-admin/upgrade.php';

public function getTemplateVars() : array {
$files = $this->commandArguments['files'] ?? $this->protectedFiles;
if ( ! empty( $files ) ) {
$files = explode( ',', $files );
$files = array_map( 'trim', $files );
$files_array = [];

foreach ( $files as $key => $value ) {
if ( preg_match( '/.+\/.+/', $value ) ) {
$file_with_directory = $this->setRuleContent( false, 'block_access_to_sensitive_files_with_directories' );
if ( isset( $this->commandArguments['server'] ) && $this->commandArguments['server'] === 'nginx' ) {
$file = $value;
} else {
$file = preg_quote( ltrim( $value, '/' ) );
}
$files_array[] = [ $file => $file_with_directory ];
} else {
$files_array[] = [ 'file' => isset( $this->commandArguments['server'] ) && $this->commandArguments['server'] === 'nginx' ? preg_quote( $value ) : $value ];
}
}
return $files_array;
}
return [];
}

}

0 comments on commit bdc4003

Please sign in to comment.