You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: .github/steps/1-step.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,12 +13,12 @@ In this first step, we'll be learning more about [CodeQL](https://codeql.github.
13
13
14
14
[CodeQL](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning-with-codeql) is a static analysis testing tool that helps you identify security weaknesses such as SQL injection, cross-site scripting, and code injection issues.
Typically CodeQL patterns are collected into [query suites](https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/about-code-scanning-with-codeql#about-codeql-queries) of patterns. When combined well, this can be a very powerful! To help with this, teams of security experts have pre-populated suites for many common scenarios and programming languages.
19
17
20
18
In many cases, taking advantage of CodeQL is as simple as accepting the default suite, but you can also select the extended suite or customize your own with [GitHub Actions]().
Copy file name to clipboardExpand all lines: .github/steps/2-step.md
+25-8Lines changed: 25 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,8 +1,8 @@
1
-
## Step 2: Prevent Vulnerabilities in a Pull Request
1
+
## Step 2: Detect Vulnerabilities in a Pull Request
2
2
3
3
In this step, we will introduce a vulnerability into the `routes.py` file to trigger an alert.
4
4
5
-
### ⌨️ Activity: Recreate a vulnerability
5
+
### ⌨️ Activity: Create a vulnerability
6
6
7
7
1. In the top navigation, select the **Code** tab.
8
8
@@ -18,15 +18,19 @@ In this step, we will introduce a vulnerability into the `routes.py` file to tri
18
18
"SELECT * FROM books WHERE name LIKE '%"+ name +"%'"
19
19
```
20
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.**
21
+
1. Above the editor in the top-right, click the **Commit changes...** button. Select the radio button next to **Create a new branch** option. **DO NOT commit to the main branch.**
22
22
23
-
1. Click **Propose changes** option and click **Create pull request**.
23
+
1. Click the **Propose changes** option and click **Create pull request**. Use the following branch name.
24
+
25
+
```txt
26
+
learning-codeql
27
+
```
24
28
25
29
### ⌨️ Activity: Review pull request
26
30
27
-
1. If needed, navigate to the newly created pull requests from the previous activity.
31
+
1. If needed, navigate to the newly created pull request from the previous activity.
28
32
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.
33
+
1. Scroll to the bottom of the pull request and search for a check named `CodeQL`. This is the analysis job scanning the proposed code changes in the pull request.
> 💡 Tip: The workflow run contains additional CodeQL information such as the run duration, logs, and analysis artifacts.
55
+
56
+
1. With the pull request started and CodeQL scan finished, Mona will check your progress and share the next steps.
57
+
58
+
> [!TIP]
59
+
> Check out the [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) page to learn more about integration of code scanning into pull requests.
43
60
44
61
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)."-->
62
+
<!--> 💡 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).-->
Copy file name to clipboardExpand all lines: .github/steps/3-step.md
+10-20Lines changed: 10 additions & 20 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,35 +4,20 @@ With our pull request changes now reviewed by CodeQL, let's take a moment to lea
4
4
5
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.
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).
<!-- > 💡 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'
15
+
### What is CWE?
19
16
20
17
Many of the patterns CodeQL scans for come from existing databases of vulnerabilities.
21
18
22
19
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).
23
20
24
-
### ⌨️ Activity: View the status of a CodeQL scan
25
-
26
-
1. In the top navigation, select the **Actions** tab.
27
-
28
-
1. If needed, wait a moment for the CodeQL run to finish (about 4 minutes).
29
-
30
-
1. Click on the **CodeQL Setup** workflow run entry to open a page showing more details.
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.
3
+
Let's fix the security vulnerability we introduced that CodeQL identified.
8
4
9
5
### ⌨️ Activity: Resolve an open alert
10
6
11
7
1. In the top navigation, select the **Security** tab.
12
8
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**.
9
+
1. In the left navigation, find the **Vulnerability alerts** area and select the **Code scanning** option.
16
10
17
-
1. Review the 2 open alerts and review the recommendations to decide changes to make.
11
+
1. Review the open alert and review the recommended changes.
18
12
19
-
1. In the top navigation, select the **Code** tab.
13
+
1. In the top navigation, select the **Code** tab. Ensure you are on the branch for your pull request (`learning-codeql`).
20
14
21
15
1. Navigate to the `server` folder and select the `routes.py` file.
22
16
23
17
1. In the top right of the preview, click the **Edit** button.
1. Navigate to about **line 16** and modify it to the below.
28
22
29
23
```py
30
24
"SELECT * FROM books WHERE name LIKE %s", name
31
25
```
32
26
33
-
1. Above the editor in the top-right, click the **Commit changes...** button. Use the defaults options to commit the changes to `main`.
27
+
1. Above the editor in the top-right, click the **Commit changes...** button. Use the defaults options to commit the changes to the `learning-codeql` branch.
34
28
35
29
- CodeQL will now initiate a another scan.
36
30
@@ -41,15 +35,4 @@ If you expand the **More info** section at the bottom of the alert, there are ve
41
35
- There should be zero open alerts and two closed alerts. Nice work! 🎉
42
36
- Feel free to review the closed alerts, especially the audit trail.
43
37
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.
0 commit comments