mirror of
https://github.com/Droid-Deck/DroidDeck.git
synced 2026-11-22 14:26:00 +00:00
Logs: fix the scrub marker's return; LAN addresses out of the zip
markScrubbed returns its try/catch result. The zip pass replaces private IPv4 addresses (10/8, 172.16/12, 192.168/16, 169.254/16) with <lan-address>; public server addresses stay.
This commit is contained in:
1 parent
facb4ce74c
commit
ec2f6e1461
4 files changed
+32
-4
No files matched your search
@@ -222,6 +222,15 @@ object LogRedactor {
|
||||
*/
|
||||
const val RULES_VERSION = 3
|
||||
|
||||
/**
|
||||
* A private IPv4 address (10/8, 172.16/12, 192.168/16, link-local 169.254/16): the home
|
||||
* network's layout, e.g. its router as the resolver. Blanked in a shared zip only; public
|
||||
* server addresses stay. Not part of a longer dotted number (a version like 10.0.19041.1).
|
||||
*/
|
||||
private val LAN_IPV4 = Regex(
|
||||
"(?<![\\d.])(?:10\\.\\d{1,3}|192\\.168|172\\.(?:1[6-9]|2\\d|3[01])|169\\.254)\\.\\d{1,3}\\.\\d{1,3}(?!\\.?\\d)"
|
||||
)
|
||||
|
||||
/** [src]'s lines, scrubbed, to [out]. */
|
||||
fun scrubTo(src: java.io.File, out: java.io.Writer) {
|
||||
src.forEachLine { line -> out.write(redact(line)); out.write("\n") }
|
||||
@@ -230,13 +239,14 @@ object LogRedactor {
|
||||
/**
|
||||
* The last pass for a file going into a shared zip: [redact], then the rules the stores' log
|
||||
* uses too ([SecretScrub]) - URLs without query, fragment and user:password and with any
|
||||
* token-bearing path segment blanked, token values and Authorization / Cookie headers blanked.
|
||||
* A line already clean comes out unchanged.
|
||||
* token-bearing path segment blanked, token values and Authorization / Cookie headers blanked
|
||||
* - and private IPv4 addresses as `<lan-address>`. A line already clean comes out unchanged.
|
||||
*/
|
||||
fun redactForShare(line: String): String {
|
||||
if (line.isEmpty()) return line
|
||||
return try {
|
||||
SecretScrub.scrub(redact(line), SecretScrub.Urls.KEEP_PATH, "<redacted:token>")
|
||||
val out = SecretScrub.scrub(redact(line), SecretScrub.Urls.KEEP_PATH, "<redacted:token>")
|
||||
LAN_IPV4.replace(out, "<lan-address>")
|
||||
} catch (t: Throwable) {
|
||||
"<redaction failed; line withheld>"
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ object SessionArtifacts {
|
||||
Log.w(TAG, "$dir is not fully scrubbed; it is scrubbed again when shared")
|
||||
return false
|
||||
}
|
||||
try {
|
||||
return try {
|
||||
File(dir, SCRUBBED_MARKER).writeText("scrubbed ${now()}\n")
|
||||
val lines = StringBuilder("rules ${LogRedactor.RULES_VERSION}\n")
|
||||
record.files.forEach { (f, s) ->
|
||||
|
||||
@@ -133,4 +133,19 @@ class LogRedactorTest {
|
||||
assertEquals(line, LogRedactor.redact(line))
|
||||
}
|
||||
}
|
||||
|
||||
@Test fun privateAddressesLeaveTheZipPublicOnesStay() {
|
||||
assertEquals("I/LinuxNetworkLink: resolver: <lan-address> <lan-address> 8.8.8.8",
|
||||
LogRedactor.redactForShare("I/LinuxNetworkLink: resolver: 192.168.1.1 10.0.0.138 8.8.8.8"))
|
||||
assertEquals("gateway <lan-address>:53 link <lan-address> lan <lan-address>",
|
||||
LogRedactor.redactForShare("gateway 172.16.4.20:53 link 169.254.10.2 lan 172.31.255.254"))
|
||||
for (line in listOf(
|
||||
"connecting to CM 162.254.193.47:27017",
|
||||
"public 172.32.0.1 and 11.0.0.1 and 193.168.1.1",
|
||||
"Windows 10.0.19041.1 build 10.0.19045",
|
||||
"Proton 10.0-3, driver 25.1.0.4",
|
||||
)) assertEquals(line, LogRedactor.redactForShare(line))
|
||||
val once = LogRedactor.redactForShare("resolver: 192.168.0.1")
|
||||
assertEquals(once, LogRedactor.redactForShare(once))
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user