Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

redact 'token' strings from logging #16622

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@
/** Utils for logging safely user commandlines. */
public class SafeRequestLogging {
private static final Pattern suppressFromLog =
Pattern.compile("--client_env=([^=]*(?:auth|pass|cookie)[^=]*)=", Pattern.CASE_INSENSITIVE);
Pattern.compile("--client_env=([^=]*(?:auth|pass|cookie|token)[^=]*)=", Pattern.CASE_INSENSITIVE);

private SafeRequestLogging() {}

/**
* Generates a string form of a request to be written to the logs, filtering the user environment
* to remove anything that looks private. The current filter criteria removes any variable whose
* name includes "auth", "pass", or "cookie".
* name includes "auth", "pass", "cookie" or "token".
*
* @return the filtered request to write to the log.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,16 @@ public void testGetRequestLogStringStripsApparentPasswordValues() {
"[--client_env=dont_paSS_ME=__private_value_removed__, --client_env=other=isprinted]");
}

@Test
public void testGetRequestLogStringStripsApparentTokenValues() {
assertThat(
SafeRequestLogging.getRequestLogString(
ImmutableList.of(
"--client_env=service_ToKEn=notprinted", "--client_env=other=isprinted")))
.isEqualTo(
"[--client_env=service_ToKEn=__private_value_removed__, --client_env=other=isprinted]");
}

@Test
public void testGetRequestLogIgnoresSensitiveTermsInValues() {
assertThat(SafeRequestLogging.getRequestLogString(ImmutableList.of("--client_env=ok=COOKIE")))
Expand Down