git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v2 2/3] http: make GIT_TRACE_CURL auth redaction optional

From
JTJonathan Tan <jonathantanmy@google.com>
Date
May 13, 2020, 19:12 UTC
Message-ID
<8c70a45b24861290b64d4487383bdfa5960332ab.1589394456.git.jonathantanmy@google.com>
In-Reply-To
<cover.1589394456.git.jonathantanmy@google.com>

By default, auth headers are redacted when a trace is output through GIT_TRACE_CURL. Allow the user to inhibit this redaction through an environment variable.

Signed-off-by: Jonathan Tan <jonathantanmy@google.com>
---
 Documentation/git.txt       |  6 ++++++
 http.c                      | 11 +++++++++--
 t/t5551-http-fetch-smart.sh | 10 ++++++++++
 3 files changed, 25 insertions(+), 2 deletions(-)
diff --git a/Documentation/git.txt b/Documentation/git.txt
index 9d6769e95a..af98cd7dc2 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -777,6 +777,12 @@ for full details.
 	See `GIT_TRACE2` for available trace output options and
 	link:technical/api-trace2.html[Trace2 documentation] for full details.
 
+`GIT_REDACT_AUTHORIZATION`::
+	By default, when a curl trace is enabled (see `GIT_TRACE_CURL` above),
+	the values of "Authorization:" and "Proxy-Authorization:" headers in
+	the trace are redacted. Set this variable to `0` to prevent this
+	redaction.
+
 `GIT_REDACT_COOKIES`::
 	This can be set to a comma-separated list of strings. When a curl trace
 	is enabled (see `GIT_TRACE_CURL` above), whenever a "Cookies:" header
diff --git a/http.c b/http.c
index 62aa995245..77eac95d64 100644
--- a/http.c
+++ b/http.c
@@ -18,6 +18,7 @@
 
 static struct trace_key trace_curl = TRACE_KEY_INIT(CURL);
 static int trace_curl_data = 1;
+static int trace_curl_redact_authorization = 1;
 static struct string_list cookies_to_redact = STRING_LIST_INIT_DUP;
 #if LIBCURL_VERSION_NUM >= 0x070a08
 long int git_curl_ipresolve = CURL_IPRESOLVE_WHATEVER;
@@ -642,8 +643,9 @@ static void redact_sensitive_header(struct strbuf *header)
 {
 	const char *sensitive_header;
 
-	if (skip_prefix(header->buf, "Authorization:", &sensitive_header) ||
-	    skip_prefix(header->buf, "Proxy-Authorization:", &sensitive_header)) {
+	if (trace_curl_redact_authorization &&
+	    (skip_prefix(header->buf, "Authorization:", &sensitive_header) ||
+	     skip_prefix(header->buf, "Proxy-Authorization:", &sensitive_header))) {
 		/* The first token is the type, which is OK to log */
 		while (isspace(*sensitive_header))
 			sensitive_header++;
@@ -859,6 +861,7 @@ static int get_curl_http_version_opt(const char *version_string, long *opt)
 static CURL *get_curl_handle(void)
 {
 	CURL *result = curl_easy_init();
+	const char *redact_authorization_envvar;
 
 	if (!result)
 		die("curl_easy_init failed");
@@ -997,6 +1000,10 @@ static CURL *get_curl_handle(void)
 	setup_curl_trace(result);
 	if (getenv("GIT_TRACE_CURL_NO_DATA"))
 		trace_curl_data = 0;
+	redact_authorization_envvar = getenv("GIT_REDACT_AUTHORIZATION");
+	if (redact_authorization_envvar &&
+	    !strcmp(redact_authorization_envvar, "0"))
+		trace_curl_redact_authorization = 0;
 	if (getenv("GIT_REDACT_COOKIES")) {
 		string_list_split(&cookies_to_redact,
 				  getenv("GIT_REDACT_COOKIES"), ',', -1);
diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
index acc8473a72..eeecfe01d7 100755
--- a/t/t5551-http-fetch-smart.sh
+++ b/t/t5551-http-fetch-smart.sh
@@ -197,6 +197,16 @@ test_expect_success 'GIT_TRACE_CURL redacts auth details' '
 	grep "Authorization: Basic <redacted>" trace
 '
 
+test_expect_success 'GIT_TRACE_CURL does not redact auth details if GIT_REDACT_AUTHORIZATION=0' '
+	rm -rf redact-auth trace &&
+	set_askpass user@host pass@host &&
+	GIT_REDACT_AUTHORIZATION=0 GIT_TRACE_CURL="$(pwd)/trace" \
+		git clone --bare "$HTTPD_URL/auth/smart/repo.git" redact-auth &&
+	expect_askpass both user@host &&
+
+	grep "Authorization: Basic [0-9a-zA-Z+/]" trace
+'
+
 test_expect_success 'disable dumb http on server' '
 	git --git-dir="$HTTPD_DOCUMENT_ROOT_PATH/repo.git" \
 		config http.getanyfile false
-- 
2.26.2.645.ge9eca65c58-goog
Previous: Jonathan TanNext: Junio C Hamano
Message 15 of 21 in “Safer GIT_CURL_VERBOSE”
  1. 0/2 Safer GIT_CURL_VERBOSEJonathan Tan, May 11, 2020
  2. 1/2 t5551: test that GIT_TRACE_CURL redacts passwordJonathan Tan, May 11, 2020
  3. Jeff KingMay 12, 2020
  4. 2/2 http, imap-send: stop using CURLOPT_VERBOSEJonathan Tan, May 11, 2020
  5. Jeff KingMay 12, 2020
  6. Jonathan TanMay 12, 2020
  7. Jeff KingMay 12, 2020
  8. brian m. carlsonMay 12, 2020
  9. Junio C HamanoMay 13, 2020
  10. Jeff KingMay 13, 2020
  11. Junio C HamanoMay 13, 2020
  12. Daniel StenbergMay 13, 2020
  13. Jeff KingMay 13, 2020
  14. 0/3 Safer GIT_CURL_VERBOSEJonathan Tan, May 13, 2020
  15. 2/3 http: make GIT_TRACE_CURL auth redaction optionalJonathan Tan, May 13, 2020
  16. Junio C HamanoMay 13, 2020
  17. 1/3 t5551: test that GIT_TRACE_CURL redacts passwordJonathan Tan, May 13, 2020
  18. 3/3 http, imap-send: stop using CURLOPT_VERBOSEJonathan Tan, May 13, 2020
  19. Junio C HamanoMay 13, 2020
  20. Junio C HamanoMay 13, 2020
  21. Jeff KingMay 15, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.