Skip to content

Commit

Permalink
refactor: info redaction
Browse files Browse the repository at this point in the history
- Also redact basic auth password
- Ignore blank values
- Use actual string length of redacted info
  • Loading branch information
tien committed Jun 30, 2023
1 parent c497188 commit 2384013
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions app/src/main/java/com/tien/piholeconnect/util/SnackBar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,11 @@ suspend fun SnackbarHostState.showGenericPiHoleConnectionError(
class SnackbarErrorViewModel @Inject constructor(
userPreferencesRepository: UserPreferencesRepository,
) : ViewModel() {
val sensitiveData =
userPreferencesRepository.userPreferencesFlow.map { preferences -> preferences.piHoleConnectionsList.map { it.apiToken } }
val sensitiveData = userPreferencesRepository.userPreferencesFlow.map { preferences ->
preferences.piHoleConnectionsList.flatMap { listOf(it.apiToken, it.basicAuthPassword) }
.map { it.trim() }.filter { it.isNotBlank() }
}

}

@Composable
Expand All @@ -83,7 +86,7 @@ fun SnackbarErrorEffect(

val sensitiveData by viewModel.sensitiveData.collectAsStateWithLifecycle(listOf())
val sanitize = { string: String ->
sensitiveData.fold(string) { acc, curr -> acc.replace(curr, "***") }
sensitiveData.fold(string) { acc, curr -> acc.replace(curr, "*".repeat(curr.length)) }
}

var errorToDisplay by remember { mutableStateOf<Throwable?>(null) }
Expand Down

0 comments on commit 2384013

Please sign in to comment.