Logs: every log in app-private storage, shared as one scrubbed zip (#484)

Session folders, tool and installer logs and the stores' log now all live under the
app's private files/logs instead of Download/DroidDeck, and every existing "Share
logs" action bundles them into one zip that goes through a final scrub.

- Where: LinuxRuntime.logDir() = files/logs; sessions keep their dated folders and
  30-session pruning, tools/ and stores/ beside them. The "Logs" setting keeps its
  meaning. Game save backups stay in Download/DroidDeck/Saves.
- Migration: at first start the old session folders, tools/ and loose logs move from
  Download/DroidDeck into files/logs (Saves untouched), and every moved folder is
  scrubbed under the current rules.
- Scrubbing: one rule set (SecretScrub) for the stores' log and the zip. The scrub
  marker carries the rules version, so a rules change re-scrubs every folder at the
  next start (in the background, a few at a time). Steam login account names and
  emails, account-name fields, OAuth codes, tokens in URLs and private LAN
  addresses are removed; Windows exception codes and server addresses are kept.
- Share: one zip of the current session folder plus the last 7 days of stores/ and
  tools/, written to cache/share and handed to the share sheet.
This commit is contained in:
The412Banner authored and GitHub committed 2026-10-09 13:28:03 -04:00
1 parent 06e108a726
commit 71e2ae8683
24 files changed
+598 -121

No files matched your search

@@ -87,4 +87,65 @@ class LogRedactorTest {
assertEquals(once, LogRedactor.redact(once))
}
}
// The Steam UI's own login line (webhelper_js.txt), as the privacy scan found it.
@Test fun loginStateLineLosesAnEmailAccount() {
val line = "[2026-10-07 21:14:03] SteamUI: INFO: Login: OnLoginStateChange someone.masked@example.com 2 1 0 0"
val out = LogRedactor.redact(line)
assertFalse(out.contains("someone.masked"))
assertFalse(out.contains("example.com"))
assertEquals("[2026-10-07 21:14:03] SteamUI: INFO: Login: OnLoginStateChange <redacted:account> 2 1 0 0", out)
assertEquals(out, LogRedactor.redactForShare(line))
}
@Test fun loginStateLineLosesAPlainAccountName() {
val line = "[2026-10-07 21:14:03] SteamUI: INFO: Login: OnLoginStateChange maskeduser42 2 1 0 0"
val out = LogRedactor.redact(line)
assertFalse(out.contains("maskeduser42"))
assertEquals("[2026-10-07 21:14:03] SteamUI: INFO: Login: OnLoginStateChange <redacted:account> 2 1 0 0", out)
assertEquals(out, LogRedactor.redactForShare(line))
}
@Test fun loginStateWithoutAnAccountIsKept() {
val line = "SteamUI: INFO: Login: OnLoginStateChange 0 1 0 0"
assertEquals(line, LogRedactor.redact(line))
}
@Test fun accountNameFieldsAreRedacted() {
val lines = listOf(
"\t\"AccountName\"\t\t\"maskeduser42\"",
"account_name=maskeduser42 remember=1",
"{\"login\":\"maskeduser42\",\"persist\":1}",
"auth: login=maskeduser42&remember=1",
"accountName: maskeduser42",
"{\"username\": \"masked user 42\"}",
)
for (line in lines) {
val out = LogRedactor.redactForShare(line)
assertFalse(out, out.contains("maskeduser42") || out.contains("masked user"))
assertTrue(out, out.contains("<redacted:account>"))
assertEquals(out, LogRedactor.redactForShare(out))
}
}
@Test fun loginAsAWordIsNotAField() {
for (line in listOf("SteamUI: INFO: Login: OnLoginStateChange 0 1 0 0", "login refresh pending", "Login: state 5")) {
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))
}
}
@@ -0,0 +1,39 @@
package com.droiddeck.launcher.core
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Test
class SecretScrubTest {
private fun share(line: String) = SecretScrub.scrub(line, SecretScrub.Urls.KEEP_PATH, "<redacted:token>")
@Test fun windowsExceptionCodesAreKept() {
for (line in listOf(
"0024:trace:seh:dispatch_exception code=406d1388 flags=0 addr=00006FFFFFC0A6E8",
"0024:warn:seh:dispatch_exception code=c0000005 flags=0 addr=0000000140012345",
"0030:trace:seh:handle_syscall_fault code=80000003 flags=0",
"exception code=0xC0000005 at 0x140012345",
// An exception code stays one even on a line that also carries OAuth keys.
"client_id=abc code=c0000005",
)) assertEquals(line, share(line))
}
@Test fun anOAuthCodeIsBlanked() {
assertEquals("redirect client_id=34a02cf8 redirect_uri=x state=1 code=<redacted:token>",
share("redirect client_id=34a02cf8 redirect_uri=x state=1 code=AUTHCODE123"))
assertEquals("GET /on_login_success?code=<redacted:token>&scope=",
share("GET /on_login_success?code=AUTHCODE123&scope="))
assertEquals("exchange_code=<redacted:token>", share("exchange_code=0123456789abcdef"))
assertEquals("authorizationCode=<redacted:token>", share("authorizationCode=ABCD1234XYZ"))
}
@Test fun aCodeWithoutOAuthAroundItIsKept() {
for (line in listOf("exit code=1337", "status code=ERR_TIMEOUT", "code 403")) assertEquals(line, share(line))
}
@Test fun scrubbingTwiceChangesNothing() {
val once = share("client_id=1 code=AUTHCODE123 ?code=XYZW1234567")
assertFalse(once.contains("AUTHCODE123"))
assertEquals(once, share(once))
}
}
@@ -33,12 +33,13 @@ class SessionLogShareTest {
"rules $rules\n" + files.joinToString("") { val f = File(folder, it); "${f.length()}\t${f.lastModified()}\t$it\n" })
}
@Test fun aRecordedUnchangedFileGoesInAsItIs() {
@Test fun aRecordedUnchangedFileIsScrubbedAgainOnTheWayIntoTheZip() {
val folder = tmp.newFolder("2026-10-06-01-steam")
// Stands in for a file the ending scrubbed; the share must not pass it through again.
// A file the ending recorded as scrubbed still gets the share's final pass: the record
// may predate a rule, and a zip is the one way a log leaves the device.
File(folder, "session.log").writeText("$secret\n")
record(folder, "session.log")
assertTrue(zip(folder).getValue("session.log").contains(leaked))
assertFalse(zip(folder).getValue("session.log").contains(leaked))
}
@Test fun anythingTheRecordDoesNotVouchForIsScrubbed() {
@@ -0,0 +1,107 @@
package com.droiddeck.launcher.session
import com.droiddeck.launcher.runtime.LinuxRuntime
import java.io.File
import java.util.zip.ZipFile
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.robolectric.RobolectricTestRunner
import org.robolectric.RuntimeEnvironment
import org.robolectric.annotation.Config
/** A shared zip is scrubbed on the way in, whatever the files on disk still hold. */
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [33])
class SessionLogShareZipTest {
private val app get() = RuntimeEnvironment.getApplication()
@Test fun everyTextFileInTheZipIsScrubbedAndTheStoresAndToolsLogsComeAlong() {
val logs = LinuxRuntime.logDir(app)
val session = File(logs, "2026-10-08-01-steam").apply { mkdirs() }
// Written raw, as a file from before a rule existed would be.
File(session, "session.log").writeText(
"fetch https://gog-cdn-fastly.gog.com/token=nva=1791500000~dirs=/x~token=0a1b2c3d4e5f/content-system/v2/store/1/ab/cd/f\n" +
"fetch https://epicgames-download1.akamaized.net/Builds/Org/a/ChunksV4/12/ABCD.chunk?__token__=exp=1~hmac=deadbeefcafe\n" +
"login refresh_token=abcdef123456 user someone@example.com code=AUTHCODE123\n" +
"Authorization: Bearer abc.def.ghi\n" +
"kept: EResult 5, app 1086940, steamapps/common/Game\n"
)
File(logs, "stores").apply { mkdirs() }.resolve("stores-2026-10-08.log").writeText("epic: f_token=zzzzzzzz12 window 32\n")
File(logs, SessionPaths.TOOLS_DIR).apply { mkdirs() }.resolve("flatpak-install.log").writeText("== install\nCookie: steamLoginSecure=76561198000000000%7C%7Ceyabc\n")
val zip = SessionLogShare.zipFolder(app, session)!!
assertTrue(zip.path.startsWith(File(app.cacheDir, "share").path))
val text = ZipFile(zip).use { z -> z.entries().toList().associate { e -> e.name to z.getInputStream(e).bufferedReader().readText() } }
assertTrue(text.keys.containsAll(listOf("2026-10-08-01-steam/session.log", "stores/stores-2026-10-08.log", "tools/flatpak-install.log")))
val all = text.values.joinToString("\n")
for (secret in listOf("0a1b2c3d4e5f", "deadbeefcafe", "abcdef123456", "someone@example.com", "AUTHCODE123", "abc.def.ghi", "zzzzzzzz12", "eyabc")) {
assertFalse("$secret survived", all.contains(secret))
}
// What makes a log worth reading stays.
assertTrue(all.contains("kept: EResult 5, app 1086940, steamapps/common/Game"))
assertTrue(all.contains("https://gog-cdn-fastly.gog.com/"))
SessionLogShare.clear(app)
assertFalse(zip.exists())
}
@Test fun theSharePassChangesNothingInACleanLine() {
val line = "dxvk: Device 0x5 (Adreno 750) https://github.com/doitsujin/dxvk/releases code 403"
assertEquals(line, com.droiddeck.launcher.core.LogRedactor.redactForShare(line))
}
// Folders an earlier build scrubbed and marked under older rules, their copied Steam UI log
// still naming the account: one app start (the move out of Download/, then the pass over
// older folders) leaves every one scrubbed on disk under the current rules.
private fun olderFolder(parent: File, name: String, marker: String = ".scrubbed-2"): File {
val dir = File(parent, name).apply { mkdirs() }
File(dir, marker).writeText("scrubbed earlier\n")
File(dir, SessionArtifacts.SCRUBBED_TREE_MARKER).writeText("rules 2\n")
File(dir, "steam").apply { mkdirs() }.resolve("webhelper_js.txt").writeText(
"[2026-10-01 20:00:00] SteamUI: INFO: Login: OnLoginStateChange someone.masked@example.com 2 1 0 0\n" +
"[2026-10-01 20:00:01] SteamUI: INFO: Login: OnLoginStateChange maskeduser42 2 1 0 0\n" +
"[2026-10-01 20:00:02] SteamUI: INFO: Login: OnLoginStateChange 0 1 0 0\n" +
"0024:trace:seh:dispatch_exception code=c0000005 flags=0\n"
)
return dir
}
private fun assertScrubbed(dir: File) {
val text = File(dir, "steam/webhelper_js.txt").readText()
for (secret in listOf("someone.masked", "example.com", "maskeduser42")) assertFalse("$secret survived in $dir", text.contains(secret))
assertTrue(text.contains("Login: OnLoginStateChange <redacted:account> 2 1 0 0"))
assertTrue(text.contains("Login: OnLoginStateChange 0 1 0 0"))
assertTrue(text.contains("code=c0000005"))
val markers = dir.list()!!.filter { it.startsWith(".scrubbed-") && it != SessionArtifacts.SCRUBBED_TREE_MARKER }
assertEquals("$dir", listOf(".scrubbed-r${com.droiddeck.launcher.core.LogRedactor.RULES_VERSION}"), markers)
assertTrue(File(dir, SessionArtifacts.SCRUBBED_TREE_MARKER).readText()
.startsWith("rules ${com.droiddeck.launcher.core.LogRedactor.RULES_VERSION}\n"))
}
@Test fun aFolderMarkedUnderOlderRulesIsScrubbedAgainAtStart() {
val dir = olderFolder(LinuxRuntime.logDir(app), "2026-10-01-01-steam")
SessionArtifacts.scrubOlder(app)
assertScrubbed(dir)
}
@Test fun everyMigratedFolderIsScrubbedUnderTheCurrentRulesInOneStart() {
val legacy = LinuxRuntime.legacyLogDir().apply { mkdirs() }
val names = (1..9).map { "2026-10-0${it}-01-steam" }
names.forEachIndexed { i, name ->
// Old markers of every kind an earlier build left, one even claiming the current rules.
olderFolder(legacy, name, marker = listOf(".scrubbed-2", ".scrubbed-1", ".scrubbed-r${com.droiddeck.launcher.core.LogRedactor.RULES_VERSION}")[i % 3])
}
File(legacy, "Saves").apply { mkdirs() }.resolve("keep.txt").writeText("save\n")
// What MainActivity runs at start.
LogMigration.run(app)
SessionArtifacts.scrubOlder(app)
val logs = LinuxRuntime.logDir(app)
for (name in names) assertScrubbed(File(logs, name))
assertEquals(listOf("Saves"), legacy.list()!!.toList())
}
}