Skip to content

Commit

Permalink
Redact deployer settings
Browse files Browse the repository at this point in the history
  • Loading branch information
bencroker committed Nov 19, 2024
1 parent aa4c056 commit 219826d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Release Notes for Blitz

## 5.9.7 - Unreleased

### Changed

- More deployer settings are now redacted when generating a diagnostics report.

## 5.9.6 - 2024-11-15

### Fixed
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "putyourlightson/craft-blitz",
"description": "Intelligent static page caching for creating lightning-fast sites.",
"version": "5.9.6",
"version": "5.9.7",
"type": "craft-plugin",
"homepage": "https://putyourlightson.com/plugins/blitz",
"license": "proprietary",
Expand Down
21 changes: 16 additions & 5 deletions src/controllers/DiagnosticsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,14 +119,25 @@ public function actionExportIncludes(int $siteId): Response
}

/**
* Returns redacted values as a JSON encoded string.
* Returns redacted plugin settings as a JSON encoded string.
*/
private function getRedacted(array $values): string
private function getRedactedPluginSettings(): string
{
$redacted = Craft::$app->getSecurity()->redactIfSensitive('', $values);
$settings = Blitz::$plugin->settings;

if (!empty($settings->deployerSettings)) {
$allowedKeys = ['gitRepositories'];
foreach ($settings->deployerSettings as $key => $value) {
if (!empty($settings->deployerSettings[$key]) && !in_array($key, $allowedKeys)) {
$settings->deployerSettings[$key] = '*';
}
}
}

$redacted = Craft::$app->getSecurity()->redactIfSensitive('', $settings->getAttributes());
$encoded = Json::encode($redacted, JSON_PRETTY_PRINT);

// Replace unicode character with asterisk
// Replace Unicode character with asterisk
return str_replace('\u2022', '*', $encoded);
}

Expand Down Expand Up @@ -158,7 +169,7 @@ private function getReport(): string
'dbDriver' => $this->dbDriver(),
'plugins' => Craft::$app->getPlugins()->getAllPlugins(),
'modules' => $modules,
'blitzPluginSettings' => $this->getRedacted(Blitz::$plugin->getSettings()->getAttributes()),
'blitzPluginSettings' => $this->getRedactedPluginSettings(),
]
);
}
Expand Down

0 comments on commit 219826d

Please sign in to comment.