From b26ec9c2fc9482b0c97bb3e432c08ccb7529dfa0 Mon Sep 17 00:00:00 2001 From: Alexandre Aubin Date: Wed, 19 Jun 2019 23:14:48 +0200 Subject: [PATCH] Find data to redact on-the-fly corresponding to common stuff --- src/yunohost/log.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/yunohost/log.py b/src/yunohost/log.py index 3631f6bf0..6bb1a4445 100644 --- a/src/yunohost/log.py +++ b/src/yunohost/log.py @@ -25,6 +25,7 @@ """ import os +import re import yaml import collections @@ -297,10 +298,22 @@ class RedactingFormatter(Formatter): def format(self, record): msg = super(RedactingFormatter, self).format(record) + self.identify_data_to_redact(msg) for data in self.data_to_redact: msg = msg.replace(data, "**********") return msg + def identify_data_to_redact(self, record): + + # Wrapping this in a try/except because we don't want this to + # break everything in case it fails miserably for some reason :s + try: + match = re.search(r'(db_pwd|password)=(\S{3,})$', record.strip()) + if match and match.group(2) not in self.data_to_redact: + self.data_to_redact.append(match.group(2)) + except Exception as e: + logger.warning("Failed to parse line to try to identify data to redact ... : %s" % e) + class OperationLogger(object):