mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-21 05:46:03 +00:00
Preserve Android shared-library names in logs
This commit is contained in:
1 parent
6521c3c3ad
commit
536bb11df8
2 files changed
+56
-1
No files matched your search
@@ -47,7 +47,21 @@ object LogRedactor {
|
||||
out.toString()
|
||||
}
|
||||
|
||||
private fun matchesEntire(input: String, regex: Regex): Boolean =
|
||||
withMatcher(regex, input) { it.matches() }
|
||||
|
||||
private fun isHidlSharedLibrary(input: String, match: java.util.regex.Matcher): Boolean {
|
||||
if (!matchesEntire(match.group(), HIDL_SHARED_LIBRARY)) return false
|
||||
fun continuesToken(char: Char) = char.isLetterOrDigit() || char in "._%+@-"
|
||||
return (match.start() == 0 || !continuesToken(input[match.start() - 1])) &&
|
||||
(match.end() == input.length || !continuesToken(input[match.end()]))
|
||||
}
|
||||
|
||||
private val EMAIL = Regex("[A-Za-z0-9._%+\\-]+@[A-Za-z0-9.\\-]+\\.[A-Za-z]{2,}")
|
||||
private val HIDL_SHARED_LIBRARY = Regex(
|
||||
"(?:android\\.(?:hardware|frameworks|hidl|system)|vendor\\.[A-Za-z0-9_]+\\.hardware)" +
|
||||
"(?:\\.[A-Za-z0-9_]+)+@[0-9]+\\.[0-9]+(?:-[A-Za-z0-9_]+)*\\.so"
|
||||
)
|
||||
private val JWT_LABELLED = Regex("(?i)(\\bJWT[\\s=:]+)(\\d{8,})")
|
||||
private val JWT_BASE64 = Regex("ey[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}\\.[A-Za-z0-9_\\-]{6,}")
|
||||
private val GUID = Regex("\\b[0-9A-Fa-f]{8}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{4}-[0-9A-Fa-f]{12}\\b")
|
||||
@@ -345,7 +359,9 @@ object LogRedactor {
|
||||
}
|
||||
if (out.has("login")) out.set(replaceMatches(out.text, LOGIN_KV) { "${it.group(1)}${it.group(2)}${quoted(it.group(3))}" })
|
||||
for (r in accounts) if (r.needs == null || out.has(r.needs)) out.set(replaceMatches(out.text, r.regex, "<redacted:account>"))
|
||||
if ('@' in out.text) out.set(replaceMatches(out.text, EMAIL, "<redacted:email>"))
|
||||
if ('@' in out.text) out.set(replaceMatches(out.text, EMAIL) { m ->
|
||||
m.group().takeIf { isHidlSharedLibrary(out.text, m) } ?: "<redacted:email>"
|
||||
})
|
||||
if (out.has("jwt", "token", "ticket", "sessionid", "steamloginsecure", "machineauth")) {
|
||||
out.set(replaceMatches(out.text, RESIDUAL) { "${it.group(1)}=<redacted:token>" })
|
||||
}
|
||||
|
||||
@@ -42,6 +42,45 @@ class LogRedactorTest {
|
||||
assertEquals("login <redacted:email> ok", LogRedactor.redact("login someone@example.com ok"))
|
||||
}
|
||||
|
||||
@Test fun hidlSharedLibrariesStayVisibleWhileAdjacentSecretsAndEmailsAreRedacted() {
|
||||
val library = "android.hardware.graphics.mapper@4.0.so"
|
||||
val vendorLibrary = "vendor.qti.hardware.display.mapper@4.0.so"
|
||||
val line = "/vendor/lib64/hw/$library loaded $vendorLibrary contact=someone@company.so token=abcdef123456"
|
||||
val expected = "/vendor/lib64/hw/$library loaded $vendorLibrary contact=<redacted:email> token=<redacted:token>"
|
||||
|
||||
assertEquals(expected, LogRedactor.redact(line))
|
||||
assertEquals(expected, LogRedactor.redactForShare(line))
|
||||
}
|
||||
|
||||
@Test fun privacyRulesOverrideTheHidlSharedLibraryException() {
|
||||
val library = "android.hardware.graphics.mapper@4.0.so"
|
||||
assertEquals("token=<redacted:token>", LogRedactor.redact("token=$library"))
|
||||
assertEquals("username=<redacted:account>", LogRedactor.redact("username=$library"))
|
||||
|
||||
val users = tmp.newFile("hidl-loginusers.vdf")
|
||||
users.writeText("\"AccountName\" \"$library\"")
|
||||
try {
|
||||
LogRedactor.learnAccounts(users)
|
||||
assertEquals("<redacted:account>", LogRedactor.redact(library))
|
||||
} finally {
|
||||
LogRedactor.learnAccounts()
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun onlyExactHidlSharedLibraryNamesBypassEmailRedaction() {
|
||||
val library = "android.hardware.graphics.mapper@4.0.so"
|
||||
|
||||
assertEquals(library, LogRedactor.redact(library))
|
||||
assertEquals("<redacted:email>", LogRedactor.redact("$library.evil"))
|
||||
assertEquals("<redacted:email>", LogRedactor.redact("someone@company.so"))
|
||||
assertEquals("<redacted:email>", LogRedactor.redact("not$library"))
|
||||
assertEquals("<redacted:email>_debug", LogRedactor.redact("${library}_debug"))
|
||||
assertEquals("<redacted:email>.1", LogRedactor.redact("${library}.1"))
|
||||
assertEquals("<redacted:email>@attacker", LogRedactor.redact("${library}@attacker"))
|
||||
assertEquals("<redacted:email>", LogRedactor.redact("android.hardware.graphics.mapper@4.0.software"))
|
||||
assertEquals("<redacted:email>", LogRedactor.redact("android.hardware.graphics.mapper@4.0.so.evil"))
|
||||
}
|
||||
|
||||
@Test fun clockTimeIsNotAnAddress() {
|
||||
val line = "[2026-09-27 10:03:05] Startup"
|
||||
assertEquals(line, LogRedactor.redact(line))
|
||||
|
||||
Reference in new issue
Block a user