|
1 | 1 | /* ownCloud Android Library is available under MIT license |
2 | | - * Copyright (C) 2023 ownCloud GmbH. |
| 2 | + * Copyright (C) 2026 ownCloud GmbH. |
3 | 3 | * |
4 | 4 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
5 | 5 | * of this software and associated documentation files (the "Software"), to deal |
|
24 | 24 | package com.owncloud.android.lib.common.http.logging |
25 | 25 |
|
26 | 26 | import com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER |
| 27 | +import com.owncloud.android.lib.common.http.HttpConstants.COOKIE_HEADER |
27 | 28 | import com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID |
| 29 | +import com.owncloud.android.lib.common.http.HttpConstants.SET_COOKIE_HEADER |
28 | 30 | import com.squareup.moshi.Moshi |
29 | 31 | import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory |
30 | 32 | import okhttp3.Headers |
@@ -85,11 +87,13 @@ class LogInterceptor : Interceptor { |
85 | 87 |
|
86 | 88 | private fun logHeaders(headers: Headers): Map<String, String> { |
87 | 89 | val auxHeaders = headers.toMap().toMutableMap() |
88 | | - if (auxHeaders.contains(AUTHORIZATION_HEADER)) { |
89 | | - val authHeaderList = auxHeaders[AUTHORIZATION_HEADER]!!.split(" ") |
90 | | - val authType = authHeaderList[0] |
91 | | - val authInfo = if (redactAuthHeader) "[redacted]" else authHeaderList[1] |
92 | | - auxHeaders[AUTHORIZATION_HEADER] = "$authType $authInfo" |
| 90 | + if (redactAuthHeader) { |
| 91 | + if (AUTHORIZATION_HEADER in auxHeaders) { |
| 92 | + val authType = auxHeaders[AUTHORIZATION_HEADER]!!.substringBefore(" ") |
| 93 | + auxHeaders[AUTHORIZATION_HEADER] = "$authType $REDACTED_VALUE" |
| 94 | + } |
| 95 | + if (COOKIE_HEADER in auxHeaders) { auxHeaders[COOKIE_HEADER] = REDACTED_VALUE } |
| 96 | + if (SET_COOKIE_HEADER in auxHeaders) { auxHeaders[SET_COOKIE_HEADER] = REDACTED_VALUE } |
93 | 97 | } |
94 | 98 | return auxHeaders |
95 | 99 | } |
@@ -182,5 +186,6 @@ class LogInterceptor : Interceptor { |
182 | 186 | private const val LIMIT_BODY_LOG: Long = 1000000 |
183 | 187 | private const val BINARY_OMITTED = "<-- Body end for response -- Binary -- Omitted:" |
184 | 188 | private const val BYTES = "bytes -->" |
| 189 | + private const val REDACTED_VALUE = "[redacted]" |
185 | 190 | } |
186 | 191 | } |
0 commit comments