In this section we are going to create an Actions workflow to scan existing workflows for any script injection
weaknesses.
-
In your repository,
click
on theActions
tab. -
This will take you to the
Actions
page and now click on thenew workflow
button to create a workflow. -
This will put you in the
starter workflows
page. EnterCodeQL Analysis
in theSearch
field and search. You should see one result. Click onConfigure
button 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
push
trigger - Remove other triggers that were pre-configured in the workflow.
- In the
strategy
:matrix
:language
section, type'javascript'
as the value for lanuage array. - Remove the
Autobuild
step entirely.
NOTE
Autobuild is only necessary for compiled languages, since we are using thejavascript
extractor, this is not really necessary.
-
Commit this file into the
default
branch. When the file is committed, it will generate apush
event and theActions WorkFlow CodeQL
workflow should be triggered. Nowclick
on theActions
tab and you should see the workflow being scheduled to run based on thepush
event. -
Monitor the workflow run and ensure that it finishes successfully.
-
Now, click on the
Security
tab. And you should see theSecurity Overview
page with two alerts created underCode Scanning
.
- Click on
Code Scanning
in the side menubar of theSecurity Overview
page. 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 more
to 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 Analysis
search 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/solutions
directory.