Improve scrubbing of sensitive identifiers

Fixes #1189
This commit is contained in:
AsamK 2024-01-31 20:33:01 +01:00
parent a40810e33e
commit 00e71ed0fc
3 changed files with 31 additions and 2 deletions

View file

@ -44,6 +44,7 @@ If `--verbose` is also given, the detailed logs will only be written to the log
*--scrub-log*:: *--scrub-log*::
Scrub possibly sensitive information from the log, like phone numbers and UUIDs. Scrub possibly sensitive information from the log, like phone numbers and UUIDs.
Doesn't work reliably on dbus logs with very verbose logging (`-vvv`)
*--config* CONFIG:: *--config* CONFIG::
Set the path, where to store the config. Set the path, where to store the config.

View file

@ -52,6 +52,8 @@ public class LogConfigurator extends ContextAwareBase implements Configurator {
rootLogger.addAppender(consoleAppender); rootLogger.addAppender(consoleAppender);
lc.getLogger("org.asamk").setLevel(verboseLevel > 1 ? Level.ALL : verboseLevel > 0 ? Level.DEBUG : Level.INFO); lc.getLogger("org.asamk").setLevel(verboseLevel > 1 ? Level.ALL : verboseLevel > 0 ? Level.DEBUG : Level.INFO);
lc.getLogger("org.asamk.Signal")
.setLevel(verboseLevel > 2 ? Level.ALL : verboseLevel > 1 ? Level.INFO : Level.WARN);
lc.getLogger("com.zaxxer.hikari.pool.PoolBase") lc.getLogger("com.zaxxer.hikari.pool.PoolBase")
.setLevel(verboseLevel > 2 ? Level.ALL : verboseLevel > 1 ? Level.INFO : Level.WARN); .setLevel(verboseLevel > 2 ? Level.ALL : verboseLevel > 1 ? Level.INFO : Level.WARN);
lc.getLogger("org.sqlite.core.NativeDB") lc.getLogger("org.sqlite.core.NativeDB")

View file

@ -37,9 +37,17 @@ public final class Scrubber {
* Supposedly, the shortest international phone numbers in use contain seven digits. * Supposedly, the shortest international phone numbers in use contain seven digits.
* Handles URL encoded +, %2B * Handles URL encoded +, %2B
*/ */
private static final Pattern E164_PATTERN = Pattern.compile("(\\+|%2B|/org/asamk/Signal/_)(\\d{5,13})(\\d{2})"); private static final Pattern E164_PATTERN = Pattern.compile("(\\+|%2B|_)(\\d{5,13})(\\d{2})");
private static final String E164_CENSOR = "*************"; private static final String E164_CENSOR = "*************";
private static final Pattern GROUP_V1_ID_PATTERN = Pattern.compile(
"(/org/asamk/Signal/.*Groups/[a-zA-Z0-9/_+-]{2}|[a-zA-Z0-9/_+-]{2})([a-zA-Z0-9/_+-]{18})([a-zA-Z0-9/_+-]{2})(==|__)");
private static final String GROUP_V1_ID_CENSOR = "*".repeat(18);
private static final Pattern GROUP_V2_ID_PATTERN = Pattern.compile(
"(/org/asamk/Signal/.*Groups/[a-zA-Z0-9/_+-]{2}|[a-zA-Z0-9/_+-]{2})([a-zA-Z0-9/_+-]{39})([a-zA-Z0-9/_+-]{2})([=_])");
private static final String GROUP_V2_ID_CENSOR = "*".repeat(39);
/** /**
* The second group will be censored. * The second group will be censored.
*/ */
@ -172,9 +180,11 @@ public final class Scrubber {
public static CharSequence scrub(CharSequence in) { public static CharSequence scrub(CharSequence in) {
in = scrubUuids(in);
in = scrubE164(in); in = scrubE164(in);
in = scrubEmail(in); in = scrubEmail(in);
in = scrubUuids(in); in = scrubGroupV2Ids(in);
in = scrubGroupV1Ids(in);
in = scrubDomains(in); in = scrubDomains(in);
in = scrubIpv4(in); in = scrubIpv4(in);
@ -189,6 +199,22 @@ public final class Scrubber {
.append(matcher.group(3))); .append(matcher.group(3)));
} }
private static CharSequence scrubGroupV1Ids(CharSequence in) {
return scrub(in,
GROUP_V1_ID_PATTERN,
(matcher, output) -> output.append(matcher.group(1))
.append(GROUP_V1_ID_CENSOR, 0, matcher.group(2).length())
.append(matcher.group(3)));
}
private static CharSequence scrubGroupV2Ids(CharSequence in) {
return scrub(in,
GROUP_V2_ID_PATTERN,
(matcher, output) -> output.append(matcher.group(1))
.append(GROUP_V2_ID_CENSOR, 0, matcher.group(2).length())
.append(matcher.group(3)));
}
private static CharSequence scrubEmail(CharSequence in) { private static CharSequence scrubEmail(CharSequence in) {
return scrub(in, return scrub(in,
CRUDE_EMAIL_PATTERN, CRUDE_EMAIL_PATTERN,