Skip to content

Commit 6010321

Browse files
authored
Fix step numbers and adjust workflows to match
1 parent c08ea91 commit 6010321

File tree

7 files changed

+133
-133
lines changed

7 files changed

+133
-133
lines changed

.github/steps/1.1-step.md

Lines changed: 0 additions & 45 deletions
This file was deleted.

.github/steps/2-step.md

Lines changed: 24 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,45 @@
1-
## Step 2: Review and Triage CodeQL Alerts
1+
## Step 2: Prevent Vulnerabilities in a Pull Request
22

3-
With our pull request changes now reviewed by CodeQL, let's take a moment to learn about managing alerts.
3+
In this step, we will introduce a vulnerability into the `routes.py` file to trigger an alert.
44

5-
GitHub provides a dedicated **Security** tab for securely managing all security related issues. CodeQL saves alerts using the same standard as many other analysis tools with the results showing up under the **Code scanning** area.
5+
### ⌨️ Activity: Recreate a vulnerability
66

7-
<img width="500" alt="image" src="https://github.com/user-attachments/assets/cf4fc6ec-e40e-4df6-8984-b6ec35341737" />
7+
1. In the top navigation, select the **Code** tab.
88

9-
### What information do alerts provide?
9+
1. Navigate to the `server` folder and select the `routes.py` file.
1010

11-
The main area of an alert provides the resolution status, affected branch, code location, and classification information like severity and [CVE identification number](https://docs.github.com/en/code-security/security-advisories/working-with-repository-security-advisories/about-repository-security-advisories#cve-identification-numbers).
11+
1. In the top right of the preview, click the **Edit** button.
1212

13+
<img width="400" alt="edit button" src="https://github.com/user-attachments/assets/19462cc5-a360-4dae-a97b-ecfd571aa403"/>
1314

14-
<img width="500" alt="additional information" src="https://github.com/user-attachments/assets/9a5aaf3f-e063-4d07-8cdd-6272eec8a411"/>
15+
1. Navigate to about **line 16** and modify it to the below.
1516

16-
<!-- > 💡 Tip: Clicking the **Show paths** link will provide additional insights about the alert's data flow from user input (source), through the application, and when it is acted on (sink). -->
17+
```py
18+
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
19+
```
1720

18-
### What is 'CWE'
21+
1. Above the editor in the top-right, click the **Commit changes...** button. Select the radio button next to **Create a new branch**. **DO NOT commit it to main branch.**
1922

20-
Many of the patterns CodeQL scans for come from existing databases of vulnerabilities.
23+
1. Click **Propose changes** option and click **Create pull request**.
2124

22-
The Common Weakness Enumeration (CWE) is a category system for hardware and software weaknesses and vulnerabilities. Think of it as a way to describe and categorize security issues in an application's source code. For more information on CWEs, see the Wikipedia article [Common Weakness Enumeration](https://en.wikipedia.org/wiki/Common_Weakness_Enumeration).
25+
### ⌨️ Activity: Review pull request
2326

24-
### ⌨️ Activity: View the status of a CodeQL scan
27+
1. If needed, navigate to the newly created pull requests from the previous activity.
2528

26-
1. In the top navigation, select the **Actions** tab.
29+
1. Scroll to the bottom of the pull request. Search for a check named `CodeQL`. This is the analysis job scanning the proposed code changes in the pull request.
2730

28-
1. If needed, wait a moment for the CodeQL run to finish (about 4 minutes).
31+
<img width="500" alt="pr panel" src="https://github.com/user-attachments/assets/1c29ee0f-cc1d-4568-9e71-338d45ad1d54"/>
2932

30-
1. Click on the **CodeQL Setup** workflow run entry to open a page showing more details.
33+
1. If the job is still running, wait a few minutes for it to complete.
3134

32-
<img width="500" alt="codeql setup" src="https://github.com/user-attachments/assets/016a729e-3b41-466c-8edf-3d4b41a86b7d"/>
35+
1. Search the comments to find a report from the analysis.
3336

34-
> 💡 Tip: The workflow run contains additional CodeQL information such as the run duration, logs, and analysis artifacts.
37+
- Notice that the results found a SQL injection vulnerability. It is also suggesting a fix.
38+
- Don't worry about responding or resolving this problem (yet).
3539

36-
### ⌨️ Activity: Review an Alert
40+
<img width="500" alt="image" src="https://github.com/user-attachments/assets/677cc104-9116-44a9-8061-091e8126442a">
3741

38-
1. In the top navigation, select the **Security** tab.
42+
1. With the pull request started, Mona will check your progress and share the next steps.
3943

40-
1. In the left navigation, find the **Vulnerability alerts** area and select the **Code scanning** option.
41-
42-
1. (Optional) Use the filters and search bar to explore the open and closed security alerts, including from the CodeQL scan.
43-
44-
1. Click on an alert.
45-
46-
1. Notice the description, related vulnerability information and a recommended solution.
47-
48-
<img width="500" alt="recommendations" src="https://github.com/user-attachments/assets/a5653b45-b66f-4e5b-8e03-a7b8cd3b91b4"/>
49-
50-
1. (Optional) Click the **View source** link to view the CodeQL query that detected the alert.
51-
52-
1. (Optional) Click the **Show more** link to view the full recommendation.
53-
54-
1. Inspect the audit trail to see a secure history of the alert, including open/close information.
55-
56-
<img width="500" alt="audit trail" src="https://github.com/user-attachments/assets/25ec5256-20c7-4e9d-8160-ff40f3763872"/>
57-
58-
### ⌨️ Activity: Dismiss and Reopen an Alert
59-
60-
1. In the top right, click **Dismiss alert** dropdown.
61-
62-
1. Select any reason and add a short explanation then click the **Dismiss alert** button.
63-
64-
- The alert state will change to `Dismissed`.
65-
- An entry is added to the audit trail, which can't be removed or edited.
66-
67-
1. Reopen the alert.
68-
69-
- The alert state will change to `Open`.
70-
- An entry is added to the audit trail, which can't be removed or edited.
7144

45+
<!-- If you would like to learn more about pull request integrations for code scanning, see "[Triage code scanning alerts in pull requests](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/triaging-code-scanning-alerts-in-pull-requests)." -->

.github/steps/3-step.md

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,71 @@
1-
## Step 3: Fix Security Vulnerabilities
1+
## Step 3: Review and Triage CodeQL Alerts
22

3-
Let's fix the existing security vulnerabilities already identified by CodeQL. Remember, at this point, we have introduced CodeQL into our repository and it has scanned the existing code. The vulnerabilities it found are real-world issues, and they need to be fixed!
3+
With our pull request changes now reviewed by CodeQL, let's take a moment to learn about managing alerts.
44

5-
Now that both of these alerts are open, let's fix them. If you look at the alerts, they both call out one specific file containing the issues: `server/routes.py`. The issue is in crafting the SQL query for the database. These queries are vulnerable to SQL injection attacks. We should rewrite these SQL statements more securely.
5+
GitHub provides a dedicated **Security** tab for securely managing all security related issues. CodeQL saves alerts using the same standard as many other analysis tools with the results showing up under the **Code scanning** area.
66

7-
If you expand the **More info** section at the bottom of the alert, there are very clear suggestions to fix this query. We're going to implement those suggestions in the next activity.
7+
<img width="500" alt="image" src="https://github.com/user-attachments/assets/cf4fc6ec-e40e-4df6-8984-b6ec35341737" />
88

9-
### ⌨️ Activity: Resolve an open alert
9+
### What information do alerts provide?
1010

11-
1. In the top navigation, select the **Security** tab.
11+
The main area of an alert provides the resolution status, affected branch, code location, and classification information like severity and [CVE identification number](https://docs.github.com/en/code-security/security-advisories/working-with-repository-security-advisories/about-repository-security-advisories#cve-identification-numbers).
12+
13+
14+
<img width="500" alt="additional information" src="https://github.com/user-attachments/assets/9a5aaf3f-e063-4d07-8cdd-6272eec8a411"/>
15+
16+
<!-- > 💡 Tip: Clicking the **Show paths** link will provide additional insights about the alert's data flow from user input (source), through the application, and when it is acted on (sink). -->
17+
18+
### What is 'CWE'
1219

13-
1. In the left navigation, find the **Vulnerability alerts** area and select the **Code scanning** option. You should see two open alerts.
20+
Many of the patterns CodeQL scans for come from existing databases of vulnerabilities.
1421

15-
> 🪧 Note: If any of the alerts are `Closed`, go to the alert's page and choose **Reopen alert**.
22+
The Common Weakness Enumeration (CWE) is a category system for hardware and software weaknesses and vulnerabilities. Think of it as a way to describe and categorize security issues in an application's source code. For more information on CWEs, see the Wikipedia article [Common Weakness Enumeration](https://en.wikipedia.org/wiki/Common_Weakness_Enumeration).
1623

17-
1. Review the 2 open alerts and review the recommendations to decide changes to make.
24+
### ⌨️ Activity: View the status of a CodeQL scan
1825

19-
1. In the top navigation, select the **Code** tab.
26+
1. In the top navigation, select the **Actions** tab.
2027

21-
1. Navigate to the `server` folder and select the `routes.py` file.
28+
1. If needed, wait a moment for the CodeQL run to finish (about 4 minutes).
2229

23-
1. In the top right of the preview, click the **Edit** button.
30+
1. Click on the **CodeQL Setup** workflow run entry to open a page showing more details.
31+
32+
<img width="500" alt="codeql setup" src="https://github.com/user-attachments/assets/016a729e-3b41-466c-8edf-3d4b41a86b7d"/>
33+
34+
> 💡 Tip: The workflow run contains additional CodeQL information such as the run duration, logs, and analysis artifacts.
35+
36+
### ⌨️ Activity: Review an Alert
37+
38+
1. In the top navigation, select the **Security** tab.
2439

25-
<img width="400" alt="edit button" src="https://github.com/user-attachments/assets/19462cc5-a360-4dae-a97b-ecfd571aa403"/>
40+
1. In the left navigation, find the **Vulnerability alerts** area and select the **Code scanning** option.
2641

27-
1. Navigate to about **line 16** and modify it to the below.
42+
1. (Optional) Use the filters and search bar to explore the open and closed security alerts, including from the CodeQL scan.
2843

29-
```py
30-
"SELECT * FROM books WHERE name LIKE %s", name
31-
```
44+
1. Click on an alert.
3245

33-
1. Above the editor in the top-right, click the **Commit changes...** button. Use the defaults options to commit the changes to `main`.
46+
1. Notice the description, related vulnerability information and a recommended solution.
3447

35-
- CodeQL will now initiate a another scan.
48+
<img width="500" alt="recommendations" src="https://github.com/user-attachments/assets/a5653b45-b66f-4e5b-8e03-a7b8cd3b91b4"/>
3649

37-
1. In the top navigation, navigate to the **Actions** tab. Wait for the **CodeQL** workflow to finish.
50+
1. (Optional) Click the **View source** link to view the CodeQL query that detected the alert.
3851

39-
1. Return the the open alerts page and review the open alerts.
52+
1. (Optional) Click the **Show more** link to view the full recommendation.
4053

41-
- There should be zero open alerts and two closed alerts. Nice work! 🎉
42-
- Feel free to review the closed alerts, especially the audit trail.
54+
1. Inspect the audit trail to see a secure history of the alert, including open/close information.
4355

44-
<!-- 1. With the CodeQL job finished, Mona will check your progress and share the next steps. -->
56+
<img width="500" alt="audit trail" src="https://github.com/user-attachments/assets/25ec5256-20c7-4e9d-8160-ff40f3763872"/>
4557

46-
1. With the pull request started, Mona will check your progress and share a final review. Nice work! You are done! 🥳
58+
### ⌨️ Activity: Dismiss and Reopen an Alert
4759

60+
1. In the top right, click **Dismiss alert** dropdown.
4861

62+
1. Select any reason and add a short explanation then click the **Dismiss alert** button.
4963

64+
- The alert state will change to `Dismissed`.
65+
- An entry is added to the audit trail, which can't be removed or edited.
5066

51-
<!-- 1. Navigate back to **Security** tab and **Code scanning alerts** area.
67+
1. Reopen the alert.
5268

53-
1. Click the **1 Closed** text to switch to a view showing closed alerts.
69+
- The alert state will change to `Open`.
70+
- An entry is added to the audit trail, which can't be removed or edited.
5471

55-
<img width="500" alt="one closed alert" src="https://github.com/user-attachments/assets/b10005b6-9ef8-4d46-a160-4c9849d2c898"/> -->

.github/steps/4-step.md

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
## Step 3: Fix Security Vulnerabilities
2+
3+
Let's fix the existing security vulnerabilities already identified by CodeQL. Remember, at this point, we have introduced CodeQL into our repository and it has scanned the existing code. The vulnerabilities it found are real-world issues, and they need to be fixed!
4+
5+
Now that both of these alerts are open, let's fix them. If you look at the alerts, they both call out one specific file containing the issues: `server/routes.py`. The issue is in crafting the SQL query for the database. These queries are vulnerable to SQL injection attacks. We should rewrite these SQL statements more securely.
6+
7+
If you expand the **More info** section at the bottom of the alert, there are very clear suggestions to fix this query. We're going to implement those suggestions in the next activity.
8+
9+
### ⌨️ Activity: Resolve an open alert
10+
11+
1. In the top navigation, select the **Security** tab.
12+
13+
1. In the left navigation, find the **Vulnerability alerts** area and select the **Code scanning** option. You should see two open alerts.
14+
15+
> 🪧 Note: If any of the alerts are `Closed`, go to the alert's page and choose **Reopen alert**.
16+
17+
1. Review the 2 open alerts and review the recommendations to decide changes to make.
18+
19+
1. In the top navigation, select the **Code** tab.
20+
21+
1. Navigate to the `server` folder and select the `routes.py` file.
22+
23+
1. In the top right of the preview, click the **Edit** button.
24+
25+
<img width="400" alt="edit button" src="https://github.com/user-attachments/assets/19462cc5-a360-4dae-a97b-ecfd571aa403"/>
26+
27+
1. Navigate to about **line 16** and modify it to the below.
28+
29+
```py
30+
"SELECT * FROM books WHERE name LIKE %s", name
31+
```
32+
33+
1. Above the editor in the top-right, click the **Commit changes...** button. Use the defaults options to commit the changes to `main`.
34+
35+
- CodeQL will now initiate a another scan.
36+
37+
1. In the top navigation, navigate to the **Actions** tab. Wait for the **CodeQL** workflow to finish.
38+
39+
1. Return the the open alerts page and review the open alerts.
40+
41+
- There should be zero open alerts and two closed alerts. Nice work! 🎉
42+
- Feel free to review the closed alerts, especially the audit trail.
43+
44+
<!-- 1. With the CodeQL job finished, Mona will check your progress and share the next steps. -->
45+
46+
1. With the pull request started, Mona will check your progress and share a final review. Nice work! You are done! 🥳
47+
48+
49+
50+
51+
<!-- 1. Navigate back to **Security** tab and **Code scanning alerts** area.
52+
53+
1. Click the **1 Closed** text to switch to a view showing closed alerts.
54+
55+
<img width="500" alt="one closed alert" src="https://github.com/user-attachments/assets/b10005b6-9ef8-4d46-a160-4c9849d2c898"/> -->

.github/workflows/2-step.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
name: Step 2
22

33
on:
4-
issues:
5-
types: [opened]
4+
pull_request:
5+
types: opened
66

77
permissions:
88
contents: read

.github/workflows/3-step.yml

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,16 @@
11
name: Step 3
22

33
on:
4-
workflow_run:
5-
workflows: [CodeQL]
6-
types:
7-
- completed
4+
issues:
5+
types: [opened]
86

97
permissions:
108
contents: read
119
actions: write
1210
issues: write
1311

1412
env:
15-
STEP_4_FILE: ".github/steps/4-step.md"
13+
STEP_3_FILE: ".github/steps/4-step.md"
1614

1715
jobs:
1816
find_exercise:
@@ -40,7 +38,7 @@ jobs:
4038
- name: Create comment - add step content
4139
run: |
4240
gh issue comment "$ISSUE_URL" \
43-
--body-file "$STEP_4_FILE"
41+
--body-file "$STEP_3_FILE"
4442
env:
4543
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
4644

.github/workflows/1.1-step.yml renamed to .github/workflows/4-step.yml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
name: Step 4
22

33
on:
4-
pull_request:
5-
types: opened
4+
workflow_run:
5+
workflows: [CodeQL]
6+
types:
7+
- completed
68

79
permissions:
810
contents: write

0 commit comments

Comments
 (0)