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
This will create a GitHub Actions Workflow file with CodeQL already set up. Since Java is a compiled language you will need to setupthe build in later steps. See the [documentation](https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/running-codeql-code-scanning-in-your-ci-system) if you would like to configure CodeQL Analysis with a 3rd party CI system instead of using GitHub Actions.
56
+
This will trigger a CodeQL Scan without needing a workflow file. Since Java is a compiled language the file will use our out-of-the-box [Autobuild action](https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages) but if your application requires more customizable compilation steps, you can switch to the advanced setup and create a workflow file where you can input your desired steps. See the [documentation](https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/running-codeql-code-scanning-in-your-ci-system) if you would like to configure CodeQL Analysis with a 3rd party CI system instead of using GitHub Actions.
57
57
</p>
58
58
</details>
59
59
60
60
<details>
61
61
62
-
<summary>Actions Workflow file</summary>
62
+
<summary>Actions Workflow file (No need to do anything!) </summary>
63
63
<p>
64
64
65
65
#### Actions Workflow
66
66
67
+
As we're going with the Default Setup, this file is not necessary but in case you're curious, here how it looks like:
68
+
67
69
The Actions Workflow file contains a number of different sections including:
68
70
1. Checking out the repository
69
71
2. Initializing the CodeQL Action
@@ -83,7 +85,12 @@ Click `Start Commit` -> `Commit this file` to commit the changes to _main_ branc
83
85
84
86
#### Workflow triggers
85
87
86
-
There are a [number of events](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) that can trigger a GitHub Actions workflow. In this example, the workflow will be triggered on
88
+
There are a [number of events](https://docs.github.com/en/free-pro-team@latest/actions/reference/events-that-trigger-workflows) that can trigger a GitHub Actions workflow.
89
+
90
+
In this example, with the default setup the triggers will be:
@@ -164,9 +171,27 @@ Click `show paths` in order to see the dataflow path that resulted in this alert
164
171
165
172
<details>
166
173
<p>
174
+
<summary>Fix the Security Alert (with Copilot)</summary>
175
+
<p>
176
+
In order to fix this specific alert, we will need to ensure parameters used in the SQL query is validated and sanitized. We will solve this with the power of Copilot!
177
+
</p>
178
+
Open the file [`IndexController.java`](./src/main/java/com/github/hackathon/advancedsecurityjava/Controllers/IndexController.java) in the `Controllers` folder and select line 40. Once highlighted, select `Shift` on your keyboard and click line 53. Finally, click on the Copilot icon that appears to the side of the highlighted code.
Ask Copilot the following prompt or feel free to try with a prompt of your own!
183
+
- English: Rewrite this method to prevent a SQL injection
184
+
- Spanish: Reescribe este método para prevenir SQL injection
185
+
186
+
Integrate the suggested code in your Index Controller. Make sure to click [Edit](https://docs.github.com/en/free-pro-team@latest/github/managing-files-in-a-repository/editing-files-in-your-repository) on the file.
187
+
188
+
Click `Create a new branch for this commit and start a pull request`, name the branch `fix-sql-injection`, and create the Pull Request.
169
189
190
+
</details>
191
+
<details>
192
+
<p>
193
+
<summary>Fix the Security Alert (without Copilot)</summary>
194
+
</p>
170
195
In order to fix this specific alert, we will need to ensure parameters used in the SQL query is validated and sanitized.
171
196
172
197
Click on the `Code` tab and [Edit](https://docs.github.com/en/free-pro-team@latest/github/managing-files-in-a-repository/editing-files-in-your-repository) the file [`IndexController.java`](./src/main/java/com/github/hackathon/advancedsecurityjava/Controllers/IndexController.java) in the `Controllers` folder, replace the content with the file [`fixme`](./fixme).
@@ -175,6 +200,12 @@ Click on the `Code` tab and [Edit](https://docs.github.com/en/free-pro-team@late
175
200
176
201
Click `Create a new branch for this commit and start a pull request`, name the branch `fix-sql-injection`, and create the Pull Request.
177
202
203
+
</details>
204
+
<details>
205
+
<p>
206
+
<summary>Re-Scan your code after new changes</summary>
207
+
</p>
208
+
178
209
#### Pull Request Status Check
179
210
180
211
In the Pull Request, you will notice that the CodeQL Analysis has started as a status check. Wait until it completes.
@@ -256,6 +287,34 @@ Click on `Show more details` by the new `Code Scanning Alert` to jump to the `Se
256
287
Notice that the security alert was found `In pull request` and not in the `main` branch (production).
Find the options for Secret Scanning and Push Protection and make sure they are both Enabled. When they are it should say disabled, similar to this image:
<p><summary>(Bonus) Try to introduce a Secret</summary></p>
307
+
<p>
308
+
309
+
Find yourself a secret that matches any of the [supported secrets](https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns#supported-secrets) and try to commit the value to the Repo. You could commit it to any file! Refer to the previous activities to refresh how Edit and Commit a change.
310
+
311
+
If you received an error, you've done it right!!
312
+
313
+
If you didn't receive an error, this may be why:
314
+
1. The secret is not supported out-of-the-box. For secrets not in the [supported secrets](https://docs.github.com/en/code-security/secret-scanning/introduction/supported-secret-scanning-patterns#supported-secrets) list, you will need to [create a Custom Pattern](https://docs.github.com/en/enterprise-cloud@latest/code-security/secret-scanning/using-advanced-secret-scanning-and-push-protection-features/custom-patterns/defining-custom-patterns-for-secret-scanning) first.
315
+
2. The secret was already leaked and you already have an Open Alert in your Security page. Why cry over spilled milk?!
316
+
3. Check again that Push Protection is enabled on your Repo!
0 commit comments