Skip to content

Commit 6709e31

Browse files
committed
Do not send telemetry for aliases
1 parent 73f3900 commit 6709e31

2 files changed

Lines changed: 35 additions & 10 deletions

File tree

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Aliases should not leak their user-defined names via telemetry, but the
2+
# resolved inner command should still record normally — its path is a core
3+
# gh command and conveys no user-authored identifier.
4+
5+
env GH_PRIVATE_ENABLE_TELEMETRY=1
6+
env GH_TELEMETRY=log
7+
env GH_TELEMETRY_SAMPLE_RATE=100
8+
9+
# Create a regular (non-shell) alias that resolves to an existing command.
10+
exec gh alias set secret-project-alias version
11+
12+
# Invoking the alias must not produce any event carrying the alias name.
13+
exec gh secret-project-alias
14+
! stderr 'secret-project-alias'
15+
16+
# The resolved inner command still records telemetry as normal.
17+
stderr 'Telemetry payload:'
18+
stderr '"command": "gh version"'

pkg/cmd/root/alias.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,15 @@ import (
1010

1111
"github.com/cli/cli/v2/internal/run"
1212
"github.com/cli/cli/v2/internal/text"
13+
"github.com/cli/cli/v2/pkg/cmdutil"
1314
"github.com/cli/cli/v2/pkg/findsh"
1415
"github.com/cli/cli/v2/pkg/iostreams"
1516
"github.com/google/shlex"
1617
"github.com/spf13/cobra"
1718
)
1819

1920
func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
20-
return &cobra.Command{
21+
cmd := &cobra.Command{
2122
Use: aliasName,
2223
Short: fmt.Sprintf("Shell alias for %q", text.Truncate(80, aliasValue)),
2324
RunE: func(c *cobra.Command, args []string) error {
@@ -39,16 +40,19 @@ func NewCmdShellAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *co
3940
}
4041
return nil
4142
},
42-
GroupID: "alias",
43-
Annotations: map[string]string{
44-
"skipAuthCheck": "true",
45-
},
43+
GroupID: "alias",
4644
DisableFlagParsing: true,
4745
}
46+
cmdutil.DisableAuthCheck(cmd)
47+
// Aliases are user-defined names and must not be reported as telemetry
48+
// dimensions, since the name itself may be sensitive (e.g. project or
49+
// organization names).
50+
cmdutil.DisableTelemetry(cmd)
51+
return cmd
4852
}
4953

5054
func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.Command {
51-
return &cobra.Command{
55+
cmd := &cobra.Command{
5256
Use: aliasName,
5357
Short: fmt.Sprintf("Alias for %q", text.Truncate(80, aliasValue)),
5458
RunE: func(c *cobra.Command, args []string) error {
@@ -60,12 +64,15 @@ func NewCmdAlias(io *iostreams.IOStreams, aliasName, aliasValue string) *cobra.C
6064
root.SetArgs(expandedArgs)
6165
return root.Execute()
6266
},
63-
GroupID: "alias",
64-
Annotations: map[string]string{
65-
"skipAuthCheck": "true",
66-
},
67+
GroupID: "alias",
6768
DisableFlagParsing: true,
6869
}
70+
cmdutil.DisableAuthCheck(cmd)
71+
// Aliases are user-defined names and must not be reported as telemetry
72+
// dimensions, since the name itself may be sensitive (e.g. project or
73+
// organization names).
74+
cmdutil.DisableTelemetry(cmd)
75+
return cmd
6976
}
7077

7178
// ExpandAlias processes argv to see if it should be rewritten according to a user's aliases.

0 commit comments

Comments
 (0)