Skip to content

Commit 63c5836

Browse files
author
Admin-01 SecW01
authored
Merge pull request #3 from ghuwsec1953/mickeygousset/dryrun1
Mickeygousset/dryrun1
2 parents 7c130ea + 4dab7e6 commit 63c5836

File tree

7 files changed

+88
-46
lines changed

7 files changed

+88
-46
lines changed

_labs/images/lab-1-3-1.png

-6.28 KB
Loading

_labs/images/lab-2-2-4.png

21.2 KB
Loading

_labs/lab1.md

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ This lab covers parts of the following exam domains:
1212

1313
We need to provision our working copy of the repository in order to begin the labs!
1414

15-
1. Navigate to URL: [https://github.com/joshjohanning-org/juice-shop-ghas-workshop](https://github.com/joshjohanning-org/juice-shop-ghas-workshop) TODO: update URL with universe repo
16-
2. Click on the **Use this template ▾** button.
17-
3. Make sure you have the **githubuniverseworkshops** organization selected.
15+
1. Navigate to URL: [https://github.com/ghuwsec1953/juice-shop-ghas-workshop](https://github.com/ghuwsec1953/juice-shop-ghas-workshop)
16+
2. Click on the **Use this template ▾** button and select **Create a new repository**.
17+
3. Make sure you have the **ghuwsec1953** organization selected as the **Owner**.
1818
4. Name the repository **YOUR_USERNAME-juice-shop-ghas-workshop**.
19-
5. ❗️❗️ Make sure to check the box to **Include all branches**. The other branches are required in order to complete the workshop. ❗️❗️
20-
6. Click the green **Create repository** button to create the repository
19+
5. Set the repository visibility to **Internal**.
20+
6. Click the green **Create repository** button to create the repository.
2121

2222
Once the repository is created, you will be automatically redirected to it. Continue on to Exercise 2.
2323

@@ -40,9 +40,10 @@ In this exercise, you will be guided through the process of enabling the remaini
4040
### Exercise 2.2: Enable Code Scanning
4141

4242
1. Next, let's enable **Code Scanning with CodeQL**. These settings are also under the **Code security** settings page.
43-
2. Underneath the GitHub Advanced Security | Code Scanning heading, click the **Set up** button in the **CodeQL analysis** row.
44-
3. There are two options: **Default** and **Advanced**. For this lab, we will use the **Default** setup which creates a workflow behind the scenes (i.e. you will not see it committed to the repo). You can use the Advanced option to manage your code scanning workflow as a GitHub Actions workflow YAML file committed to the repo.
45-
4. Select the **Default** option, review the settings. By default, we will scan the JavaScript code, use the default CodeQL queries (for highest precision), and scan the default branch on push, pull request, and on a weekly schedule.
43+
2. Click the **Enable** button next to GitHub Advanced Security if it is not enabled. If prompted, then click the **Enable GitHub Advanced Security for this repository** button.
44+
3. Underneath the GitHub Advanced Security | Code Scanning heading, click the **Set up** button in the **CodeQL analysis** row.
45+
4. There are two options: **Default** and **Advanced**. For this lab, we will use the **Default** setup which creates a workflow behind the scenes (i.e. you will not see it committed to the repo). You can use the Advanced option to manage your code scanning workflow as a GitHub Actions workflow YAML file committed to the repo.
46+
5. Select the **Default** option and review the settings. By default, we will scan the JavaScript code (it may suggest Python as well), use the default CodeQL queries (for highest precision), and scan the default branch on push, pull request, and on a weekly schedule.
4647

4748
<details>
4849
<img src="images/lab-1-2-1.png"/>
@@ -68,7 +69,7 @@ In this exercise, you will be guided through the process of enabling the remaini
6869
### Exercise 2.3: Enable Secret Scanning
6970

7071
1. If it's not already enabled, click on the **Enable** button to enable Secret Scanning.
71-
2. Check the box to **Use AI detection to find additional secrets (beta)**. This feature uses AI to find secrets/passwords that may be in your code that don't correspond to a known provider pattern.
72+
2. Check the box to **Scan for generic secrets**. This feature uses AI to find secrets/passwords that may be in your code that don't correspond to a known provider pattern.
7273
3. Click the **Enable** button next to the **Validity checks** setting. This feature checks if the secret is still valid for [specific partners](https://docs.github.com/en/enterprise-cloud@latest/code-security/secret-scanning/introduction/supported-secret-scanning-patterns#high-confidence-patterns), such as AWS and, of course, GitHub. As an example, you can use this feature to check if a GitHub personal access token found in the repo is still valid and needs to be revoked.
7374
4. Click the **Enable** button next to the **Non-provider patterns** setting. This scans for patterns that don't correspond to partners but still have a common syntax, such as a MySQL or MongoDB connection string.
7475
5. Click the **Enable** button next to the "Push protection" setting. This feature will block pushes that contain high-precision secrets. You can use this [chart](https://docs.github.com/en/enterprise-cloud@latest/code-security/secret-scanning/introduction/supported-secret-scanning-patterns#supported-secrets) to determine which types of secrets would be blocked with secret scanning push protection enabled.

_labs/lab2.md

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ Now that we have all of the security feature enabled, let's review the security
44

55
This lab covers parts of the following exam domains:
66

7-
Domain 2: Configure and use secret scanning
8-
Domain 3: Configure and use dependency management
9-
Domain 4: Configure and use code scanning
7+
- Domain 2: Configure and use secret scanning
8+
- Domain 3: Configure and use dependency management
9+
- Domain 4: Configure and use code scanning
1010

1111
## Exercise 1: Reviewing Dependabot alerts
1212

@@ -42,9 +42,8 @@ Domain 4: Configure and use code scanning
4242
5. You can manually close an alert by clicking on the **Dismiss alert** button in the upper right hand corner. It's not recommended to close alerts manually, but there may be times where this is helpful (for example, the code that contains the alert is not used).
4343
- If you resolve an alert by upgrading to a non-vulnerable version, Dependabot will automatically close the alert!
4444
6. If there is a non-vulnerable package version to update to, you will see a **Create Dependabot security update** button to queue Dependabot to attempt to create a pull request automatically to upgrade the vulnerable dependency. With this feature, assuming your build and tests pass, you can merge the pull request to close the alert.
45-
- TODO: Do we want to have them actually do this? or do you think showing/telling them about it is good. enough. Right now I think showing/telling is good enough. We can always add steps to have them do it if we need to lengthen the labs
4645
7. Go **back** to the prior page and let's take a look at the list of Dependabot alerts again.
47-
8. We can filter by **Package**, **Ecosystem**, **Manifest**, and **Severity**. For example, sometimes upgrading just one package can resolve multiple security alerts, so this can be a great way to prioritize fixes.
46+
8. We can filter by **Package**, **Ecosystem**, **Manifest**, and **Severity**. For example, sometimes upgrading just one package can resolve multiple security alerts, so this can be a great way to prioritize fixes. You can see this, if you enabled Dependabot security updates, by the fact that multiple Dependabot alerts are tied to the same PR.
4847

4948
<details>
5049
<img src="images/lab-2-1-4.png"/>
@@ -93,15 +92,21 @@ Domain 4: Configure and use code scanning
9392
9. Oftentimes, there will be a lot of information to help understand the vulnerability and how to fix it. There should be a **Show more** expandable section that will show more information about the type of vulnerability you're working with.
9493
10. In the upper right-hand corner, there is a **Generate fix** button to use Copilot to generate a fix for the vulnerability. Click it! This is a great way to learn how to fix the vulnerability and to see how to fix it in the context of your code.
9594
11. It will take a little time to generate a suggestion. Wait for it to finish.
96-
12. If you're happy with the suggestion, click the **Create PR with fix** button. This will create a draft pull request with the fix for the vulnerability. In a real world example, assuming your build and tests pass, you would merge the PR.
95+
12. If you're happy with the suggestion, click the **Commit to a new branch** button.
96+
13. Accept the defaults and click **Commit change**.
97+
14. This will create a draft pull request with the fix for the vulnerability. In a real world example, assuming your build and tests pass, you would move the PR out of a draft state and merge it.
9798

9899
<details>
99100
<img src="images/lab-2-2-4.png"/>
100101
</details>
101102

102-
13. The nice thing with code scanning alerts (just like Dependabot alerts) is that once you merge the code that resolves an alert, the alert will be automatically closed. This is because the alert is no longer present in the code. After merging the code into the default branch, a code scan will run and once it finishes, the alert will be closed. You can test this by merging the pull request we just created! It will take a few minutes for the code scanning to run and close the alert
103-
14. If you did merge the pull request, check back on the list of code scanning alerts under the **Security** tab in the repo. Once the code scan finishes running, you should see one (1) **Closed** alert listed.
104-
- #TODO: May have to flesh this out more (see comment: https://github.com/joshjohanning-org/universe2024-ghas-workshop/pull/1/files#r1760207693)
103+
13. The nice thing with code scanning alerts (just like Dependabot alerts) is that once you merge the code that resolves an alert, the alert will be automatically closed. This is because the alert is no longer present in the code. After merging the code into the default branch, a code scan will run and once it finishes, the alert will be closed. You can test this by merging the pull request we just created! It will take a few minutes for the code scanning to run and close the alert.
104+
14. Click the **Ready for review** button on the pull request. This moves the pull request out of the draft state
105+
15. Click the **Merge pull request button**, followed by the **Confirm merge** button.
106+
16. Let's go watch the workflow run. Select the **Actions** tab at the top of the page.
107+
17. Select **CodeQL** on the left side of the page. This shows you all the default runs for the CodeQL workflow. You should see a workflow running right now.
108+
18. Click the running workflow to see the details of the run.
109+
19. Once the workflow completes successfully, return to the **Security** tab and check back on the list of code scanning alerts. You should see one (1) **Closed** alert listed.
105110

106111
> [!NOTE]
107112
> You don't need a Copilot license in order to use the Copilot features with GitHub Advanced Security. However, Copilot can certainly be helpful in resolving issues in your IDE and Copilot chat can explain the vulnerability and how to fix it.

_labs/lab3.md

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,49 @@ Domain 6: Describe GitHub Advanced Security best practices
1717
</details>
1818

1919
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**.
2547

2648
<details>
2749
<img src="images/lab-3-1-2.png"/>
2850
</details>
2951

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.
3359
- 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**
3463
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.
3564

3665
<details>
@@ -39,15 +68,15 @@ Domain 6: Describe GitHub Advanced Security best practices
3968

4069
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.
4170
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.**
4372

4473
<details>
4574
<img src="images/lab-3-1-4.png"/>
4675
</details>
4776

4877
## Exercise 2: Creating a code scanning ruleset
4978

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!
5180

5281
> [!NOTE]
5382
> We have to wait for the PR check to finish entirely (with a pass or fail) in order to create the ruleset properly!

_labs/lab4.md

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ With Dependency Review enabled and configured, we want to block vulnerable packa
44

55
This lab covers parts of the following exam domains:
66

7-
Domain 3: Configure and use dependency management
8-
Domain 6: Describe GitHub Advanced Security best practices
7+
- Domain 3: Configure and use dependency management
8+
- Domain 6: Describe GitHub Advanced Security best practices
99

1010
## Exercise 1: Add the Dependency Review Action
1111

@@ -22,7 +22,7 @@ First, let's add the dependency review action workflow.
2222

2323
5. Review the action and its defaults on line 32-39. This action can also block specific open source license types.
2424
6. In the upper right, click on **Commit changes...**
25-
7. Since we have a ruleset, we have to create a branch and merge this to main via pull request. Create a branch and commit (**propose**) the changes.
25+
7. Since we have a ruleset, we have to create a branch and merge this to main via pull request. Create a branch and commit (**Propose changes**) the changes.
2626

2727
<details>
2828
<img src="images/lab-4-1-2.png"/>
@@ -54,7 +54,7 @@ First, let's add the dependency review action workflow.
5454
<img src="images/lab-4-1-5.png"/>
5555
</details>
5656

57-
17. Save the ruleset.
57+
17. Save the changes to the ruleset.
5858

5959
## Exercise 2: Introduce a dependency vulnerability
6060

@@ -68,21 +68,31 @@ Now, let's attempt to add a vulnerable dependency to the codebase and test out t
6868
</details>
6969

7070
3. Navigate back to the **Code** tab in the repo.
71-
4. Switch to the `lab4/dependency-vulnerability` branch.
71+
4. Click the **package.json** file to open it
72+
5. Click the pencil icon at the top right of the file to go into edit mode
73+
6. Go to the end of line 181 and hit Enter to create a blank line for line 182
74+
7. Add the following code to line 182:
75+
76+
```
77+
"tar": "2.2.2",
78+
```
79+
80+
8. Click the **Commit changes** button.
81+
9. Change the branch name to **lab4/dependency-vulnerability** and click **Propose changes** to start a pull request
82+
10. Switch to the `lab4/dependency-vulnerability` branch.
7283
- You can change to this branch by selecting the **main** dropdown below the repository name when under the **Code** tab.
73-
5. Open up the `package.json` file in the repository root.
74-
6. Navigate to line 182 and review this line - this branch has a change to introduce the `"tar": "2.2.2"` package to the codebase - a package with a known vulnerability.
84+
11. Open up the `package.json` file in the repository root.
85+
12. Navigate to line 182 and review this line - this branch has a change to introduce the `"tar": "2.2.2"` package to the codebase - a package with a known vulnerability.
7586

7687
<details>
7788
<img src="images/lab-4-2-2.png"/>
7889
</details>
7990

8091
7. Create a pull request by navigating the the **Pull requests** tab and clicking on the **New pull request** button.
81-
8. Make sure to select the `lab4/dependency-vulnerability` branch to merge into the `main` branch. Also make sure to use Copilot to generate a PR summary for you
82-
If you scroll down to the status check section of the PR, you should see a note: "This branch is out-of-date with the base branch".
83-
10. Click on the **Update branch** button; this adds in the dependency review workflow you committed in the prior exercise. TODO: verify this works correctly
84-
11. Wait for the dependency review job to finish.
85-
12. It should make a comment to the pull request with a note that it found a vulnerable package dependency. In fact, adding this one vulnerable package would introduce 3 new vulnerabilities to our codebase.
92+
8. Use Copilot to generate a PR summary for you
93+
9. Click the **Create pull request** button
94+
10. Wait for the dependency review job to finish.
95+
11. It should make a comment to the pull request with a note that it found a vulnerable package dependency. In fact, adding this one vulnerable package would introduce 3 new vulnerabilities to our codebase.
8696

8797
<details>
8898
<img src="images/lab-4-2-3.png"/>

0 commit comments

Comments
 (0)