forked from git-for-windows/git
-
Notifications
You must be signed in to change notification settings - Fork 97
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Redact unsafe URLs in the Trace2 output (#616)
The Trace2 output can contain secrets when a user issues a Git command with sensitive information in the command-line. A typical (if highly discouraged) example is: `git clone https://user:[email protected]/`. With this PR, the Trace2 output redacts passwords in such URLs by default. This series also includes a commit to temporarily disable leak checking on t0210,t0211 because the tests uncover other unrelated bugs in Git.
- Loading branch information
Showing
6 changed files
with
253 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
test_description='test trace2 facility (normal target)' | ||
|
||
TEST_PASSES_SANITIZE_LEAK=true | ||
TEST_PASSES_SANITIZE_LEAK=false | ||
. ./test-lib.sh | ||
|
||
# Turn off any inherited trace2 settings for this test. | ||
|
@@ -283,4 +283,22 @@ test_expect_success 'using global config with include' ' | |
test_cmp expect actual | ||
' | ||
|
||
test_expect_success 'unsafe URLs are redacted by default' ' | ||
test_when_finished \ | ||
"rm -r trace.normal unredacted.normal clone clone2" && | ||
test_config_global \ | ||
"url.$(pwd).insteadOf" https://user:[email protected]/ && | ||
test_config_global trace2.configParams "core.*,remote.*.url" && | ||
GIT_TRACE2="$(pwd)/trace.normal" \ | ||
git clone https://user:[email protected]/ clone && | ||
! grep user:pwd trace.normal && | ||
GIT_TRACE2_REDACT=0 GIT_TRACE2="$(pwd)/unredacted.normal" \ | ||
git clone https://user:[email protected]/ clone2 && | ||
grep "start .* clone https://user:[email protected]" unredacted.normal && | ||
grep "remote.origin.url=https://user:[email protected]" unredacted.normal | ||
' | ||
|
||
test_done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
test_description='test trace2 facility (perf target)' | ||
|
||
TEST_PASSES_SANITIZE_LEAK=true | ||
TEST_PASSES_SANITIZE_LEAK=false | ||
. ./test-lib.sh | ||
|
||
# Turn off any inherited trace2 settings for this test. | ||
|
@@ -268,4 +268,23 @@ test_expect_success PTHREADS 'global counter test/test2' ' | |
have_counter_event "main" "counter" "test" "test2" 60 actual | ||
' | ||
|
||
test_expect_success 'unsafe URLs are redacted by default' ' | ||
test_when_finished \ | ||
"rm -r actual trace.perf unredacted.perf clone clone2" && | ||
test_config_global \ | ||
"url.$(pwd).insteadOf" https://user:[email protected]/ && | ||
test_config_global trace2.configParams "core.*,remote.*.url" && | ||
GIT_TRACE2_PERF="$(pwd)/trace.perf" \ | ||
git clone https://user:[email protected]/ clone && | ||
! grep user:pwd trace.perf && | ||
GIT_TRACE2_REDACT=0 GIT_TRACE2_PERF="$(pwd)/unredacted.perf" \ | ||
git clone https://user:[email protected]/ clone2 && | ||
perl "$TEST_DIRECTORY/t0211/scrub_perf.perl" <unredacted.perf >actual && | ||
grep "d0|main|start|.* clone https://user:[email protected]" actual && | ||
grep "d0|main|def_param|.*|remote.origin.url:https://user:[email protected]" actual | ||
' | ||
|
||
test_done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,4 +323,44 @@ test_expect_success 'discard traces when there are too many files' ' | |
head -n2 trace_target_dir/git-trace2-discard | tail -n1 | grep \"event\":\"too_many_files\" | ||
' | ||
|
||
# In the following "...redact..." tests, skip testing the GIT_TRACE2_REDACT=0 | ||
# case because we would need to exactly model the full JSON event stream like | ||
# we did in the basic tests above and I do not think it is worth it. | ||
|
||
test_expect_success 'unsafe URLs are redacted by default in cmd_start events' ' | ||
test_when_finished \ | ||
"rm -r trace.event" && | ||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \ | ||
test-tool trace2 300redact_start git clone https://user:[email protected]/ clone2 && | ||
! grep user:pwd trace.event | ||
' | ||
|
||
test_expect_success 'unsafe URLs are redacted by default in child_start events' ' | ||
test_when_finished \ | ||
"rm -r trace.event" && | ||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \ | ||
test-tool trace2 301redact_child_start git clone https://user:[email protected]/ clone2 && | ||
! grep user:pwd trace.event | ||
' | ||
|
||
test_expect_success 'unsafe URLs are redacted by default in exec events' ' | ||
test_when_finished \ | ||
"rm -r trace.event" && | ||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \ | ||
test-tool trace2 302redact_exec git clone https://user:[email protected]/ clone2 && | ||
! grep user:pwd trace.event | ||
' | ||
|
||
test_expect_success 'unsafe URLs are redacted by default in def_param events' ' | ||
test_when_finished \ | ||
"rm -r trace.event" && | ||
GIT_TRACE2_EVENT="$(pwd)/trace.event" \ | ||
test-tool trace2 303redact_def_param url https://user:[email protected]/ && | ||
! grep user:pwd trace.event | ||
' | ||
|
||
test_done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters