Skip to content

Commit

Permalink
Merge pull request #36 from igorhrcek/custom-files-fix
Browse files Browse the repository at this point in the history
fix: Fix BlockAccessToCustomSensitiveFiles
  • Loading branch information
igorhrcek authored Mar 21, 2022
2 parents 2c935ac + bdc4003 commit 56e7b1c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/SubCommands/AddSecurityHeaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class AddSecurityHeaders extends SubCommand {
public string $removalMessage= 'Add Security Headers rule has been removed.';

public function getTemplateVars() : array {

$default_headers = [
'Strict-Transport-Security' => '"max-age=63072000; includeSubDomains; preload"',
'Referrer-Policy' => 'strict-origin-when-cross-origin',
Expand Down
19 changes: 14 additions & 5 deletions src/SubCommands/BlockAccessToCustomSensitiveFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ public function getTemplateVars(): array {
$files_array = [];

foreach ($files as $key => $value) {
$file = (isset($this->commandArguments['server']) && $this->commandArguments['server'] === 'nginx') ?
preg_quote($value) : $value;

$files_array[] = ['file' => $file];
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 {
$file = (isset($this->commandArguments['server']) && $this->commandArguments['server'] === 'nginx') ?
preg_quote($value) : $value;
$files_array[] = ['file' => $file];
}
}

return $files_array;
}

Expand Down
2 changes: 2 additions & 0 deletions src/SubCommands/BlockAccessToSensitiveFiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class BlockAccessToSensitiveFiles extends SubCommand {
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
*/
Expand Down Expand Up @@ -37,4 +38,5 @@ public function getTemplateVars() : array {
}
return [];
}

}

0 comments on commit 56e7b1c

Please sign in to comment.