@@ -38,6 +38,7 @@ const errorMissingAction = "KnownIssue-4: Action %s is not in the knowledge base
3838const errorAlreadyHasPermissions = "KnownIssue-5: Permissions were not added to the job since it already had permissions defined"
3939const errorDockerAction = "KnownIssue-6: Action %s is a docker action which uses Github token. Docker actions that uses token are not supported"
4040const errorReusableWorkflow = "KnownIssue-7: Action %s is a reusable workflow. Reusable workflows are not supported as of now."
41+ const errorGithubTokenInJobEnv = "KnownIssue-8: Permissions were not added to the jobs since it has GITHUB_TOKEN in job level env variable"
4142const errorIncorrectYaml = "Unable to parse the YAML workflow file"
4243
4344// To avoid a typo while adding the permissions
@@ -78,6 +79,15 @@ func alreadyHasWorkflowPermissions(workflow metadata.Workflow) bool {
7879 return workflow .Permissions .IsSet
7980}
8081
82+ func githubTokenInJobLevelEnv (job metadata.Job ) bool {
83+ for _ , envValue := range job .Env {
84+ if strings .Contains (envValue , "secrets.GITHUB_TOKEN" ) || strings .Contains (envValue , "github.token" ) {
85+ return true
86+ }
87+ }
88+ return false
89+ }
90+
8191func AddWorkflowLevelPermissions (inputYaml string , addProjectComment bool ) (string , error ) {
8292 workflow := metadata.Workflow {}
8393
@@ -177,6 +187,12 @@ func AddJobLevelPermissions(inputYaml string) (*SecureWorkflowReponse, error) {
177187 continue
178188 }
179189
190+ if githubTokenInJobLevelEnv (job ) {
191+ fixWorkflowPermsReponse .HasErrors = true
192+ errors [jobName ] = append (errors [jobName ], errorGithubTokenInJobEnv )
193+ continue
194+ }
195+
180196 if metadata .IsCallingReusableWorkflow (job ) {
181197 fixWorkflowPermsReponse .HasErrors = true
182198 errors [jobName ] = append (errors [jobName ], fmt .Sprintf (errorReusableWorkflow , job .Uses ))
0 commit comments