parentalcontrols: replacing the PIN now requires the old PIN on every entry path
- Commit
d53a59e99f407cbc38d1e01c8e4524b7974d93e0- Author
- Vayun Mathur <[email protected]>
- When
- 2026-12-01 09:15 UTC (5 days ago)
- Parents
5569aa5
Route.PinSetup was ungated on all entry paths: an explicit intent to the exported MainActivity (or an onNewIntent delivering PinSetup) stacked Dashboard+PinSetup unconditionally and rendered PinSetupScreen, whose onSet calls ParentPin.set — a function whose contract says the caller must have verified the old PIN first, and which does not check it. Anyone able to launch the activity overwrote the verifier, defeating the PIN gate and its brute-force lockout. Only first-run creation is legitimately ungated, and nothing distinguished it from a PIN change; the in-app Manage flow already went through the gate correctly. Cold start and external routing now send PinSetup to PinGate(ManagePin) when a PIN exists (setup only when none does), and pinSetupEntry itself redirects to the gate when a PIN is set and unverified — defence in depth, also covering re-challenge after backgrounding mid-change. Two regression tests pin the cold-start and external paths. Schedules, enforcement decisions and the enforcer were audited and cleared. Verified: :parentalcontrols:testDevUnitTest 99 tests pass; lint error is pre-existing on an untouched file.
Diff
parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/Navigation.kt
diff --git a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/Navigation.kt b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/Navigation.ktindex 7229cdfd49..1a72ace4b8 100644--- a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/Navigation.kt+++ b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/Navigation.kt@@ -63,7 +63,7 @@ fun Navigation( MainNavigation(backStack) { dashboardEntry(viewModel, pin, backStack, pinVerified, pendingControls, pendingAfterSetup) gatedEntries(viewModel, pinVerified, backStack)- pinSetupEntry(pin, scope, backStack, pendingAfterSetup, onFinish)+ pinSetupEntry(pin, pinVerified, scope, backStack, pendingAfterSetup, onFinish) pinGateEntry(viewModel, pin, scope, backStack, pinVerified, pendingControls, pendingAfterSetup, onFinish) } }
parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt
diff --git a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.ktindex b6e4c1a737..4146d8e84e 100644--- a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt+++ b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationEntries.kt@@ -2,6 +2,7 @@ package com.vayunmathur.parentalcontrols.ui import androidx.compose.runtime.Composable import androidx.compose.runtime.DisposableEffect+import androidx.compose.runtime.LaunchedEffect import androidx.compose.runtime.MutableState import androidx.compose.runtime.getValue import androidx.compose.runtime.mutableStateOf@@ -213,13 +214,20 @@ internal fun SchoolTimeEntry(viewModel: SupervisionViewModel) { /** The PIN-setup destination; completion hands over to the pending gate. */ internal fun EntryProviderScope<Route>.pinSetupEntry( pin: ParentPin,+ pinVerified: MutableState<Boolean>, scope: CoroutineScope, backStack: NavBackStack<Route>, pendingAfterSetup: MutableState<PinGateTarget?>, onFinish: () -> Unit, ) { entry<Route.PinSetup>(metadata = DetailPage()) {- PinSetupScreen(+ // Defence in depth: setup is ungated only for first-run creation.+ // With a PIN already set it is a PIN change and needs the ManagePin+ // gate pass (pinVerified) that normally precedes this destination.+ if (pin.isSet() && !pinVerified.value) {+ LaunchedEffect(Unit) { backStack.setLast(Route.PinGate(PinGateTarget.ManagePin)) }+ } else {+ PinSetupScreen( actions = PinSetupActions( onSet = { entry -> val after = pendingAfterSetup.value@@ -238,7 +246,8 @@ internal fun EntryProviderScope<Route>.pinSetupEntry( }, onCancel = { leaveGate(backStack, onFinish) }, ),- )+ )+ } } }
parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationGate.kt
diff --git a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationGate.kt b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationGate.ktindex 62b2b89380..cc98c9fa24 100644--- a/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationGate.kt+++ b/parentalcontrols/src/main/java/com/vayunmathur/parentalcontrols/ui/NavigationGate.kt@@ -24,6 +24,12 @@ internal fun rememberInitialBackStack( rememberNavBackStack<Route>(Route.PinGate(initialTarget)) initialTarget != null -> rememberNavBackStack<Route>(Route.PinSetup)+ initialRoute == Route.PinSetup && pinIsSet ->+ // PIN setup with a PIN already set is a PIN *change*: it must pass+ // the ManagePin gate first, never land straight on the setup form+ // (an explicit PIN-setup intent to the exported host would otherwise+ // overwrite the verifier with no old-PIN check).+ rememberNavBackStack<Route>(Route.Dashboard, Route.PinGate(PinGateTarget.ManagePin)) initialRoute == Route.PinSetup -> rememberNavBackStack<Route>(Route.Dashboard, Route.PinSetup) initialRoute == Route.Dashboard ->@@ -78,7 +84,12 @@ internal fun ExternalRouteEffect( route == Route.Dashboard -> backStack.reset(Route.Dashboard) PinGateTarget.forRoute(route) != null -> requestGated(backStack, pin, pinVerified, pendingAfterSetup, PinGateTarget.forRoute(route)!!)- route == Route.PinSetup -> requestSetup(backStack, pendingAfterSetup, null)+ route == Route.PinSetup ->+ if (pin.isSet()) {+ backStack.add(Route.PinGate(PinGateTarget.ManagePin))+ } else {+ requestSetup(backStack, pendingAfterSetup, null)+ } else -> backStack.add(route) } onExternalRouteConsumed()
parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt
diff --git a/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt b/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.ktindex 18f58e0b0c..2ed589c449 100644--- a/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt+++ b/parentalcontrols/src/test/java/com/vayunmathur/parentalcontrols/RouteAndUsageAccessTest.kt@@ -284,6 +284,45 @@ class RouteAndUsageAccessTest { } } + @Test fun navigationPinSetupWithPinSetRoutesToManagePinGate() {+ val pin = ParentPin.get(app)+ pin.clear()+ pin.set("1234")+ try {+ val vm = SupervisionViewModel(app)+ rule.setContent { Navigation(vm, initialRoute = Route.PinSetup) }+ rule.waitForIdle()+ // An explicit PIN-setup intent (exported host) must not land on+ // the setup form when a PIN exists: that would overwrite the+ // verifier with no old-PIN check.+ rule.onNodeWithText("Enter the parent PIN to change these settings.").assertIsDisplayed()+ } finally {+ pin.clear()+ }+ }++ @Test fun navigationExternalPinSetupWithPinSetRoutesToGate() {+ val pin = ParentPin.get(app)+ pin.clear()+ pin.set("1234")+ try {+ val vm = SupervisionViewModel(app)+ rule.setContent {+ Navigation(+ vm, initialRoute = Route.Dashboard,+ externalRoute = Route.PinSetup, onExternalRouteConsumed = {},+ )+ }+ rule.waitUntil(timeoutMillis = 8000) {+ runCatching {+ rule.onNodeWithText("Enter the parent PIN to change these settings.").assertIsDisplayed(); true+ }.getOrDefault(false)+ }+ } finally {+ pin.clear()+ }+ }+ @Test fun navigationDashboardIsUngated() { ParentPin.get(app).clear() val vm = SupervisionViewModel(app)