From 01e61de82692cb33c57380c9ce45447e4cbd1a96 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 04:12:36 +0000 Subject: [PATCH 1/5] Initial plan From d343eaad3c1e0a0f71498cc269e146b523907d31 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 04:23:08 +0000 Subject: [PATCH 2/5] Improve secret sanitization: fix inefficiency, reduce false positives, add GitHub Actions expression support Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/cli/compile_config.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/pkg/cli/compile_config.go b/pkg/cli/compile_config.go index 3b07dfff5ff..58dabf914a0 100644 --- a/pkg/cli/compile_config.go +++ b/pkg/cli/compile_config.go @@ -59,8 +59,10 @@ var sensitivePatterns = []*regexp.Regexp{ regexp.MustCompile(`(?i)(secret|password|token|key|credential|api[_-]?key)s?\s*[:=]\s*['"]?[^\s'"]+['"]?`), // Match GitHub token patterns regexp.MustCompile(`gh[ps]_[a-zA-Z0-9]{36,}`), - // Match potential API keys - regexp.MustCompile(`['\"][a-zA-Z0-9_\-]{32,}['\"]`), + // Match GitHub Actions secret expressions + regexp.MustCompile(`\$\{\{\s*secrets\.[^}]+\}\}`), + // Match quoted strings of 40+ chars preceded by secret-like keywords + regexp.MustCompile(`(?i)(secret|password|token|key|credential|api[_-]?key)s?\s*[:=]\s*['\"][a-zA-Z0-9_\-]{40,}['\"]`), } // sanitizeErrorMessage removes potentially sensitive information from error messages @@ -72,9 +74,9 @@ func sanitizeErrorMessage(msg string) string { sanitized = pattern.ReplaceAllStringFunc(sanitized, func(match string) string { // Try to preserve the structure of the message while redacting the value if strings.Contains(match, ":") || strings.Contains(match, "=") { - parts := regexp.MustCompile(`[:=]`).Split(match, 2) - if len(parts) == 2 { - return parts[0] + ": [REDACTED]" + idx := strings.IndexAny(match, ":=") + if idx != -1 && idx+1 < len(match) { + return match[:idx+1] + " [REDACTED]" } } return "[REDACTED]" From 2ed9c54d74c41edadda6cbd395d7660b9131e7c1 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 04:29:09 +0000 Subject: [PATCH 3/5] Refine regex patterns: make secret name matching more specific and improve character class clarity Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/cli/compile_config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/cli/compile_config.go b/pkg/cli/compile_config.go index 58dabf914a0..10b670cc9b8 100644 --- a/pkg/cli/compile_config.go +++ b/pkg/cli/compile_config.go @@ -60,9 +60,9 @@ var sensitivePatterns = []*regexp.Regexp{ // Match GitHub token patterns regexp.MustCompile(`gh[ps]_[a-zA-Z0-9]{36,}`), // Match GitHub Actions secret expressions - regexp.MustCompile(`\$\{\{\s*secrets\.[^}]+\}\}`), + regexp.MustCompile(`\$\{\{\s*secrets\.[a-zA-Z0-9_-]+\}\}`), // Match quoted strings of 40+ chars preceded by secret-like keywords - regexp.MustCompile(`(?i)(secret|password|token|key|credential|api[_-]?key)s?\s*[:=]\s*['\"][a-zA-Z0-9_\-]{40,}['\"]`), + regexp.MustCompile(`(?i)(secret|password|token|key|credential|api[_-]?key)s?\s*[:=]\s*['"][-a-zA-Z0-9_]{40,}['\"]`), } // sanitizeErrorMessage removes potentially sensitive information from error messages From d8a69838d5eeea2f72617c40f966e3961e9c5463 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 05:01:14 +0000 Subject: [PATCH 4/5] Add validation to ensure secret values are GitHub Actions expressions Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- pkg/workflow/compiler_jobs.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/workflow/compiler_jobs.go b/pkg/workflow/compiler_jobs.go index 7e634f83e09..277fea6e03e 100644 --- a/pkg/workflow/compiler_jobs.go +++ b/pkg/workflow/compiler_jobs.go @@ -4,6 +4,7 @@ import ( "fmt" "os" "path/filepath" + "regexp" "strings" "github.com/githubnext/gh-aw/pkg/constants" @@ -14,6 +15,9 @@ import ( var compilerJobsLog = logger.New("workflow:compiler_jobs") +// secretExpressionPattern matches GitHub Actions secret expressions like ${{ secrets.MY_TOKEN }} +var secretExpressionPattern = regexp.MustCompile(`^\$\{\{\s*secrets\.[a-zA-Z0-9_-]+(\s*\|\|[^}]*)?\s*\}\}$`) + // This file contains job building functions extracted from compiler.go // These functions are responsible for constructing the various jobs that make up // a compiled agentic workflow, including activation, main, safe outputs, and custom jobs. @@ -1393,6 +1397,10 @@ func (c *Compiler) buildCustomJobs(data *WorkflowData, activationJobCreated bool job.Secrets = make(map[string]string) for key, val := range secretsMap { if valStr, ok := val.(string); ok { + // Validate that secret values are GitHub Actions expressions + if !secretExpressionPattern.MatchString(valStr) { + return fmt.Errorf("job '%s': secret '%s' must be a GitHub Actions expression like ${{ secrets.MY_SECRET }}, got: %s", jobName, key, valStr) + } job.Secrets[key] = valStr } } From 47ca2ab1861a044c6af6a8628c8ebc873c5286e3 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Mon, 15 Dec 2025 05:15:55 +0000 Subject: [PATCH 5/5] Add security test for secret validation and include in CI Co-authored-by: pelikhan <4175913+pelikhan@users.noreply.github.com> --- .github/workflows/ci.yml | 2 +- pkg/workflow/compiler_jobs_test.go | 88 ++++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 99aa2deb133..1dbbede251f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -95,7 +95,7 @@ jobs: pattern: "TestMCP|TestTool|TestSkill|TestPlaywright|TestFirewall" - name: "Workflow Validation" packages: "./pkg/workflow" - pattern: "TestValidat|TestLock|TestError|TestWarning" + pattern: "TestValidat|TestLock|TestError|TestWarning|TestSecurity" - name: "Workflow Safe Outputs" packages: "./pkg/workflow" pattern: "SafeOutputs|CreatePullRequest|OutputLabel|HasSafeOutputs" diff --git a/pkg/workflow/compiler_jobs_test.go b/pkg/workflow/compiler_jobs_test.go index 21e91bdf478..0da2c664471 100644 --- a/pkg/workflow/compiler_jobs_test.go +++ b/pkg/workflow/compiler_jobs_test.go @@ -534,3 +534,91 @@ Test content` t.Error("Expected 'result' output") } } + +// TestSecuritySecretValidation tests that secret values must be GitHub Actions expressions +// This is a security test to prevent plain text secrets from being used +func TestSecuritySecretValidation(t *testing.T) { + tests := []struct { + name string + secretValue string + shouldError bool + errorMsg string + }{ + { + name: "valid secret expression", + secretValue: "${{ secrets.MY_TOKEN }}", + shouldError: false, + }, + { + name: "valid secret with default", + secretValue: "${{ secrets.DD_SITE || 'datadoghq.com' }}", + shouldError: false, + }, + { + name: "valid secret with spaces", + secretValue: "${{ secrets.API_KEY }}", + shouldError: false, + }, + { + name: "plain text secret - should fail", + secretValue: "my-plain-text-secret", + shouldError: true, + errorMsg: "must be a GitHub Actions expression", + }, + { + name: "wrong context - should fail", + secretValue: "${{ github.token }}", + shouldError: true, + errorMsg: "must be a GitHub Actions expression", + }, + { + name: "vars instead of secrets - should fail", + secretValue: "${{ vars.MY_VAR }}", + shouldError: true, + errorMsg: "must be a GitHub Actions expression", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + tmpDir := testutil.TempDir(t, "secret-validation-test") + + frontmatter := `--- +on: push +permissions: + contents: read +engine: copilot +strict: false +jobs: + test-job: + uses: owner/repo/.github/workflows/reusable.yml@main + secrets: + token: ` + tt.secretValue + ` +--- + +# Test Workflow + +Test content` + + testFile := filepath.Join(tmpDir, "test.md") + if err := os.WriteFile(testFile, []byte(frontmatter), 0644); err != nil { + t.Fatal(err) + } + + compiler := NewCompiler(false, "", "test") + err := compiler.CompileWorkflow(testFile) + + if tt.shouldError { + if err == nil { + t.Errorf("Expected error for secret value %q, but got none", tt.secretValue) + } else if !strings.Contains(err.Error(), tt.errorMsg) { + t.Errorf("Expected error message to contain %q, got: %v", tt.errorMsg, err) + } + } else { + if err != nil { + t.Errorf("Expected no error for secret value %q, but got: %v", tt.secretValue, err) + } + } + }) + } +}