Skip to content

Commit 25cab2e

Browse files
authored
Merge pull request #4897 from owncloud/fix/cookie_header_redacted
fix: redact cookie headers to prevent information leaks
2 parents 3b0b27f + 52276e6 commit 25cab2e

3 files changed

Lines changed: 19 additions & 7 deletions

File tree

‎changelog/unreleased/4897‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
Security: Redact cookie headers in logs
2+
3+
Cookie headers have been redacted in the logs depending on the app
4+
configuration, in order to prevent sensitive information leaks.
5+
6+
https://github.com/owncloud/android/pull/4897

‎owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/HttpConstants.java‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2024 ownCloud GmbH.
2+
* Copyright (C) 2026 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -35,6 +35,7 @@ public class HttpConstants {
3535

3636
public static final String AUTHORIZATION_HEADER = "Authorization";
3737
public static final String COOKIE_HEADER = "Cookie";
38+
public static final String SET_COOKIE_HEADER = "Set-Cookie";
3839
public static final String BEARER_AUTHORIZATION_KEY = "Bearer ";
3940
public static final String USER_AGENT_HEADER = "User-Agent";
4041
public static final String IF_MATCH_HEADER = "If-Match";

‎owncloudComLibrary/src/main/java/com/owncloud/android/lib/common/http/logging/LogInterceptor.kt‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* ownCloud Android Library is available under MIT license
2-
* Copyright (C) 2023 ownCloud GmbH.
2+
* Copyright (C) 2026 ownCloud GmbH.
33
*
44
* Permission is hereby granted, free of charge, to any person obtaining a copy
55
* of this software and associated documentation files (the "Software"), to deal
@@ -24,7 +24,9 @@
2424
package com.owncloud.android.lib.common.http.logging
2525

2626
import com.owncloud.android.lib.common.http.HttpConstants.AUTHORIZATION_HEADER
27+
import com.owncloud.android.lib.common.http.HttpConstants.COOKIE_HEADER
2728
import com.owncloud.android.lib.common.http.HttpConstants.OC_X_REQUEST_ID
29+
import com.owncloud.android.lib.common.http.HttpConstants.SET_COOKIE_HEADER
2830
import com.squareup.moshi.Moshi
2931
import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory
3032
import okhttp3.Headers
@@ -85,11 +87,13 @@ class LogInterceptor : Interceptor {
8587

8688
private fun logHeaders(headers: Headers): Map<String, String> {
8789
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 }
9397
}
9498
return auxHeaders
9599
}
@@ -182,5 +186,6 @@ class LogInterceptor : Interceptor {
182186
private const val LIMIT_BODY_LOG: Long = 1000000
183187
private const val BINARY_OMITTED = "<-- Body end for response -- Binary -- Omitted:"
184188
private const val BYTES = "bytes -->"
189+
private const val REDACTED_VALUE = "[redacted]"
185190
}
186191
}

0 commit comments

Comments
 (0)