-
-
Notifications
You must be signed in to change notification settings - Fork 21
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
Fix: remove sensitive logs #116
Changes from all commits
527c667
4df8abb
55db5ca
5e449f8
d89bd50
db1ef33
0d213e6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -68,3 +68,8 @@ [email protected] | |
# USE ABSOLUTE PATHS for better predictability | ||
WEBDAV_TMP_DIR='/tmp' | ||
WEBDAV_PUBLIC_DIR='/webdav' | ||
|
||
# Logging path | ||
# By default, it will log in the standard Symfony directory: var/log/prod.log (for production) | ||
# You can use /dev/null here if you want to discard logs entirely | ||
LOG_FILE_PATH="%kernel.logs_dir%/%kernel.environment%.log" | ||
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
namespace App\Logging\Monolog; | ||
|
||
use Monolog\Processor\ProcessorInterface; | ||
|
||
final class PasswordFilterProcessor implements ProcessorInterface | ||
{ | ||
private const REDACTED = '****'; | ||
private const PASSWORD_KEY = 'password'; | ||
private const SENSITIVE_ARGS_FUNCTIONS = ['validateUserPass', 'ldapOpen', 'password_verify', 'imapOpen', 'ldap_bind', 'hashPassword', 'dav']; | ||
|
||
public function __invoke(array $record): array | ||
{ | ||
// Remove potentially sensitive data from function arguments | ||
$shouldRedactArgs = array_key_exists('function', $record) && in_array($record['function'], self::SENSITIVE_ARGS_FUNCTIONS); | ||
|
||
foreach ($record as $key => $item) { | ||
if (self::PASSWORD_KEY === strtolower($key) || ('args' === $key && $shouldRedactArgs)) { | ||
$record[$key] = self::REDACTED; | ||
} elseif (is_array($item)) { | ||
$record[$key] = $this($item); | ||
} | ||
} | ||
|
||
return $record; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -62,7 +62,12 @@ protected function imapOpen($username, $password) | |
$this->utils->createPasswordlessUserWithDefaultObjects($username, $username, $username); | ||
|
||
$em = $this->doctrine->getManager(); | ||
$em->flush(); | ||
|
||
try { | ||
$em->flush(); | ||
} catch (\Exception $e) { | ||
error_log('IMAP Error (flush): '.$e->getMessage()); | ||
} | ||
Comment on lines
-65
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching the exception will allow to continue (as the auth succeeded) and not log the trace, if any |
||
} | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -91,7 +91,7 @@ protected function ldapOpen($username, $password) | |
try { | ||
$ldap = ldap_connect($this->LDAPAuthUrl); | ||
} catch (\ErrorException $e) { | ||
error_log($e->getMessage()); | ||
error_log('LDAP Error (ldap_connect): '.ldap_error($ldap).' ('.ldap_errno($ldap).')'); | ||
} | ||
|
||
if (!$ldap || !ldap_set_option($ldap, LDAP_OPT_PROTOCOL_VERSION, 3)) { | ||
|
@@ -124,8 +124,7 @@ protected function ldapOpen($username, $password) | |
$success = true; | ||
} | ||
} catch (\ErrorException $e) { | ||
error_log($e->getMessage()); | ||
error_log('LDAP Error: '.ldap_error($ldap).' ('.ldap_errno($ldap).')'); | ||
error_log('LDAP Error (ldap_bind): '.ldap_error($ldap).' ('.ldap_errno($ldap).')'); | ||
} | ||
|
||
if ($success && $this->autoCreate) { | ||
|
@@ -161,7 +160,12 @@ protected function ldapOpen($username, $password) | |
$this->utils->createPasswordlessUserWithDefaultObjects($username, $displayName, $email); | ||
|
||
$em = $this->doctrine->getManager(); | ||
$em->flush(); | ||
|
||
try { | ||
$em->flush(); | ||
} catch (\Exception $e) { | ||
error_log('LDAP Error (flush): '.$e->getMessage()); | ||
} | ||
Comment on lines
-164
to
+168
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Catching the exception will allow to continue (as the auth succeeded) and not log the trace, if any |
||
} | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here for the env var