Skip to content

Commit 6c3f14a

Browse files
authored
dont upload token on gh aw init (#14558)
1 parent 6ec467f commit 6c3f14a

1 file changed

Lines changed: 17 additions & 9 deletions

File tree

pkg/cli/init.go

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"github.com/github/gh-aw/pkg/console"
1212
"github.com/github/gh-aw/pkg/constants"
1313
"github.com/github/gh-aw/pkg/logger"
14-
"github.com/github/gh-aw/pkg/parser"
1514
"github.com/github/gh-aw/pkg/workflow"
1615
)
1716

@@ -203,15 +202,21 @@ func setupEngineSecrets(engine string, verbose bool) error {
203202
secretValue := os.Getenv(spec.Name)
204203

205204
// Try alternative environment variable names
205+
// NOTE: We intentionally do NOT use GetGitHubToken() fallback for COPILOT_GITHUB_TOKEN here.
206+
// The init command should only detect explicitly set environment variables, not scrape
207+
// the user's gh auth token. Using gh auth token for secrets would be a security risk
208+
// as users may not realize their personal token is being uploaded to the repository.
209+
// The trial command handles this differently with explicit warnings.
206210
if secretValue == "" {
207211
switch spec.Name {
208212
case "ANTHROPIC_API_KEY":
209213
secretValue = os.Getenv("ANTHROPIC_KEY")
210214
case "OPENAI_API_KEY":
211215
secretValue = os.Getenv("OPENAI_KEY")
212216
case "COPILOT_GITHUB_TOKEN":
213-
// Use the proper GitHub token helper
214-
secretValue, _ = parser.GetGitHubToken()
217+
// Only check explicit environment variable, do NOT use gh auth token fallback
218+
// This prevents accidentally uploading user's personal token to the repository
219+
secretValue = os.Getenv("COPILOT_GITHUB_TOKEN")
215220
}
216221
}
217222

@@ -231,12 +236,13 @@ func setupEngineSecrets(engine string, verbose bool) error {
231236
fmt.Fprintln(os.Stderr, "")
232237

233238
// Ask for confirmation before configuring secrets
239+
// SECURITY: Default to "No" to prevent accidental token uploads
234240
var confirmSetSecrets bool
235241
confirmForm := huh.NewForm(
236242
huh.NewGroup(
237243
huh.NewConfirm().
238244
Title("Would you like to configure these secrets as repository Actions secrets?").
239-
Description("This will use the gh CLI to set the secrets in your repository").
245+
Description("This will upload the API keys or tokens as secrets in your repository. Default: No").
240246
Affirmative("Yes, configure secrets").
241247
Negative("No, skip").
242248
Value(&confirmSetSecrets),
@@ -329,19 +335,21 @@ func attemptSetSecret(secretName, repoSlug string, verbose bool) error {
329335
}
330336

331337
// Get secret value from environment
338+
// NOTE: We intentionally do NOT use GetGitHubToken() fallback for COPILOT_GITHUB_TOKEN here.
339+
// The init command should only use explicitly set environment variables to avoid
340+
// accidentally uploading the user's personal gh auth token to the repository.
332341
secretValue := os.Getenv(secretName)
333342
if secretValue == "" {
334-
// Try alternative names
343+
// Try alternative names (but NOT gh auth token fallback for security)
335344
switch secretName {
336345
case "ANTHROPIC_API_KEY":
337346
secretValue = os.Getenv("ANTHROPIC_KEY")
338347
case "OPENAI_API_KEY":
339348
secretValue = os.Getenv("OPENAI_KEY")
340349
case "COPILOT_GITHUB_TOKEN":
341-
secretValue, err = parser.GetGitHubToken()
342-
if err != nil {
343-
return fmt.Errorf("failed to get GitHub token: %w", err)
344-
}
350+
// Only check explicit environment variable, do NOT use gh auth token fallback
351+
// This prevents accidentally uploading user's personal token to the repository
352+
secretValue = os.Getenv("COPILOT_GITHUB_TOKEN")
345353
}
346354
}
347355

0 commit comments

Comments
 (0)