Skip to content

Commit 3c52d45

Browse files
committed
trace2: redact URLs in alias events
trace2_cmd_alias_fl() passes its argument array directly to the targets. A URL embedded in an ordinary alias definition, or passed through a shell alias, can therefore appear in an alias event without the redaction used for start, child_start, and exec events. Redact the arguments before alias-event dispatch and release the temporary array afterward. Signed-off-by: Taylor Blau <ttaylorr@openai.com>
1 parent 7ce7828 commit 3c52d45

2 files changed

Lines changed: 13 additions & 1 deletion

File tree

t/t0212-trace2-event.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,4 +407,11 @@ test_expect_success 'URL signature redaction can be disabled' '
407407
test_grep "\"event\":\"error\".*sig=secret" trace.event
408408
'
409409

410+
test_expect_success 'alias events redact URL signatures' '
411+
test_when_finished "rm trace.event" &&
412+
test_config alias.redact "rev-parse --sq-quote https://example.com/?sig=secret" &&
413+
GIT_TRACE2_EVENT="$(pwd)/trace.event" git redact >/dev/null &&
414+
test_grep "\"event\":\"alias\".*sig=<REDACTED>" trace.event
415+
'
416+
410417
test_done

trace2.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,14 +560,19 @@ void trace2_cmd_alias_fl(const char *file, int line, const char *alias,
560560
const char **argv)
561561
{
562562
struct tr2_tgt *tgt_j;
563+
const char **redacted;
563564
int j;
564565

565566
if (!trace2_enabled)
566567
return;
567568

569+
redacted = redact_argv(argv);
570+
568571
for_each_wanted_builtin (j, tgt_j)
569572
if (tgt_j->pfn_alias_fl)
570-
tgt_j->pfn_alias_fl(file, line, alias, argv);
573+
tgt_j->pfn_alias_fl(file, line, alias, redacted);
574+
575+
free_redacted_argv(redacted, argv);
571576
}
572577

573578
void trace2_cmd_list_config_fl(const char *file, int line)

0 commit comments

Comments
 (0)