Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 17 additions & 9 deletions pkg/cli/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import (
"github.com/github/gh-aw/pkg/console"
"github.com/github/gh-aw/pkg/constants"
"github.com/github/gh-aw/pkg/logger"
"github.com/github/gh-aw/pkg/parser"
"github.com/github/gh-aw/pkg/workflow"
)

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

// Try alternative environment variable names
// NOTE: We intentionally do NOT use GetGitHubToken() fallback for COPILOT_GITHUB_TOKEN here.
// The init command should only detect explicitly set environment variables, not scrape
// the user's gh auth token. Using gh auth token for secrets would be a security risk
// as users may not realize their personal token is being uploaded to the repository.
// The trial command handles this differently with explicit warnings.
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The comment says “The trial command handles this differently with explicit warnings,” but the trial flow appears to set COPILOT_GITHUB_TOKEN via parser.GetGitHubToken()/prompts without an explicit warning about uploading a personal gh auth token. Please either add the referenced warning in the trial path or reword/remove this sentence so the security rationale comment stays accurate.

Suggested change
// The trial command handles this differently with explicit warnings.
// If other flows use a gh auth token as a fallback, they must include explicit warnings

Copilot uses AI. Check for mistakes.
if secretValue == "" {
switch spec.Name {
case "ANTHROPIC_API_KEY":
secretValue = os.Getenv("ANTHROPIC_KEY")
case "OPENAI_API_KEY":
secretValue = os.Getenv("OPENAI_KEY")
case "COPILOT_GITHUB_TOKEN":
// Use the proper GitHub token helper
secretValue, _ = parser.GetGitHubToken()
// Only check explicit environment variable, do NOT use gh auth token fallback
// This prevents accidentally uploading user's personal token to the repository
secretValue = os.Getenv("COPILOT_GITHUB_TOKEN")
Comment on lines 216 to +219
Copy link

Copilot AI Feb 8, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This COPILOT_GITHUB_TOKEN branch is redundant: secretValue was already initialized with os.Getenv(spec.Name), and spec.Name is "COPILOT_GITHUB_TOKEN". Consider removing this case (or using it for true alternative env var names) to avoid implying extra lookup logic that doesn’t change behavior.

This issue also appears on line 349 of the same file.

See below for a potential fix:


Copilot uses AI. Check for mistakes.
}
}

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

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

// Get secret value from environment
// NOTE: We intentionally do NOT use GetGitHubToken() fallback for COPILOT_GITHUB_TOKEN here.
// The init command should only use explicitly set environment variables to avoid
// accidentally uploading the user's personal gh auth token to the repository.
secretValue := os.Getenv(secretName)
if secretValue == "" {
// Try alternative names
// Try alternative names (but NOT gh auth token fallback for security)
switch secretName {
case "ANTHROPIC_API_KEY":
secretValue = os.Getenv("ANTHROPIC_KEY")
case "OPENAI_API_KEY":
secretValue = os.Getenv("OPENAI_KEY")
case "COPILOT_GITHUB_TOKEN":
secretValue, err = parser.GetGitHubToken()
if err != nil {
return fmt.Errorf("failed to get GitHub token: %w", err)
}
// Only check explicit environment variable, do NOT use gh auth token fallback
// This prevents accidentally uploading user's personal token to the repository
secretValue = os.Getenv("COPILOT_GITHUB_TOKEN")
}
}

Expand Down
Loading