Skip to content

Commit 0ea67ce

Browse files
committed
🐛 detect dangerous patterns in toJSON() in dangerous workflows
Signed-off-by: Adam Korczynski <[email protected]>
1 parent c29a04d commit 0ea67ce

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

checks/raw/dangerous_workflow.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@ func containsUntrustedContextPattern(variable string) bool {
5252
if strings.Contains(variable, "github.head_ref") {
5353
return true
5454
}
55-
return strings.Contains(variable, "github.event.") && untrustedContextPattern.MatchString(variable)
55+
return strings.Contains(variable, "github.event.") &&
56+
(untrustedContextPattern.MatchString(variable) ||
57+
untrustedContextPattern.MatchString(fmt.Sprintf("toJSON(%s)", variable)))
5658
}
5759

5860
type triggerName string

checks/raw/dangerous_workflow_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ package raw
1717
import (
1818
"context"
1919
"errors"
20+
"fmt"
2021
"io"
2122
"os"
2223
"testing"
@@ -83,6 +84,9 @@ func TestUntrustedContextVariables(t *testing.T) {
8384
if r := containsUntrustedContextPattern(tt.variable); !r == tt.expected {
8485
t.Fail()
8586
}
87+
if r := containsUntrustedContextPattern(fmt.Sprintf("toJSON(%s)", tt.variable)); !r == tt.expected {
88+
t.Fail()
89+
}
8690
})
8791
}
8892
}

0 commit comments

Comments
 (0)