In this section we are going to create an Actions workflow to scan existing workflows for any script injection weaknesses.
-
In your repository,
clickon theActionstab. -
This will take you to the
Actionspage and now click on thenew workflowbutton to create a workflow. -
This will put you in the
starter workflowspage. EnterCodeQL Analysisin theSearchfield and search. You should see one result. Click onConfigurebutton on the resulting workflow template. This will take you to the edit window of the the workflow file.
Now we can edit this workflow to customize it to scan the workflows.
- Give a name to the file (it could be
actions-workflow-codeql.yml) and also give a name to the workflow (this could beActions WorkFlow CodeQL)
At this point, you are close to having a CodeQL Workflow that can scan your repository for vulnerabitlities.
- Edit the workflow file as follows:
Look over the first few lines of the workflow. You'd notice that the workflow gets triggered by push to the default branch and also by several other events.
Edit the workflow's trigger section as follows:
- Keep the
pushtrigger - Remove other triggers that were pre-configured in the workflow.
- In the
strategy:matrix:languagesection, type'javascript'as the value for lanuage array. - Remove the
Autobuildstep entirely.
NOTE
Autobuild is only necessary for compiled languages, since we are using thejavascriptextractor, this is not really necessary.
-
Commit this file into the
defaultbranch. When the file is committed, it will generate apushevent and theActions WorkFlow CodeQLworkflow should be triggered. Nowclickon theActionstab and you should see the workflow being scheduled to run based on thepushevent. -
Monitor the workflow run and ensure that it finishes successfully.
-
Now, click on the
Securitytab. And you should see theSecurity Overviewpage with two alerts created underCode Scanning.
- Click on
Code Scanningin the side menubar of theSecurity Overviewpage. And click on the first alert -Expression Injection in Actions
You'll see the details of the alert including the file where this weakness exists.
- Click on
Show moreto see more details including how to resolve this alert.
The Exercise 5 and Exercise 6 will show how to modify the problematic workflow file to resolve this alert. At the end of those exercises, once the file is committed, it will trigger the Actions Workflow CodeQL and the alert should be resolved if the recommend fix was implemented.
NOTE
IfCodeQl Analysissearch is not returning any results, code scanning might not be enabled for the repo, please contact your organization admin or repository admin to enable it. If you want to learn more about setting up code scanning, you can follow this tutorial.
NOTE
For your convenience a sample of this workflow is available in/solutionsdirectory.