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
2. Give it a few moments to load the repository. Codespaces allows you full access to a cloud compute environment to develop and debug your code. It's a great way to get started with a project quickly and to contribute to open source projects.
20
-
3. Switch to the `lab3/code-scanning-vulnerability` branch. This branch has a commit with an intentional security vulnerability in it. To switch branches, you can:
21
-
- In the lower left of the Codespace, click on `main` and pick the branch.
22
-
- Otherwise, in a terminal (CTRL/CMD + `` ` `` ) and enter: `git checkout lab3/code-scanning-vulnerability`
23
-
4. Open the `routes/login.ts` file. This file has a security vulnerability in it.
24
-
5. Highlight line 36. Let's ask Copilot Chat to explain this line of code. With line 36 highlighted, **right click --> Copilot --> Explain**.
20
+
3. Now Josh has given you a new piece of code to add to the **routes/login.ts** file.
21
+
4. We need to create a new branch. Click **main** in the taskbar at the bottom of VSCode.
22
+
5. Select **Create new branch**, enter **lab3/code-scanning-vulnerability**, and hit Enter. The branch will be created and VSCode will switch to the branch.
23
+
6. Open the **routes/login.ts** file.
24
+
7. Find lines 36-46 and delete them
25
+
26
+
```
27
+
models.sequelize.query(
28
+
'SELECT * FROM Users WHERE email = :email AND password = :password AND deletedAt IS NULL',
29
+
{
30
+
replacements: {
31
+
email: req.body.email || '',
32
+
password: security.hash(req.body.password || '')
33
+
},
34
+
model: UserModel,
35
+
plain: true
36
+
}
37
+
)
38
+
```
39
+
40
+
8. At line 36, add the following code:
41
+
42
+
```
43
+
models.sequelize.query(`SELECT * FROM Users WHERE email = '${req.body.email || ''}' AND password = '${security.hash(req.body.password || '')}' AND deletedAt IS NULL`, { model: UserModel, plain: true })
44
+
```
45
+
46
+
9. You know what? Maybe we should double-check this code from Josh. Highlight line 36. Let's ask Copilot Chat to explain this line of code. With line 36 highlighted, **right click** on the line and select **Copilot --> Explain**.
25
47
26
48
<details>
27
49
<imgsrc="images/lab-3-1-2.png"/>
28
50
</details>
29
51
30
-
6. Copilot chat should open up and explain what this line is doing. And oh no, read it thoroughly - it tells us we have a vulnerability! 😱
31
-
7. We can ask Copilot chat how we could fix it. Better yet, do this: right click on line 36 and select **Copilot --> Fix**. ❗️❗️ We don't want to save anything though, so just review the fix for now. ❗️❗️
32
-
8. Let's create a pull request for this branch to attempt to merge it into main.
52
+
10. Copilot chat should open up and explain what this line is doing. And oh no, read it thoroughly - it tells us we have a vulnerability! 😱
53
+
11. We can ask Copilot chat how we could fix it. Better yet, do this: right click on line 36 and select **Copilot --> Fix**. ❗️❗️ We don't want to save anything though, so just review the fix for now. Don't accept this change, discard it.❗️❗️
54
+
12. Let's push our new branch and changes up to GitHub. Select the **Source Control** extension on the left side of Visual Studio Code
55
+
13. Click the **+** button next to **login.ts** to stage the changes
56
+
14. Add a commit message and click **Commit**.
57
+
15. Click **Publish Branch** to push your new branch with the code changes to GitHub.
58
+
16. Let's create a pull request for this branch to attempt to merge it into main.
33
59
- In another browser tab, navigate back to the repository --> **Pull requests** tab --> **New pull request** button --> select the `lab3/code-scanning-vulnerability` to merge into `main`.
60
+
- Click **Create pull request**
61
+
- In the pull request description, click the Copilot icon on the bar and have Copilot generate a pull request summary for you.
62
+
- Click **Create pull request**
34
63
9. After the pull request is created, the code scanning job will have been initiated. You can see the status of the job in the pull request checks. It will take a few minutes to run.
10. CodeQL should find the vulnerability, so the check will fail. Also, we should see Copilot create us an autofix on the PR that we can review.
41
70
11. It might take Copilot a few moments to create the autofix.
42
-
12. Review the autofix - we can prevent a vulnerability from entering the repository now with a click of a button! 🎉But don't commit the suggestion yet.
71
+
12. Review the autofix - we can prevent a vulnerability from entering the repository now with a click of a button! 🎉**But don't commit the suggestion yet.**
43
72
44
73
<details>
45
74
<imgsrc="images/lab-3-1-4.png"/>
46
75
</details>
47
76
48
77
## Exercise 2: Creating a code scanning ruleset
49
78
50
-
Without a ruleset (GitHub's newer version of branch protections), even though CodeQL found the vulnerability, a developer could still merge the code mistakenly, or merge the code before the CodeQL checks finish. Let's prevent this!
79
+
Without a ruleset (GitHub's new version of branch protections), even though CodeQL found the vulnerability, a developer could still merge the code mistakenly, or merge the code before the CodeQL checks finish. Let's prevent this!
51
80
52
81
> [!NOTE]
53
82
> We have to wait for the PR check to finish entirely (with a pass or fail) in order to create the ruleset properly!
0 commit comments