]> source.dussan.org Git - nextcloud-server.git/commitdiff
Don't log passwords on dav exceptions 5619/head
authorJoas Schilling <coding@schilljs.com>
Thu, 29 Jun 2017 09:43:32 +0000 (11:43 +0200)
committerJoas Schilling <coding@schilljs.com>
Wed, 5 Jul 2017 13:10:38 +0000 (15:10 +0200)
Signed-off-by: Joas Schilling <coding@schilljs.com>
apps/dav/lib/Connector/Sabre/ExceptionLoggerPlugin.php
apps/dav/tests/unit/Connector/Sabre/ExceptionLoggerPluginTest.php
lib/private/Log.php

index 4f7c2286827e1016af1a14338e42636f8009fa25..dce2f9c45e4fdc80973a29c5670d0c417209e552 100644 (file)
@@ -94,26 +94,9 @@ class ExceptionLoggerPlugin extends \Sabre\DAV\ServerPlugin {
                        $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,
+               ]);
        }
 }
index 8088ee6dc4dd8c24521076aa51834797aa615cce..85ede2ad681d07a085d4966bfddd60d4f2e082bc 100644 (file)
@@ -71,13 +71,13 @@ class ExceptionLoggerPluginTest extends TestCase {
                $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')]
                ];
        }
 
index ea20353a0a08953ce3b761265f9e717649a11300..0d291218096253c78129353100281a5e9076a7ce 100644 (file)
@@ -305,13 +305,18 @@ class Log implements ILogger {
        /**
         * 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(),
@@ -319,10 +324,10 @@ class Log implements ILogger {
                        '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);
        }
 
        /**