Skip to content

Commit c3e2b98

Browse files
meisterTmattem
andauthored
redact 'token' strings from logging (bazelbuild#16764)
It's common for users to set 'TOKEN' as an env var. While this is a little like whack-a-mole and we can't cover everything, this seems like a common string to redact. Closes bazelbuild#16622. PiperOrigin-RevId: 488392632 Change-Id: I7b48199cc140d6736cd145df63e03eeda747c7fb (cherry picked from commit 1940c5d) Co-authored-by: Matt Mackay <[email protected]>
1 parent 3bda5c9 commit c3e2b98

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

src/main/java/com/google/devtools/build/lib/runtime/SafeRequestLogging.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,15 @@
2121
/** Utils for logging safely user commandlines. */
2222
public class SafeRequestLogging {
2323
private static final Pattern suppressFromLog =
24-
Pattern.compile("--client_env=([^=]*(?:auth|pass|cookie)[^=]*)=", Pattern.CASE_INSENSITIVE);
24+
Pattern.compile(
25+
"--client_env=([^=]*(?:auth|pass|cookie|token)[^=]*)=", Pattern.CASE_INSENSITIVE);
2526

2627
private SafeRequestLogging() {}
2728

2829
/**
2930
* Generates a string form of a request to be written to the logs, filtering the user environment
3031
* to remove anything that looks private. The current filter criteria removes any variable whose
31-
* name includes "auth", "pass", or "cookie".
32+
* name includes "auth", "pass", "cookie" or "token".
3233
*
3334
* @return the filtered request to write to the log.
3435
*/

src/test/java/com/google/devtools/build/lib/runtime/SafeRequestLoggingTest.java

+10
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,16 @@ public void testGetRequestLogStringStripsApparentPasswordValues() {
6969
"[--client_env=dont_paSS_ME=__private_value_removed__, --client_env=other=isprinted]");
7070
}
7171

72+
@Test
73+
public void testGetRequestLogStringStripsApparentTokenValues() {
74+
assertThat(
75+
SafeRequestLogging.getRequestLogString(
76+
ImmutableList.of(
77+
"--client_env=service_ToKEn=notprinted", "--client_env=other=isprinted")))
78+
.isEqualTo(
79+
"[--client_env=service_ToKEn=__private_value_removed__, --client_env=other=isprinted]");
80+
}
81+
7282
@Test
7383
public void testGetRequestLogIgnoresSensitiveTermsInValues() {
7484
assertThat(SafeRequestLogging.getRequestLogString(ImmutableList.of("--client_env=ok=COOKIE")))

0 commit comments

Comments
 (0)