Skip to content

Commit

Permalink
secrets appear on errors in logfile (#261)
Browse files Browse the repository at this point in the history
With PHP>=8.2 they will appear like this:

```
/var/www/html/apps-extra/app_api/lib/Service/AppAPIService.php
line 89
OCA\AppAPI\Service\AppAPIService->requestToExAppInternal(
  [
    "OCA\\AppAPI\\Db\\ExApp",
    3
  ],
  "POST",
  "http://host.docker.internal:9031/video_to_gif",
  [
    "SensitiveParameterValue"
  ]
)
```

Also adjustments in the Nextcloud Server required, to hide headers in
`IClient` calls, we cannot do it from AppAPI side.

Signed-off-by: Alexander Piskun <[email protected]>
  • Loading branch information
bigcat88 authored Apr 2, 2024
1 parent b059900 commit 1917ca8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Fixed

- Corrected error handling for `occ` commands: `register` and `update`. #258
- `SensitiveParameter` is applied to variables containing secrets, preventing them from being leaked to the logs. #261

## [2.3.2 - 2024-03-28]

Expand Down
45 changes: 35 additions & 10 deletions lib/Service/AppAPIService.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,20 +85,30 @@ public function requestToExApp(
array $options = [],
?IRequest $request = null,
): array|IResponse {
$request_data = $this->prepareRequestToExApp($exApp, $route, $userId, $method, $params, $options, $request);
$requestData = $this->prepareRequestToExApp($exApp, $route, $userId, $method, $params, $options, $request);
return $this->requestToExAppInternal($exApp, $method, $requestData['url'], $requestData['options']);
}

private function requestToExAppInternal(
ExApp $exApp,
string $method,
string $uri,
#[\SensitiveParameter]
array $options,
): array|IResponse {
try {
switch ($method) {
case 'GET':
$response = $this->client->get($request_data['url'], $request_data['options']);
$response = $this->client->get($uri, $options);
break;
case 'POST':
$response = $this->client->post($request_data['url'], $request_data['options']);
$response = $this->client->post($uri, $options);
break;
case 'PUT':
$response = $this->client->put($request_data['url'], $request_data['options']);
$response = $this->client->put($uri, $options);
break;
case 'DELETE':
$response = $this->client->delete($request_data['url'], $request_data['options']);
$response = $this->client->delete($uri, $options);
break;
default:
return ['error' => 'Bad HTTP method'];
Expand All @@ -119,16 +129,26 @@ public function requestToExAppAsync(
array $options = [],
?IRequest $request = null,
): void {
$request_data = $this->prepareRequestToExApp($exApp, $route, $userId, $method, $params, $options, $request);
$requestData = $this->prepareRequestToExApp($exApp, $route, $userId, $method, $params, $options, $request);
$this->requestToExAppInternalAsync($exApp, $method, $requestData['url'], $requestData['options']);
}

private function requestToExAppInternalAsync(
ExApp $exApp,
string $method,
string $uri,
#[\SensitiveParameter]
array $options,
): void {
switch ($method) {
case 'POST':
$promise = $this->client->postAsync($request_data['url'], $request_data['options']);
$promise = $this->client->postAsync($uri, $options);
break;
case 'PUT':
$promise = $this->client->putAsync($request_data['url'], $request_data['options']);
$promise = $this->client->putAsync($uri, $options);
break;
case 'DELETE':
$promise = $this->client->deleteAsync($request_data['url'], $request_data['options']);
$promise = $this->client->deleteAsync($uri, $options);
break;
default:
$this->logger->error('Bad HTTP method: requestToExAppAsync accepts only `POST`, `PUT` and `DELETE`');
Expand All @@ -145,6 +165,7 @@ private function prepareRequestToExApp(
?string $userId,
string $method,
array $params,
#[\SensitiveParameter]
array $options,
?IRequest $request,
): array {
Expand Down Expand Up @@ -478,7 +499,11 @@ public function runOccCommand(string $command): bool {
return true;
}

public function heartbeatExApp(string $exAppUrl, array $auth): bool {
public function heartbeatExApp(
string $exAppUrl,
#[\SensitiveParameter]
array $auth,
): bool {
$heartbeatAttempts = 0;
$delay = 1;
$maxHeartbeatAttempts = 60 * 10 * $delay; // minutes for container initialization
Expand Down

0 comments on commit 1917ca8

Please sign in to comment.