Skip to content

Commit f62c959

Browse files
Update to 3 in STEP and README.md
1 parent 2707eae commit f62c959

File tree

2 files changed

+27
-74
lines changed

2 files changed

+27
-74
lines changed

.github/steps/-step.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2
1+
3

README.md

Lines changed: 26 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -16,93 +16,46 @@ _Ensuring the security of application source code is a critical step in modern s
1616
</header>
1717

1818
<!--
19-
<<< Author notes: Step 2 >>>
19+
<<< Author notes: Step 3 >>>
2020
Start this step by acknowledging the previous step.
2121
Define terms and link to docs.github.com.
22-
TBD-step-2-notes.
22+
TBD-step-3-notes.
2323
-->
2424

25-
## Step 2: Review and Triage CodeQL Alerts
25+
## Step 3: Fix Security Vulnerabilities
2626

27-
_Way to go! You got CodeQL running! :tada:_
28-
29-
In this exercise, we'll review the CodeQL scan results, triage an alert, and create a GitHub issue to track an alert.
30-
31-
**What is GitHub Actions**: GitHub Actions is the automation and CI/CD platform within GitHub. We use GitHub Actions to orchestrate and execute security scans with code scanning. GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform that allows you to automate your build, test, and deployment pipeline. For more information on GitHub Actions, see "[Understanding GitHub Actions](https://docs.github.com/en/actions/learn-github-actions/understanding-github-actions)."
32-
33-
**What is CWE**: 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)."
34-
35-
### :keyboard: Activity 1: View the status of a CodeQL scan
36-
37-
In this activity, we'll explore GitHub Actions to view the status of a CodeQL scan.
38-
1. In your new repository, go to your Actions page by selecting **Actions** from the top navigation bar. If the CodeQL Action run is still executing, you will see a yellow spinner indicating the scan is still in progress. This typically takes about 4 minutes to complete.
39-
2. Select the run by clicking on **CodeQL Setup**.
40-
41-
![codeql-setup](/images/codeql-setup.png)
42-
43-
Notice that more information is available inside the Actions run. Feel free to explore this section to view information such as the CodeQL logs, duration, status, and artifacts generated by CodeQL.
44-
45-
Once the scan is complete, a green check will show next to the execution.
27+
_Nice work finishing Step 2: Reviewing and Triaging CodeQL Alerts :sparkles:_
4628

47-
### :keyboard: Activity 2: View all CodeQL Alerts
48-
49-
In this activity, we will view the CodeQL findings in the Security page of your repository. The Security page is where all security related information is displayed.
50-
51-
1. Navigate to the **Security** tab in the top navigation bar of your repository.
52-
2. Select **Code scanning** under the "Vulnerability alerts" heading in left-side navigation bar.
29+
In this step, we will work to fix the existing security vulnerabilities already identified by CodeQL. Remember, at this point, we have introduced CodeQL into our repository and had it scan the existing code. The vulnerabilities it found are real-world issues, and they need to be fixed! We'll fix this issue by editing the `/server/routes.py` file.
5330

54-
This screen will contain all the vulnerabilities identified by CodeQL inside this repository's codebase. Explore the different filters and search capabilities in this page. These filtering capabilities become very helpful when you're working with many findings!
31+
### :keyboard: Activity 1: Review alerts
32+
First, before we fix these alerts, we need to make sure the alerts are still open. We'll also need to gather information on which files to fix and how best to fix them.
5533

34+
1. Navigate to your code scanning alerts page: **Security** > **Code scanning**.
35+
1. You should see two alerts listed as "**Open**". If any of the alerts are listed as "**Closed**", open the alert page and choose **Reopen alert**.
5636

57-
### :keyboard: Activity 3: Review an Alert
58-
59-
In this activity, we will explore the alert UI. We'll review the data flow of the vulnerability, indentify what part of the code the alert impacts, and get more information about the alert.
60-
61-
**Alert status:** This section displays the current alert status (open or closed), identifies the branch where the scan detected the alert, and shows the timestamp of the alert.
37+
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.
6238

63-
![alert-status](/images/alert-status.png)
39+
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.
6440

65-
**Location information:** This section describes which part of the code is vulnerable.
41+
### :keyboard: Activity 2: Edit routes.py
42+
We now know where the issues exist and how to fix them. We'll start by modifying the file `routes.py`. Again, you'll want to do these next steps in a separate browser window or tab.
6643

67-
![location-information](/images/location-information.png)
68-
69-
**Paths:** Clicking on "Show paths" will give you additional insights into the alert's data flow. The modal shows us where the user input (we call that a "source") flows through the application until it's acted on (we call this the "sink"). This visualizes the flow of data through your application.
44+
1. Click the **Code** tab in your repository.
45+
2. Select the `server` folder.
46+
3. Select the `routes.py` file.
47+
4. Click the **Edit** button to the right.
7048

71-
**Recommendations:** This section provides a quick overview of the tool (CodeQL in this case), Rule ID, and even allows you to view the CodeQL query used to find this vulnerability. You can view the query by clicking **View source**. Additionally, this pane includes recommendations for fixing this vulnerability. Click **Show more** to view the full recommendation.
72-
73-
![recommendations](/images/recommendations.png)
74-
75-
**Audit trail:** The audit trail shows the history of the alert. This trail will show the status as users mark an alert as closed or fix an alert in the code.
76-
77-
![audit-trail](/images/audit-trail.png)
78-
79-
**Alert triage:** Use the buttons at the top right of the alert to triage or create a new issue for the alert. Don't do anything yet. We'll get into these buttons in a moment. 😄
80-
81-
**Additional info:** Finally, the right-side panel contains information such as tags, CWE information, and the severity of the alert
82-
![additional-information.png](/images/additiona-information.png)
83-
84-
85-
### :keyboard: Activity 4: Dismiss an Alert
86-
Now that we're familiar with the alert layout, let's work through the process of closing one.
87-
88-
1. Inside this same alert, click **Dismiss alert**, choose any reason for dismissal, and add a short note.
89-
2. Click **Dismiss alert**.
90-
3. At this point, the alert will change its state to "Dismissed". You can now see the change you made in the audit trail at the bottom of the alert.
91-
4. Navigate back to **Security** > **Code scanning alerts**. You'll see that you only have 1 alert listed.
92-
5. Click **1 Closed**. This will bring you to the closed alerts where you can view the alert you just closed.
93-
![one-closed-alert.png](/images/one-closed-alert.png)
94-
95-
7. (Optional) You can also reopen the alert by opening it, then selecting **Reopen alert**.
96-
97-
### :keyboard: Activity 5: Create a GitHub Issue for an Alert
98-
This last step will show you how to create a GitHub Issue to track the work that goes into resolving a vulnerability. Issues provide a space for collaboration for a security problem and can be assigned to people or teams.
49+
![edit-button.png](/images/edit-button.png)
50+
51+
5. Edit line 16 by highlighting the SQL statement and replace it with this text: `"SELECT * FROM books WHERE name LIKE %s", name`.
52+
53+
6. Edit line 22 to replace the SQL statement with this text: `"SELECT * FROM books WHERE author LIKE %s", author`.
9954

100-
1. Open one of the open alerts that CodeQL identified from the scan.
101-
2. Click the green **Create issue** button at the top right of the alert. If you don't see this button, check the status of the alert to make sure it's an open alert.
102-
3. Add any details you would like to include in the new issue form.
103-
4. Click **Submit new issue**.
104-
5. To view the your issue, click **Issues** in the top navigation bar of your repository.
105-
6. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step.
55+
7. Click **Commit changes...** from the top right. The "Propose changes" window will pop up. Leave the defaults configured, and click **Commit changes** again.
56+
8. CodeQL will now initiate a new scan. Check the status of that scan by navigating to **Actions** then choose the **CodeQL** action. Once the scan job completes, Actions will display a green check next to the last run.
57+
9. Once that CodeQL scan is done, navigate to **Security** > **Code scanning** to review the alerts. You should have zero open alerts and two closed alerts 🎉. Feel free to review the closed alerts, especially the audit trail.
58+
10. Wait about 20 seconds then refresh this page (the one you're following instructions from). [GitHub Actions](https://docs.github.com/en/actions) will automatically update to the next step.
10659

10760
<footer>
10861

0 commit comments

Comments
 (0)