|
| 1 | +# **Secure Open Source Training Repository** |
| 2 | + |
| 3 | +## 🛠️ **What You'll Learn** |
| 4 | +This repository is designed for **hands-on exercises** to help you **secure open-source projects on GitHub**. You'll learn how to: |
| 5 | + |
| 6 | +- **Find and fix vulnerabilities** using **CodeQL and Copilot Autofix** |
| 7 | +- **Detect and remove hardcoded secrets** using **GitHub Secret Scanning & Push Protection** |
| 8 | +- **Keep dependencies secure** with **Dependabot** |
| 9 | +- **Prevent unreviewed code from being merged** by enabling **branch protection** |
| 10 | +- **Set up responsible security reporting** with **SECURITY.md and Private Vulnerability Reporting (PVR)** |
| 11 | + |
| 12 | +Each section contains a **practical exercise** to apply these security best practices. |
| 13 | + |
| 14 | +--- |
| 15 | + |
| 16 | +## 🔒 **Hands-on Security Exercises** |
| 17 | + |
| 18 | +### **1. Running Code Scanning (CodeQL) & Using Copilot Autofix** |
| 19 | +📌 **Objective:** Use **CodeQL scanning** to detect vulnerabilities and **Copilot Autofix** to quickly fix them. |
| 20 | + |
| 21 | +#### **Steps** |
| 22 | +1. **Fork this repository** to your GitHub account. |
| 23 | +2. **Enable Code Scanning**: |
| 24 | + - Go to **Settings > Security > Code Security > Code Scanning**. |
| 25 | + - Click **Enable Default Setup** for **CodeQL Analysis**. |
| 26 | + - Click **Enable CodeQL**. |
| 27 | + - In the **Actions** tab, wait for the CodeQL setup to complete. |
| 28 | +3. **Review vulnerabilities flagged by CodeQL**: |
| 29 | + - Open the **Security** tab |
| 30 | + - 📝 **Note:** If the **Security** tab is not in the main navigation bar, click the **ellipsis menu (…)** in the top-right corner and select **Security**. |
| 31 | + - Click on **Code scanning alerts** to view issues. |
| 32 | +4. **Fix a detected vulnerability using Copilot Autofix**: |
| 33 | + - Click on a detected vulnerability. |
| 34 | + - Click **Generate fix**. |
| 35 | + - Commit the fix to a **new branch**. |
| 36 | + - Click **Commit change** to open a **pull request**. |
| 37 | + - Click **Ready for review** and **Merge pull request**. |
| 38 | + |
| 39 | +✅ **Now, your repository has CodeQL enabled and can automatically detect vulnerabilities!** |
| 40 | + |
| 41 | +--- |
| 42 | + |
| 43 | +### **2. Detecting and Managing Secrets (Secret Scanning & Push Protection)** |
| 44 | +📌 **Objective:** Learn how to verify **Secret Scanning and Push Protection settings**, commit a secret using the GitHub UI, view secret alerts, and properly remove exposed secrets. |
| 45 | + |
| 46 | +#### **Steps** |
| 47 | + |
| 48 | +##### **1. Verify Secret Scanning & Push Protection Are Enabled** |
| 49 | +- Navigate to **Settings > Code security & analysis**. |
| 50 | +- Ensure that both **"Secret scanning"** and **"Push protection"** are enabled. |
| 51 | + |
| 52 | +##### **2. Commit a Secret Using the GitHub** |
| 53 | +- Navigate to **`config.js`** and click the **pencil (✏️) edit button**. |
| 54 | +- Replace the placeholder values with an [AWS secret](https://drive.google.com/file/d/1ZGOQD1YCvp_h2Qhak76fIoK_3kFLFyfi/view?usp=sharing). |
| 55 | +- Scroll down, enter a commit message (e.g., **"Adding AWS keys to test push protection"**), and click **Commit changes**. |
| 56 | + |
| 57 | +##### **3. Observe GitHub’s Behavior** |
| 58 | +- **If Push Protection is enabled**, GitHub will **block the commit** with a security warning. |
| 59 | +- If prompted, **bypass the alert** (for testing purposes). |
| 60 | +- If you force the commit, **Secret Scanning will detect the secret later**. |
| 61 | + |
| 62 | +##### **4. View Secret Scanning Alerts** |
| 63 | +- Go to **Security > Secret Scanning**. |
| 64 | +- 📝 **Note:** If the **Security** tab is not in the main navigation bar, click the **ellipsis menu (…)** in the top-right corner and select **Security**. |
| 65 | + |
| 66 | +##### **5. Respond to a Secret Scanning Alert** |
| 67 | +- Locate the **alert for the committed secret**. |
| 68 | +- Follow GitHub’s **recommended steps** to: |
| 69 | + - **Revoke the exposed secret** (if applicable). |
| 70 | + - **Remove it from the codebase** properly. |
| 71 | + |
| 72 | + |
| 73 | +#### **📌 N.B.: Revoking Secrets from the Service Provider** |
| 74 | +🔴 **Removing the secret from your repository does not revoke its access.** If a real AWS key (or any secret) is exposed, you must: |
| 75 | +1. **Go to your AWS account or the service provider** where the key was generated. |
| 76 | +2. **Revoke or rotate the secret** to prevent unauthorized use. |
| 77 | +3. **Update your application** with a new, secure secret stored safely (e.g., environment variables). |
| 78 | + |
| 79 | +✅ **Now, your repository is protected against secret leaks!** |
| 80 | + |
| 81 | +--- |
| 82 | + |
| 83 | +### **3. Updating Dependencies (Dependabot)** |
| 84 | +📌 **Objective:** Use **Dependabot** to detect and update outdated dependencies. |
| 85 | + |
| 86 | +#### **Steps** |
| 87 | +1. **Enable Dependabot**: |
| 88 | + - Navigate to **Security > Dependabot Alerts**. |
| 89 | + - Enable **Dependabot alerts** if not already active. |
| 90 | + - 📝 **Note:** If the **Security** tab is not in the main navigation bar, click the **ellipsis menu (…)** in the top-right corner and select **Security**. |
| 91 | +2. **Check for dependency alerts**: |
| 92 | + - Go to **Security > Dependabot Alerts**. |
| 93 | +3. **Apply Dependabot's suggested fixes**: |
| 94 | + - Click on a **Dependabot security alert**. |
| 95 | + - Follow instructions to **create a pull request (PR)** for the update. |
| 96 | + - **Merge the PR** to apply the update. |
| 97 | + |
| 98 | +✅ **Now, your repository is set up to detect and fix vulnerable dependencies!** |
| 99 | + |
| 100 | +--- |
| 101 | + |
| 102 | +### **4. Configuring Branch Protection** |
| 103 | +📌 **Objective:** Set up **branch protection rules** to enforce security best practices. |
| 104 | + |
| 105 | +#### **Steps** |
| 106 | + |
| 107 | +##### **1. Navigate to Branch Protection Settings** |
| 108 | +- Go to **Settings > Branches**. |
| 109 | +- Click **"Add Rule"** under **Branch protection rules**. |
| 110 | +- In the **Branch name pattern** field, type `main`. |
| 111 | + |
| 112 | +##### **2. Enable the Following Protection Settings** |
| 113 | +- ✅ **Require pull requests before merging** |
| 114 | +- ✅ **Require at least one approval before merging** |
| 115 | +- ✅ **Require status checks to pass before merging** |
| 116 | +- ✅ **Prevent force pushes to `main`** |
| 117 | + |
| 118 | +##### **3. Save the Changes and Test** |
| 119 | +- Try making a change via the GitHub UI: |
| 120 | + - Click the **pencil (✏️) edit button** on `README.md`. |
| 121 | + - Make a small change and click **"Commit changes"**. |
| 122 | +- GitHub should **block direct commits** and suggest creating a **pull request**. |
| 123 | +- Click **"Create pull request"**, add a description, and submit it. |
| 124 | +- **Request approval** (if required) and merge the pull request. |
| 125 | + |
| 126 | +✅ **Now, your repository is protected against unreviewed changes!** |
| 127 | + |
| 128 | +--- |
| 129 | + |
| 130 | +### **5. Handling a Security Report (`SECURITY.md` & Private Vulnerability Reporting)** |
| 131 | +📌 **Objective:** Learn how to **set up a security policy, report, and manage vulnerabilities responsibly**. |
| 132 | + |
| 133 | +#### **Steps** |
| 134 | + |
| 135 | +##### **1. Create a Security Policy (`SECURITY.md`)** |
| 136 | +- Navigate to **Settings > Security > Security Policy**. |
| 137 | +- Click **"Set up a security policy"**. |
| 138 | +- Define your policy, including: |
| 139 | + - **How to report security issues** |
| 140 | + - **Expected response times** |
| 141 | + - **Preferred contact method** (e.g., Private Vulnerability Reporting, email) |
| 142 | + |
| 143 | +##### **2. Enable Private Vulnerability Reporting (PVR)** |
| 144 | +- Go to **Settings > Security > Private Vulnerability Reporting**. |
| 145 | +- Click **"Enable"** to allow responsible disclosure of vulnerabilities. |
| 146 | + |
| 147 | +##### **3. Simulate a Security Report** |
| 148 | +- Navigate to **Security > Private Vulnerability Reporting**. |
| 149 | +- Click **"Report a Vulnerability"** and submit a sample report. |
| 150 | + |
| 151 | +##### **4. Apply a Security Fix & Publish a Security Advisory** |
| 152 | +- Fix the vulnerability in your repository. |
| 153 | +- Navigate to **Security > Security Advisories**. |
| 154 | +- Click **"New Draft Advisory"**, fill in details, and **publish** once the fix is deployed. |
| 155 | + |
| 156 | +✅ **Now, your repository has a structured process for handling vulnerabilities!** |
| 157 | + |
| 158 | +--- |
| 159 | + |
| 160 | +## **💡 Final Notes** |
| 161 | +- Follow each exercise **step by step**. |
| 162 | +- **Fix vulnerabilities** flagged by GitHub security tools. |
| 163 | +- Explore **GitHub’s security features** in real-time. |
| 164 | + |
| 165 | +**Happy Securing! 🔒** |
0 commit comments