Skip to content

Commit c08ea91

Browse files
authored
Reorder steps to introduce vulnerability then resolve it.
1 parent 79c8ba4 commit c08ea91

File tree

6 files changed

+92
-86
lines changed

6 files changed

+92
-86
lines changed

.github/steps/1.1-step.md

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Step 2.1: Prevent Vulnerabilities in a Pull Request
2+
3+
In this step, we will introduce a vulnerability into the `routes.py` file to trigger an alert.
4+
5+
### ⌨️ Activity: Recreate a vulnerability
6+
7+
1. In the top navigation, select the **Code** tab.
8+
9+
1. Navigate to the `server` folder and select the `routes.py` file.
10+
11+
1. In the top right of the preview, click the **Edit** button.
12+
13+
<img width="400" alt="edit button" src="https://github.com/user-attachments/assets/19462cc5-a360-4dae-a97b-ecfd571aa403"/>
14+
15+
1. Navigate to about **line 16** and modify it to the below.
16+
17+
```py
18+
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
19+
```
20+
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.**
22+
23+
1. Click **Propose changes** option and click **Create pull request**.
24+
25+
### ⌨️ Activity: Review pull request
26+
27+
1. If needed, navigate to the newly created pull requests from the previous activity.
28+
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.
30+
31+
<img width="500" alt="pr panel" src="https://github.com/user-attachments/assets/1c29ee0f-cc1d-4568-9e71-338d45ad1d54"/>
32+
33+
1. If the job is still running, wait a few minutes for it to complete.
34+
35+
1. Search the comments to find a report from the analysis.
36+
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).
39+
40+
<img width="500" alt="image" src="https://github.com/user-attachments/assets/677cc104-9116-44a9-8061-091e8126442a">
41+
42+
1. With the pull request started, Mona will check your progress and share the next steps.
43+
44+
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/2-step.md

Lines changed: 32 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,25 @@
11
## Step 2: Review and Triage CodeQL Alerts
22

3-
Now we will review the CodeQL scan results, triage an alert, and create a GitHub issue to track an alert.
3+
With our pull request changes now reviewed by CodeQL, let's take a moment to learn about managing alerts.
44

5-
### What is CWE
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-
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).
7+
<img width="500" alt="image" src="https://github.com/user-attachments/assets/cf4fc6ec-e40e-4df6-8984-b6ec35341737" />
8+
9+
### What information do alerts provide?
10+
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'
19+
20+
Many of the patterns CodeQL scans for come from existing databases of vulnerabilities.
21+
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).
823

924
### ⌨️ Activity: View the status of a CodeQL scan
1025

@@ -26,43 +41,31 @@ Common Weakness Enumeration (CWE) is a category system for hardware and software
2641

2742
1. (Optional) Use the filters and search bar to explore the open and closed security alerts, including from the CodeQL scan.
2843

29-
#### Alert status and location
30-
31-
The main area of the 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).
32-
33-
> 💡 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).
34-
35-
<img width="500" alt="alert status" src="https://github.com/user-attachments/assets/2fecc67d-52ef-44fc-ad89-1eb28ceb9437">
36-
37-
<img width="500" alt="location information" src="https://github.com/user-attachments/assets/1a450118-f200-436b-8433-04b7e5e4f1a8"/>
38-
39-
<img width="500" alt="additional information" src="https://github.com/user-attachments/assets/9a5aaf3f-e063-4d07-8cdd-6272eec8a411"/>
40-
41-
#### Explanation and Recommendation
44+
1. Click on an alert.
4245

43-
This alert is further described, justified, and a recommended solution is provided when possible.
46+
1. Notice the description, related vulnerability information and a recommended solution.
4447

45-
- Click the **View source** link to view the CodeQL query that detected the alert.
46-
- Click the **Show more** link to view the full recommendation.
48+
<img width="500" alt="recommendations" src="https://github.com/user-attachments/assets/a5653b45-b66f-4e5b-8e03-a7b8cd3b91b4"/>
4749

48-
<img width="500" alt="recommendations" src="https://github.com/user-attachments/assets/a5653b45-b66f-4e5b-8e03-a7b8cd3b91b4"/>
50+
1. (Optional) Click the **View source** link to view the CodeQL query that detected the alert.
4951

50-
#### Audit trail
52+
1. (Optional) Click the **Show more** link to view the full recommendation.
5153

52-
The audit trail provides a secure history of the alert for future reference, like who marked the vulnerability as closed/fixed.
54+
1. Inspect the audit trail to see a secure history of the alert, including open/close information.
5355

54-
<img width="500" alt="audit trail" src="https://github.com/user-attachments/assets/25ec5256-20c7-4e9d-8160-ff40f3763872"/>
56+
<img width="500" alt="audit trail" src="https://github.com/user-attachments/assets/25ec5256-20c7-4e9d-8160-ff40f3763872"/>
5557

56-
### ⌨️ Activity: Dismiss an Alert
58+
### ⌨️ Activity: Dismiss and Reopen an Alert
5759

58-
1. On the alert page, in the top right, click **Dismiss alert** dropdown.
60+
1. In the top right, click **Dismiss alert** dropdown.
5961

6062
1. Select any reason and add a short explanation then click the **Dismiss alert** button.
6163

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

64-
1. Navigate back to **Security** tab and **Code scanning alerts** area.
67+
1. Reopen the alert.
6568

66-
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.
6771

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

.github/steps/3-step.md

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,6 @@ If you expand the **More info** section at the bottom of the alert, there are ve
3030
"SELECT * FROM books WHERE name LIKE %s", name
3131
```
3232

33-
1. Navigate to about **line 22** and modify it to the below.
34-
35-
```py
36-
"SELECT * FROM books WHERE author LIKE %s", author
37-
```
38-
3933
1. Above the editor in the top-right, click the **Commit changes...** button. Use the defaults options to commit the changes to `main`.
4034

4135
- CodeQL will now initiate a another scan.
@@ -47,4 +41,15 @@ If you expand the **More info** section at the bottom of the alert, there are ve
4741
- There should be zero open alerts and two closed alerts. Nice work! 🎉
4842
- Feel free to review the closed alerts, especially the audit trail.
4943

50-
1. With the CodeQL job finished, Mona will check your progress and share the next steps.
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/steps/4-step.md

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

server/routes.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,14 @@ def index():
1313

1414
if name:
1515
cursor.execute(
16-
"SELECT * FROM books WHERE name LIKE '%" + name + "%'"
16+
"SELECT * FROM books WHERE name LIKE %s", name
1717
)
1818
books = [Book(*row) for row in cursor]
1919

2020
elif author:
2121
cursor.execute(
22-
"SELECT * FROM books WHERE author LIKE '%" + author + "%'"
22+
"SELECT * FROM books WHERE author LIKE %s", author
23+
2324
)
2425
books = [Book(*row) for row in cursor]
2526

0 commit comments

Comments
 (0)