From 79a40d93b337a680f4644c96a350719bf62e8790 Mon Sep 17 00:00:00 2001 From: The412Banner Date: Fri, 9 Oct 2026 11:57:08 -0400 Subject: [PATCH] Logs: scrub Steam account names everywhere, keep Proton exception codes Older session folders kept the Steam login account in steam/webhelper_js.txt (OnLoginStateChange ): their scrub marker predated the account rules and never expired. The marker now carries the rules version, so folders scrubbed under older rules are scrubbed again at app start (every subfolder), and folders moved out of Download/ are scrubbed after the move. New rules: OnLoginStateChange , AccountName / account_name / username / login fields. A bare code= is blanked only in a query string or beside OAuth keys, never as an 8-hex exception code. --- .../droiddeck/launcher/core/LogRedactor.kt | 27 ++++++++++- .../droiddeck/launcher/core/SecretScrub.kt | 21 +++++++-- .../launcher/session/LogMigration.kt | 12 ++++- .../launcher/session/SessionArtifacts.kt | 38 +++++++++------ .../launcher/core/LogRedactorTest.kt | 46 +++++++++++++++++++ .../launcher/core/SecretScrubTest.kt | 39 ++++++++++++++++ .../session/SessionLogShareZipTest.kt | 36 +++++++++++++++ docs/progress-log.md | 14 ++++++ 8 files changed, 213 insertions(+), 20 deletions(-) create mode 100644 app/src/test/java/com/droiddeck/launcher/core/SecretScrubTest.kt diff --git a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt index 23bad40c6a..a46f037750 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/LogRedactor.kt @@ -75,9 +75,24 @@ object LogRedactor { * user who signs in with a plain account name, not an email, had it in every log. The single * space then a non-space keeps "OnLoginStateChange 0 1 0 0" (no account yet) as it is. */ - private val LOGIN_STATE = Regex("(OnLoginStateChange )(\\S+)") + private val LOGIN_STATE = Regex("(?i)(OnLoginStateChange:? )([^\\s<]\\S*)") private val LOGIN_USERS = Regex("(OnLoginUsersChanged )(\\S.*)$") + /** + * An account name as a field: `AccountName`, `account_name`, `username` (`"AccountName" + * "someone"` in a VDF, `account_name=...`, `"username": "..."`) and `login` - the last only + * as `login=`, a quoted key or a VDF pair, so "Login: OnLoginStateChange ..." keeps its label. + * A quoted value is blanked whole; one already blanked is left as it is. + */ + private const val ACCOUNT_VALUE = "(\"[^\"<\\r\\n]+\"|'[^'<\\r\\n]+'|[^\\s\"'<>&;,}]+)" + private val ACCOUNT_KV = Regex( + "(?i)(? = emptyList() @@ -205,7 +220,7 @@ object LogRedactor { * only when that matches, so a folder scrubbed under older rules is scrubbed again on the way * out. */ - const val RULES_VERSION = 2 + const val RULES_VERSION = 3 /** [src]'s lines, scrubbed, to [out]. */ fun scrubTo(src: java.io.File, out: java.io.Writer) { @@ -232,6 +247,12 @@ object LogRedactor { src.forEachLine { line -> out.write(redactForShare(line)); out.write("\n") } } + /** ``, inside [value]'s quotes when it had them. */ + private fun quoted(value: String): String { + val q = value.first().takeIf { it == '"' || it == '\'' }?.toString().orEmpty() + return "$q$q" + } + /** [line] with every credential shape replaced. Null- and exception-safe by construction. */ fun redact(line: String): String { if (line.isEmpty()) return line @@ -260,6 +281,8 @@ object LogRedactor { for (r in own) out = r.replace(out, "") out = LOGIN_STATE.replace(out) { "${it.groupValues[1]}" } out = LOGIN_USERS.replace(out) { "${it.groupValues[1]}" } + out = ACCOUNT_KV.replace(out) { "${it.groupValues[1]}${it.groupValues[2]}${quoted(it.groupValues[3])}" } + out = LOGIN_KV.replace(out) { "${it.groupValues[1]}${it.groupValues[2]}${quoted(it.groupValues[3])}" } for (r in accounts) out = r.replace(out, "") out = EMAIL.replace(out, "") out = RESIDUAL.replace(out) { "${it.groupValues[1]}=" } diff --git a/app/src/main/java/com/droiddeck/launcher/core/SecretScrub.kt b/app/src/main/java/com/droiddeck/launcher/core/SecretScrub.kt index 76a2fe302c..c91ca60ef9 100644 --- a/app/src/main/java/com/droiddeck/launcher/core/SecretScrub.kt +++ b/app/src/main/java/com/droiddeck/launcher/core/SecretScrub.kt @@ -9,7 +9,9 @@ package com.droiddeck.launcher.core * and a plain first path segment (the stores' lines, where a GOG secure link carries its token in * the path); [Urls.KEEP_PATH] keeps the path but blanks any segment that carries a token. * - Outside URLs, the values of token-like keys (`token`, `__token__`, `f_token`, `hdnts`, access / - * refresh / id tokens; `code=` and exchange codes of four characters or more) and of + * refresh / id tokens; exchange and authorization codes of four characters or more, and a bare + * `code=` where it is one: in a query string or on a line with OAuth keys such as `client_id`, + * `redirect_uri` or `state`, never an 8-hex exception code like Proton's `code=c0000005`) and of * Authorization / Cookie headers are blanked with [mark]. * * A line already scrubbed comes out unchanged. @@ -21,13 +23,26 @@ object SecretScrub { private val SAFE_SEGMENT = Regex("""[A-Za-z0-9._\-]{1,40}""") private val TOKEN_SEGMENT = Regex("""(?i)(token|hdnts|hmac|signature|sig|exp)=""") private val TOKEN = Regex("""(?i)(?}]+""") - private val CODE = Regex("""(?i)(?}]{4,}""") + /** Codes that are only ever OAuth grants. */ + private val GRANT_CODE = Regex("""(?i)(?}]{4,}""") + /** A bare `code=`: a grant only right after `?` / `&` (a query string) or beside OAuth keys ([OAUTH_CONTEXT]). */ + private val CODE = Regex("""(?i)(?}]{4,})""") + private val OAUTH_CONTEXT = Regex("""(?i)(? if (urls == Urls.SHORT) short(m.value) else keepPath(m.value, mark) } out = TOKEN.replace(out) { m -> m.groupValues[1] + m.groupValues[2] + mark } - out = CODE.replace(out) { m -> m.groupValues[1] + m.groupValues[2] + mark } + out = GRANT_CODE.replace(out) { m -> m.groupValues[1] + m.groupValues[2] + mark } + val oauth = OAUTH_CONTEXT.containsMatchIn(text) + val src = out + out = CODE.replace(src) { m -> + val inQuery = m.range.first > 0 && src[m.range.first - 1] in "?&" + val grant = !STATUS_CODE.matches(m.groupValues[3]) && (oauth || inQuery) + if (grant) m.groupValues[1] + m.groupValues[2] + mark else m.value + } out = HEADER.replace(out) { m -> m.groupValues[1] + m.groupValues[2] + mark } return out } diff --git a/app/src/main/java/com/droiddeck/launcher/session/LogMigration.kt b/app/src/main/java/com/droiddeck/launcher/session/LogMigration.kt index e5e1ba6a04..b52228e820 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/LogMigration.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/LogMigration.kt @@ -9,7 +9,8 @@ import java.io.File /** * Once, on the first start of a build with private logs: the session folders, tools/ and the loose * tool logs that earlier builds left in `Download/DroidDeck/` move into `files/logs/`. Best effort: - * an item that cannot be moved stays where it is. Nothing else in that folder is touched - game + * an item that cannot be moved stays where it is. Moved session folders are scrubbed again under the + * current rules ([SessionArtifacts.scrubMoved]). Nothing else in that folder is touched - game * save backups (Saves/) stay public - and after this pass the app never reads it again. */ object LogMigration { @@ -26,6 +27,7 @@ object LogMigration { // Unreadable (no storage access yet): try again next start rather than give up on them. if (items == null) { Log.w(TAG, "$legacy cannot be listed; logs there stay until it can"); return } var moved = 0 + val movedFolders = ArrayList() for (f in items) { val isLog = SessionPaths.isSessionFolder(f) || (f.isDirectory && f.name == SessionPaths.TOOLS_DIR) || @@ -33,8 +35,14 @@ object LogMigration { if (!isLog) continue val dest = File(if (f.isFile) File(target, SessionPaths.TOOLS_DIR).apply { mkdirs() } else target, f.name) if (dest.exists() && f.name != SessionPaths.TOOLS_DIR) continue - if (move(f, dest)) moved++ else Log.w(TAG, "could not move ${f.name}; left in place") + if (move(f, dest)) { + moved++ + if (SessionPaths.isSessionFolder(dest)) movedFolders.add(dest) + } else Log.w(TAG, "could not move ${f.name}; left in place") } + // Earlier builds scrubbed these under older rules (or not at all) and marked them done; + // they go through the current redactor before anything can share them. + SessionArtifacts.scrubMoved(context, movedFolders) try { marker.writeText("moved $moved item(s)\n") } catch (e: Exception) { Log.w(TAG, "could not mark the move: ${e.message}") } if (moved > 0) Log.i(TAG, "moved $moved log item(s) from $legacy into $target") } diff --git a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt index 6c2c03fe52..4a552675db 100644 --- a/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt +++ b/app/src/main/java/com/droiddeck/launcher/session/SessionArtifacts.kt @@ -31,8 +31,12 @@ object SessionArtifacts { /** Written last; a folder without it did not get its ending. */ const val COMPLETE_MARKER = ".complete" - /** Every file in the folder has been through the redactor, own addresses and accounts included (-2: accounts added). */ - private const val SCRUBBED_MARKER = ".scrubbed-2" + /** + * Every file in the folder has been through the redactor under its current rules. Named after + * [LogRedactor.RULES_VERSION], so a folder scrubbed under older rules is scrubbed again. + */ + private val SCRUBBED_MARKER = ".scrubbed-r${LogRedactor.RULES_VERSION}" + private val OLD_SCRUBBED_MARKER = Regex("""\.scrubbed-(r?\d+)""") /** * Written by a session's own ending, and only when every file in the folder, subfolders @@ -67,10 +71,11 @@ object SessionArtifacts { } /** - * Once, for session folders written before every file was scrubbed and before the device's own - * addresses were (network.txt listed them; the client's IPv6 check logs "external address" - * into steam/connection_log.txt): the whole folder, steam/ included, through the redactor. - * A marker records it. Runs at app start with [finishAbandoned]. + * For session folders not yet scrubbed under the redactor's current rules - written before + * every file was scrubbed, before the device's own addresses or the Steam account were, or + * moved in from Download/ ([LogMigration]): the whole folder, steam/ and every other subfolder + * included, through the redactor. A marker records it. Runs at app start with + * [finishAbandoned]. */ @Synchronized fun scrubOlder(context: Context) { @@ -78,13 +83,20 @@ object SessionArtifacts { val dirs = LinuxRuntime.logDir(context).listFiles { f -> SessionPaths.isSessionFolder(f) && f != current && !File(f, SCRUBBED_MARKER).exists() } ?: return + scrubFolders(context, dirs.toList()) + if (dirs.isNotEmpty()) Log.i(TAG, "scrubbed ${dirs.size} older session folder(s)") + } + + /** [dirs] (session folders [LogMigration] just moved in) through the redactor, whatever their markers say. */ + @Synchronized + fun scrubMoved(context: Context, dirs: List) { + scrubFolders(context, dirs.filter { SessionPaths.isSessionFolder(it) && it != SessionPaths.current() }) + } + + private fun scrubFolders(context: Context, dirs: List) { if (dirs.isEmpty()) return LogRedactor.learnFromRuntime(LinuxRuntime.rootDir(context)) - dirs.forEach { dir -> - Record(dir).let { r -> scrubFolder(dir, r); File(dir, "steam").takeIf { it.isDirectory }?.let { scrubFolder(it, r) } } - try { File(dir, SCRUBBED_MARKER).writeText("scrubbed ${now()}\n") } catch (e: Exception) {} - } - Log.i(TAG, "scrubbed ${dirs.size} older session folder(s)") + dirs.forEach { scrubAndMark(it) } } /** @@ -152,6 +164,7 @@ object SessionArtifacts { return } try { + dir.listFiles { f -> OLD_SCRUBBED_MARKER.matches(f.name) }?.forEach { it.delete() } File(dir, SCRUBBED_MARKER).writeText("scrubbed ${now()}\n") val lines = StringBuilder("rules ${LogRedactor.RULES_VERSION}\n") record.files.forEach { (f, s) -> @@ -181,8 +194,7 @@ object SessionArtifacts { }.toSet() } - /** The end-of-session scrub of [dir] on its own (steam/ already in place), for tests. */ - @androidx.annotation.VisibleForTesting + /** The end-of-session scrub of [dir] on its own (steam/ already in place); also the pass over older and moved folders. */ internal fun scrubAndMark(dir: File) = markScrubbed(scrubTree(Record(dir))) /** diff --git a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt index 8b21590974..1dea75db49 100644 --- a/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/core/LogRedactorTest.kt @@ -87,4 +87,50 @@ 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 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 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("")) + 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)) + } + } } diff --git a/app/src/test/java/com/droiddeck/launcher/core/SecretScrubTest.kt b/app/src/test/java/com/droiddeck/launcher/core/SecretScrubTest.kt new file mode 100644 index 0000000000..86ff6ece8f --- /dev/null +++ b/app/src/test/java/com/droiddeck/launcher/core/SecretScrubTest.kt @@ -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, "") + + @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=", + share("redirect client_id=34a02cf8 redirect_uri=x state=1 code=AUTHCODE123")) + assertEquals("GET /on_login_success?code=&scope=", + share("GET /on_login_success?code=AUTHCODE123&scope=")) + assertEquals("exchange_code=", share("exchange_code=0123456789abcdef")) + assertEquals("authorizationCode=", 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)) + } +} diff --git a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt index 319b9ef3a9..0e296d6997 100644 --- a/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt +++ b/app/src/test/java/com/droiddeck/launcher/session/SessionLogShareZipTest.kt @@ -52,4 +52,40 @@ class SessionLogShareZipTest { val line = "dxvk: Device 0x5 (Adreno 750) https://github.com/doitsujin/dxvk/releases code 403" assertEquals(line, com.droiddeck.launcher.core.LogRedactor.redactForShare(line)) } + + // A folder an earlier build scrubbed and marked under older rules, its copied Steam UI log + // still naming the account: the pass at app start (and after the move out of Download/) + // scrubs it again on disk. + private fun olderFolder(name: String): File { + val dir = File(LinuxRuntime.logDir(app), name).apply { mkdirs() } + File(dir, ".scrubbed-2").writeText("scrubbed earlier\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" + ) + 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", text.contains(secret)) + assertTrue(text.contains("Login: OnLoginStateChange 2 1 0 0")) + assertTrue(text.contains("Login: OnLoginStateChange 0 1 0 0")) + assertFalse(File(dir, ".scrubbed-2").exists()) + assertTrue(File(dir, ".scrubbed-r${com.droiddeck.launcher.core.LogRedactor.RULES_VERSION}").exists()) + } + + @Test fun aFolderMarkedUnderOlderRulesIsScrubbedAgainAtStart() { + val dir = olderFolder("2026-10-01-01-steam") + SessionArtifacts.scrubOlder(app) + assertScrubbed(dir) + } + + @Test fun aMovedFolderIsScrubbedWhateverItsMarkersSay() { + val dir = olderFolder("2026-10-01-02-steam") + File(dir, ".scrubbed-r${com.droiddeck.launcher.core.LogRedactor.RULES_VERSION}").writeText("claimed\n") + SessionArtifacts.scrubMoved(app, listOf(dir)) + assertScrubbed(dir) + } } diff --git a/docs/progress-log.md b/docs/progress-log.md index c0829621a5..dbd1631623 100644 --- a/docs/progress-log.md +++ b/docs/progress-log.md @@ -36,6 +36,20 @@ the timeline, then lessons and backlog. Companion to the README (what the app *d both blank token values and Authorization / Cookie headers; the two test suites pass on it. The Plasma desktop writes nothing outside the session folder (its output is the session's `desktop.log`), so there was nothing new to move. +- **Privacy scan fixes:** the Steam login account (an email, 374 times) was still in older + folders' copied `steam/webhelper_js.txt` (`SteamUI: INFO: Login: OnLoginStateChange `): + those folders carried a scrub marker from before the account rules, and the marker never + expired. The marker is now named after the redactor's rules version (`.scrubbed-r3`), so every + folder scrubbed under older rules goes through again at app start, steam/ and every subfolder + included; folders moved out of `Download/DroidDeck` are scrubbed after the move whatever their + markers say (`SessionArtifacts.scrubMoved`). New rules: `OnLoginStateChange `, and + `AccountName` / `account_name` / `username` / `login` fields (`login` only as `login=`, a quoted + key or a VDF pair, so the "Login:" label stays). The `code=` rule no longer touches Proton's + exception codes (`code=c0000005`, `406d1388`, `80000003`): a bare `code=` is blanked only right + after `?`/`&` or on a line with OAuth keys (`client_id`, `redirect_uri`, `state`, tokens), and + never when it is 8 hex digits; exchange / authorization codes are always blanked. Tests: + `LogRedactorTest` (the login line with an email and with a plain name), `SecretScrubTest`, + `SessionLogShareZipTest` (older and moved folders scrubbed on disk). ## 2026-10-08 - `feat/stores`: GOG, Epic Games and Amazon Games in the launcher (in progress) A new **Stores** section - the three storefronts' libraries and public catalogs, one download