Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/SECURITY_AND_REDACTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,10 @@ regardless of which inspector captured it.

## Default policy

`RedactionPolicy.default()`'s 25 sensitive field names (case-insensitive, matched against header
`RedactionPolicy.default()`'s sensitive field names (case-insensitive, matched against header
names, JSON keys, and form field names):

```text
authorization proxy-authorization www-authenticate authentication
cookie set-cookie x-api-key api-key
apikey x-auth-token x-access-token x-csrf-token
x-xsrf-token access_token refresh_token id_token
Expand All @@ -24,9 +23,7 @@ passphrase secret client_secret private_key
session_id
```

A matched value is replaced wholesale with `<redacted>`. Independently of the field-name list, any
`Bearer <token>` text pattern is redacted wherever it appears (e.g. inside a body that isn't valid
JSON/form data), so a leaked bearer token in a non-standard location is still caught.
A matched value is replaced wholesale with `<redacted>`. `Authorization` headers and Bearer tokens are kept unredacted by default to allow developers to inspect and copy tokens during debugging; custom `textPatterns` and additional `sensitiveFieldNames` can be configured via `RedactionPolicy` if further redaction is desired.

## Redaction strategies beyond removal

Expand Down
4 changes: 2 additions & 2 deletions docs/THREAT_MODEL.md
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,8 @@ a remedy, not a proof of control.

## Redaction is an allowlist, and allowlists miss things

`RedactionPolicy.default()` matches a fixed set of ~25 field names (case-insensitively) against
header names, JSON keys, and form/query field names, plus one regex for `Bearer <token>` text. See
`RedactionPolicy.default()` matches a set of sensitive field names (case-insensitively) against
header names, JSON keys, and form/query field names. See
[SECURITY_AND_REDACTION.md](SECURITY_AND_REDACTION.md) for the exact list.

Everything not on that list is transmitted and stored **verbatim**. In practice that means:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -963,7 +963,12 @@ private fun ConnectUrlPanel(
TextButton(
onClick = {
clipboard.setText(AnnotatedString(connectUrl))
val message = if (usesSessionCode) "Session code copied -- keep it private" else "Dashboard URL copied"
val message =
if (usesSessionCode) {
"Session code copied -- keep it private"
} else {
"Dashboard URL copied"
}
Toast.makeText(context, message, Toast.LENGTH_SHORT).show()
},
modifier = Modifier.align(Alignment.End),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,12 @@ class MainActivity : Activity() {
val url = connectUrl ?: return@setOnClickListener
val clipboard = getSystemService(ClipboardManager::class.java)
clipboard.setPrimaryClip(ClipData.newPlainText("DevConsole dashboard URL", url))
val message = if (url.contains("#code=")) "Session code copied -- keep it private" else "Dashboard URL copied"
val message =
if (url.contains("#code=")) {
"Session code copied -- keep it private"
} else {
"Dashboard URL copied"
}
Toast.makeText(this@MainActivity, message, Toast.LENGTH_SHORT).show()
}
}
Expand Down Expand Up @@ -501,7 +506,7 @@ class MainActivity : Activity() {
"No session code is required in the default open mode. Use SESSION_CODE before sharing " +
"a LAN-bound dashboard on an untrusted network.\n\n"
} +
"This debugging session uses local-network HTTP. Other participants on an untrusted network " +
"This debugging session uses local-network HTTP. Other participants on an untrusted network " +
"may observe or modify traffic. Use ADB localhost mode or a trusted isolated network " +
"for sensitive testing."
statusView.text = message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class ComposerRequestTest {
ComposerRequest(
method = "POST",
url = "https://api.test/orders?access_token=url-canary",
headers = mapOf("Authorization" to "Bearer header-canary", "Accept" to "application/json"),
headers = mapOf("Cookie" to "session=header-canary", "Accept" to "application/json"),
body = """{"password":"body-canary","keep":"visible"}""",
query = listOf(ComposerQueryParameter("token", "query-canary")),
formFields = mapOf("client_secret" to "form-canary"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class EventBatchWriterTest {
val writer = EventBatchWriter(store, this, capacity = 2, maxBatchSize = 2, flushIntervalMs = 1000)
writer.start()

writer.submit(event("Bearer first-secret"))
writer.submit(event("Bearer second-secret"))
writer.submit(event("password=first-secret"))
writer.submit(event("password=second-secret"))
testScheduler.runCurrent()

assertEquals(1, store.batches.size)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@ class EventPipelineTest {
pluginId = "network",
type = "network.request",
severity = EventSeverity.INFO,
summary = "Authorization: Bearer raw-token",
tags = mapOf("Authorization" to "Bearer another-token", "route" to "/orders"),
summary = "password=raw-token",
tags = mapOf("Cookie" to "session=another-token", "route" to "/orders"),
),
)

val event = pipeline.snapshot().single()
assertFalse(event.summary.contains("raw-token"))
assertEquals("<redacted>", event.tags.getValue("Authorization"))
assertEquals("<redacted>", event.tags.getValue("Cookie"))
assertEquals("/orders", event.tags.getValue("route"))
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class EventExportWriterTest {
ExportRequest(
sessionId = "session-1",
destination = destination,
events = listOf(event(summary = "request Bearer export-secret")),
events = listOf(event(summary = "password=export-secret")),
),
)

Expand Down Expand Up @@ -122,7 +122,7 @@ class EventExportWriterTest {
"event-1" to
TimelineAnnotation(
bookmarked = true,
note = "Authorization: Bearer note-secret",
note = "password=note-secret",
),
),
)
Expand All @@ -131,7 +131,7 @@ class EventExportWriterTest {
ZipFile(destination).use { zip ->
val timeline = zip.getInputStream(zip.getEntry("timeline.jsonl")).bufferedReader().readText()
assertTrue(timeline.contains("\"bookmarked\":true"))
assertTrue(timeline.contains("\"note\":\"Authorization: <redacted>\""))
assertTrue(timeline.contains("\"note\":\"password=<redacted>\""))
assertFalse(timeline.contains("note-secret"))
}
} finally {
Expand Down Expand Up @@ -316,7 +316,7 @@ class EventExportWriterTest {
val request =
evidenceRequest(destination).withEvidenceBundle(
baseEvidenceBundle().copy(
reportMarkdown = "Summary: Authorization: Bearer report-secret",
reportMarkdown = "password=report-secret",
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1336,6 +1336,11 @@ private fun NetworkTransaction.evidenceDetailJson(): String =
capture.request.url.path
.escapeJson(),
).append('"')
append(",\"query\":\"")
.append(
capture.request.url.queryString
.escapeJson(),
).append('"')
append(",\"status\":").append(capture.response?.statusCode ?: "null")
val contentType = (capture.response?.contentType ?: capture.request.contentType).orEmpty()
append(",\"contentType\":\"").append(contentType.escapeJson()).append('"')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class AndroidFileInspectorTest {
@Test
fun `preview redacts text file contents`() {
File(application.filesDir, "secret.txt")
.writeText("authorization: Bearer sk-super-secret-value-1234567890")
.writeText("password=sk-super-secret-value-1234567890")

val preview = inspector.preview("files", "secret.txt")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class AndroidInspectorExporterTest {
NetworkRequestInput(
method = "GET",
url = "https://api.example.test$path",
headers = mapOf("Authorization" to "Bearer $SECRET_TOKEN"),
headers = mapOf("Cookie" to "session=$SECRET_TOKEN"),
),
NetworkResponseInput(
statusCode = 200,
Expand Down Expand Up @@ -187,7 +187,7 @@ class AndroidInspectorExporterTest {
wallTimeMs = 10,
monoTimeNs = 10,
severity = 3,
summary = "Checkout failed: Authorization Bearer $SECRET_TOKEN",
summary = "password=$SECRET_TOKEN",
tagsJson = "{}",
payloadJson = null,
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,12 @@ class AndroidPreferencesInspectorTest {
application
.getSharedPreferences("secret_prefs", Context.MODE_PRIVATE)
.edit()
.putString("auth_token", "Bearer sk-super-secret-value-1234567890")
.putString("access_token", "sk-super-secret-value-1234567890")
.putInt("count", 3)
.commit()

val file = inspector.files().first { it.name == "secret_prefs" }
val tokenEntry = file.entries.first { it.key == "auth_token" }
val tokenEntry = file.entries.first { it.key == "access_token" }

assertFalse(tokenEntry.value.contains("sk-super-secret-value-1234567890"))
assertTrue(tokenEntry.redacted)
Expand Down
4 changes: 2 additions & 2 deletions sdk/full/src/test/kotlin/io/devconsole/CrashCaptureTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,10 @@ class CrashCaptureTest {

@Test
fun `the crash payload is redacted`() {
capture().recordAnr("main", "called with Authorization: Bearer topsecret123")
capture().recordAnr("main", "password=topsecret123")

assertTrue(
"expected the token to be redacted: ${appended.single().payloadJson}",
"expected the password to be redacted: ${appended.single().payloadJson}",
"topsecret123" !in appended.single().payloadJson.orEmpty(),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ import org.robolectric.annotation.Config
@RunWith(RobolectricTestRunner::class)
@Config(sdk = [34])
class CrashPolicyGatingTest {
private fun anrWatchdogThreadRunning(): Boolean = Thread.getAllStackTraces().keys.any { it.name == ANR_THREAD_NAME }
private fun anrWatchdogThreadRunning(): Boolean =
Thread.getAllStackTraces().keys.any { it.name == ANR_THREAD_NAME && it.isAlive }

/**
* Thread start/interrupt-triggered exit are asynchronous relative to the call that triggers
Expand Down Expand Up @@ -89,6 +90,7 @@ class CrashPolicyGatingTest {
@Test
fun `anrWatchdogEnabled = false never starts the watchdog thread`() =
runTest {
awaitThreadState(expectedRunning = false, timeoutMs = 2_000L)
val provider = PlatformFacadeProvider()
val config = DevConsoleConfig.default().withCrashPolicy(CrashPolicy(anrWatchdogEnabled = false))
provider.initialize(ApplicationProvider.getApplicationContext(), config)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,12 +90,13 @@ class FullInspectorDataSourceTest {
id: String,
startedAtEpochMs: Long,
completedAtEpochMs: Long?,
url: String = "https://api.example.test/orders",
) {
val capture =
captureFactory.capture(
NetworkRequestInput(
method = "GET",
url = "https://api.example.test/orders",
url = url,
headers = mapOf("X-Request-Id" to id),
),
NetworkResponseInput(
Expand Down Expand Up @@ -728,6 +729,29 @@ class FullInspectorDataSourceTest {
assertTrue(evidence.items("session-1").isEmpty())
}

/**
* The traffic list row shows path + query, and it reads that query back off `url` -- so the
* mapping has to carry the query across there, while `path` stays the bare endpoint that
* mock-rule prefill escapes into a regex.
*/
@Test
fun `snapshot carries a transaction's query string on the url, not folded into the path`() {
val store = networkStore()
recordTransaction(
store,
"tx-query",
startedAtEpochMs = 0,
completedAtEpochMs = 5,
url = "https://api.example.test/orders?status=open&page=2",
)
val source = FullInspectorDataSource(store, MockEngine(emptyList()), configSupplier = { null })

val transaction = source.snapshot().transactions.single()

assertEquals("/orders", transaction.path)
assertEquals("https://api.example.test/orders?status=open&page=2", transaction.url)
}

@Test
fun `snapshot maps transactions, mock rules, and capabilities from the underlying engines`() {
val store = networkStore()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,11 +207,18 @@ class RemoteConfigInspectorTest {
}

@Test
fun `a bearer token inside an ordinary value is still scrubbed`() {
val entries = redactingBoundary().apply(listOf(entry("welcome_banner", "Bearer abc123def")))
fun `a secret inside an ordinary value is still scrubbed when policy specifies pattern`() {
val policy =
RedactionPolicy(
sensitiveFieldNames = emptySet(),
textPatterns = listOf(Regex("secret-[0-9]+")),
)
val entries =
RedactingRemoteConfig(RedactionEngine(policy), policy)
.apply(listOf(entry("welcome_banner", "secret-12345")))

assertTrue(entries.single().redacted)
assertFalse(entries.single().value.contains("abc123def"))
assertFalse(entries.single().value.contains("secret-12345"))
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class LogRecorderTest {
@Test
fun `records a redacted entry`() {
LogRecorder(redaction, sink, nowEpochMs = { 42L })
.record(LogLevel.INFO, "Checkout", "calling with Authorization: Bearer abc123def")
.record(LogLevel.INFO, "Checkout", "password=abc123def")

val entry = emitted.single()
assertEquals(LogLevel.INFO, entry.level)
assertEquals("Checkout", entry.tag)
assertEquals(42L, entry.timestampEpochMs)
assertTrue("expected the bearer token to be redacted, got: ${entry.message}", "abc123def" !in entry.message)
assertTrue("expected the password to be redacted, got: ${entry.message}", "abc123def" !in entry.message)
assertNull(entry.stackTrace)
}

Expand Down
1 change: 1 addition & 0 deletions sdk/network/api/network.api
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,7 @@ public final class io/devconsole/network/NetworkUrl {
public final fun getHost ()Ljava/lang/String;
public final fun getPath ()Ljava/lang/String;
public final fun getQuery ()Ljava/util/Map;
public final fun getQueryString ()Ljava/lang/String;
public final fun getScheme ()Ljava/lang/String;
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,17 @@ data class NetworkUrl(
val path: String,
val query: Map<String, String>,
) {
/**
* The already-redacted query in `a=1&b=2` form, empty when the request carried no parameters.
* Split out of [display] so a list row can show the query beside the path without having to
* re-parse a full URL string.
*/
val queryString: String get() = query.entries.joinToString("&") { "${it.key}=${it.value}" }

val display: String get() =
buildString {
append("$scheme://$host$path")
if (query.isNotEmpty()) append('?').append(query.entries.joinToString("&") { "${it.key}=${it.value}" })
if (query.isNotEmpty()) append('?').append(queryString)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,22 @@ class NetworkCaptureFactoryTest {
private val factory = NetworkCaptureFactory(RedactionEngine(RedactionPolicy.default()))

@Test
fun `redacts headers query and textual body before producing capture`() {
fun `redacts headers query and textual body before producing capture while preserving authorization`() {
val capture =
factory.capture(
request =
NetworkRequestInput(
method = "POST",
url = "https://example.test/orders?access_token=raw-secret",
headers = mapOf("Authorization" to "Bearer header-secret"),
body = "Bearer body-secret".encodeToByteArray(),
headers = mapOf("Authorization" to "Bearer header-token", "Cookie" to "session=header-secret"),
body = "{\"password\":\"body-secret\"}".encodeToByteArray(),
contentType = "application/json",
),
response = null,
)

assertEquals("<redacted>", capture.request.headers.getValue("Authorization"))
assertEquals("Bearer header-token", capture.request.headers.getValue("Authorization"))
assertEquals("<redacted>", capture.request.headers.getValue("Cookie"))
assertFalse(
capture.request.url.display
.contains("raw-secret"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class NetworkExportTest {
NetworkRequestInput(
method = "POST",
url = "https://example.test/orders?access_token=query-secret",
headers = mapOf("Authorization" to "Bearer header-secret"),
body = "Bearer body-secret".encodeToByteArray(),
headers = mapOf("Cookie" to "session=header-secret"),
body = "{\"password\":\"body-secret\"}".encodeToByteArray(),
contentType = "application/json",
),
NetworkResponseInput(statusCode = 201),
Expand Down Expand Up @@ -286,7 +286,7 @@ class NetworkExportTest {
NetworkRequestInput(
method = "POST",
url = "https://example.test/orders",
headers = mapOf("Authorization" to "Bearer header-secret"),
headers = mapOf("Cookie" to "session=header-secret"),
body = "{\"token\":\"body-secret\"}".encodeToByteArray(),
contentType = "application/json",
),
Expand Down
Loading