MCPcopy Create free account
hub / github.com/github/gh-aw / TestSecurityTokenLeakage

Function TestSecurityTokenLeakage

pkg/workflow/security_regression_test.go:423–465  ·  view source on GitHub ↗

TestSecurityTokenLeakage validates that tokens cannot be leaked through various expression paths.

(t *testing.T)

Source from the content-addressed store, hash-verified

421// TestSecurityTokenLeakage validates that tokens cannot be leaked through
422// various expression paths.
423func TestSecurityTokenLeakage(t *testing.T) {
424 tests := []struct {
425 name string
426 content string
427 shouldBlock bool
428 description string
429 }{
430 {
431 name: "token_in_allowed_expression",
432 content: "${{ github.workflow }}/${{ secrets.TOKEN }}",
433 shouldBlock: true,
434 description: "Token in combined expression should be blocked",
435 },
436 {
437 name: "token_with_function_wrapper",
438 content: "${{ toJson(secrets.TOKEN) }}",
439 shouldBlock: true,
440 description: "Token wrapped in function should be blocked",
441 },
442 {
443 name: "token_in_conditional",
444 content: "${{ secrets.TOKEN == '' && 'empty' || 'has-value' }}",
445 shouldBlock: true,
446 description: "Token in conditional should be blocked",
447 },
448 {
449 name: "token_with_string_concat",
450 content: "${{ 'prefix-' + secrets.TOKEN + '-suffix' }}",
451 shouldBlock: true,
452 description: "Token with string concatenation should be blocked",
453 },
454 }
455
456 for _, tt := range tests {
457 t.Run(tt.name, func(t *testing.T) {
458 err := validateExpressionSafety(tt.content)
459
460 if tt.shouldBlock && err == nil {
461 t.Errorf("Security violation: %s - %s", tt.name, tt.description)
462 }
463 })
464 }
465}
466
467// =============================================================================
468// Safe Output System Tests

Callers

nothing calls this directly

Calls 3

validateExpressionSafetyFunction · 0.85
RunMethod · 0.45
ErrorfMethod · 0.45

Tested by

no test coverage detected