Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable12] Don't log passwords on dav exceptions #5619

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 4 additions & 21 deletions apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php
Expand Up @@ -94,26 +94,9 @@ public function logException(\Exception $ex) {
$level = \OCP\Util::DEBUG;
}

$message = $ex->getMessage();
if ($ex instanceof Exception) {
if (empty($message)) {
$response = new Response($ex->getHTTPCode());
$message = $response->getStatusText();
}
$message = "HTTP/1.1 {$ex->getHTTPCode()} $message";
}

$user = \OC_User::getUser();

$exception = [
'Message' => $message,
'Exception' => $exceptionClass,
'Code' => $ex->getCode(),
'Trace' => $ex->getTraceAsString(),
'File' => $ex->getFile(),
'Line' => $ex->getLine(),
'User' => $user,
];
$this->logger->log($level, 'Exception: ' . json_encode($exception), ['app' => $this->appName]);
$this->logger->logException($ex, [
'app' => $this->appName,
'level' => $level,
]);
}
}
Expand Up @@ -71,13 +71,13 @@ public function testLogging($expectedLogLevel, $expectedMessage, $exception) {
$this->plugin->logException($exception);

$this->assertEquals($expectedLogLevel, $this->logger->level);
$this->assertStringStartsWith('Exception: {"Message":"' . $expectedMessage, $this->logger->message);
$this->assertStringStartsWith('Exception: {"Exception":' . json_encode(get_class($exception)) . ',"Message":"' . $expectedMessage . '",', $this->logger->message);
}

public function providesExceptions() {
return [
[0, 'HTTP\/1.1 404 Not Found', new NotFound()],
[4, 'HTTP\/1.1 400 This path leads to nowhere', new InvalidPath('This path leads to nowhere')]
[0, '', new NotFound()],
[4, 'This path leads to nowhere', new InvalidPath('This path leads to nowhere')]
];
}

Expand Down
15 changes: 10 additions & 5 deletions lib/private/Log.php
Expand Up @@ -305,24 +305,29 @@ public function log($level, $message, array $context = array()) {
/**
* Logs an exception very detailed
*
* @param \Exception | \Throwable $exception
* @param \Exception|\Throwable $exception
* @param array $context
* @return void
* @since 8.2.0
*/
public function logException($exception, array $context = array()) {
$exception = array(
$level = Util::ERROR;
if (isset($context['level'])) {
$level = $context['level'];
unset($context['level']);
}
$data = array(
'Exception' => get_class($exception),
'Message' => $exception->getMessage(),
'Code' => $exception->getCode(),
'Trace' => $exception->getTraceAsString(),
'File' => $exception->getFile(),
'Line' => $exception->getLine(),
);
$exception['Trace'] = preg_replace('!(' . implode('|', $this->methodsWithSensitiveParameters) . ')\(.*\)!', '$1(*** sensitive parameters replaced ***)', $exception['Trace']);
$data['Trace'] = preg_replace('!(' . implode('|', $this->methodsWithSensitiveParameters) . ')\(.*\)!', '$1(*** sensitive parameters replaced ***)', $data['Trace']);
$msg = isset($context['message']) ? $context['message'] : 'Exception';
$msg .= ': ' . json_encode($exception);
$this->error($msg, $context);
$msg .= ': ' . json_encode($data);
$this->log($level, $msg, $context);
}

/**
Expand Down