|
1 | | -# gitfolio |
2 | | -Minimal and modern developer portfolio template built with Next.js and Tailwind CSS. |
| 1 | +# Gitfolio - GitHub Advanced Security Demo |
| 2 | + |
| 3 | +Minimal and modern developer portfolio template built with Next.js - **intentionally vulnerable for educational purposes**. |
| 4 | + |
| 5 | +## ⚠️ Important Security Notice |
| 6 | + |
| 7 | +**THIS REPOSITORY CONTAINS INTENTIONAL SECURITY VULNERABILITIES** |
| 8 | + |
| 9 | +This is a demonstration repository for teaching GitHub Advanced Security features. It includes: |
| 10 | +- Exposed secrets and API keys |
| 11 | +- Vulnerable dependencies |
| 12 | +- Insecure code patterns |
| 13 | + |
| 14 | +**DO NOT USE THIS CODE IN PRODUCTION** |
| 15 | + |
| 16 | +## 🎯 Demo Scenarios |
| 17 | + |
| 18 | +### 1. Secret Scanning Demo 🔐 |
| 19 | + |
| 20 | +**Files to review:** |
| 21 | +- [.env](.env) - Environment variables with exposed secrets |
| 22 | +- [config.js](config.js) - Hardcoded API keys and credentials |
| 23 | + |
| 24 | +**What will be detected:** |
| 25 | +- Stripe API keys |
| 26 | +- AWS credentials |
| 27 | +- Azure connection strings |
| 28 | +- GitHub tokens |
| 29 | +- Database passwords |
| 30 | + |
| 31 | +**Expected behavior:** GitHub Secret Scanning will automatically detect these patterns and create alerts in the Security tab. |
| 32 | + |
| 33 | +### 2. Dependabot Demo 📦 |
| 34 | + |
| 35 | +**Files to review:** |
| 36 | +- [package.json](package.json) |
| 37 | + |
| 38 | +**Vulnerable dependencies included:** |
| 39 | +- `axios@0.21.1` - Known CVE for Server-Side Request Forgery |
| 40 | +- `lodash@4.17.19` - Multiple security vulnerabilities |
| 41 | +- `express@4.17.1` - Potential security issues |
| 42 | +- `next@12.0.0` - Outdated version |
| 43 | +- `react@17.0.2` - Outdated version |
| 44 | + |
| 45 | +**Expected behavior:** Dependabot will: |
| 46 | +1. Scan dependencies on push |
| 47 | +2. Create alerts for known vulnerabilities |
| 48 | +3. Automatically open pull requests with suggested updates |
| 49 | + |
| 50 | +### 3. CodeQL Analysis Demo 🔍 |
| 51 | + |
| 52 | +**Vulnerable API endpoints:** |
| 53 | + |
| 54 | +#### Command Injection |
| 55 | +- **File:** [pages/api/user-search.js](pages/api/user-search.js) |
| 56 | +- **Vulnerability:** User input directly concatenated into shell command |
| 57 | +- **Attack example:** `username=admin; rm -rf /` |
| 58 | + |
| 59 | +#### SQL Injection |
| 60 | +- **File:** [lib/db.js](lib/db.js) |
| 61 | +- **Vulnerability:** Unsanitized user input in SQL queries |
| 62 | +- **Attack example:** `username=admin' OR '1'='1` |
| 63 | + |
| 64 | +#### Path Traversal |
| 65 | +- **File:** [pages/api/download.js](pages/api/download.js) |
| 66 | +- **Vulnerability:** Unrestricted file path access |
| 67 | +- **Attack example:** `filename=../../../../etc/passwd` |
| 68 | + |
| 69 | +#### Cross-Site Scripting (XSS) |
| 70 | +- **File:** [pages/api/display-message.js](pages/api/display-message.js) |
| 71 | +- **Vulnerability:** Unsanitized user input rendered in HTML |
| 72 | +- **Attack example:** `message=<script>alert('XSS')</script>` |
| 73 | + |
| 74 | +**Expected behavior:** CodeQL will trace data flow from user inputs to dangerous sinks and create security alerts. |
| 75 | + |
| 76 | +## 🚀 Setup Instructions |
| 77 | + |
| 78 | +### Prerequisites |
| 79 | +- Node.js 14+ installed |
| 80 | +- GitHub account with Advanced Security enabled |
| 81 | +- Git configured locally |
| 82 | + |
| 83 | +### Quick Start |
| 84 | + |
| 85 | +### Enable GitHub Advanced Security |
| 86 | + |
| 87 | +1. **Push code to GitHub:** |
| 88 | +```bash |
| 89 | +git add . |
| 90 | +git commit -m "Add security demo scenarios" |
| 91 | +git push origin security-for-beginners |
| 92 | +``` |
| 93 | +2. **Enable Advanced Security features:** |
| 94 | + - Go to repository Settings → Security & analysis |
| 95 | + - Enable Dependency graph |
| 96 | + - Enable Dependabot alerts |
| 97 | + - Enable Dependabot security updates |
| 98 | + - Enable Secret scanning |
| 99 | + - Enable Code scanning (CodeQL analysis) |
| 100 | + |
| 101 | +3. **View security alerts:** |
| 102 | + - Navigate to Security tab |
| 103 | + - Check "Code scanning" for CodeQL alerts |
| 104 | + - Check "Secret scanning" for exposed credentials |
| 105 | + - Check "Dependabot" for vulnerable dependencies |
| 106 | + |
| 107 | +## 🛡️ Remediation Examples |
| 108 | + |
| 109 | +### Fix Secret Scanning Issues: |
| 110 | +1. Remove hardcoded secrets from code |
| 111 | +2. Use environment variables properly |
| 112 | +3. Add `.env` to `.gitignore` |
| 113 | +4. Rotate exposed credentials |
| 114 | +5. Use GitHub Secrets for CI/CD |
| 115 | + |
| 116 | +### Fix Dependabot Issues: |
| 117 | +1. Review Dependabot PRs |
| 118 | +2. Test updated dependencies |
| 119 | +3. Merge security updates |
| 120 | +4. Configure Dependabot settings |
| 121 | + |
| 122 | +### Fix CodeQL Issues: |
| 123 | +1. **Command Injection:** Use parameterized commands or allowlists |
| 124 | +2. **SQL Injection:** Use prepared statements/parameterized queries |
| 125 | +3. **Path Traversal:** Validate and sanitize file paths |
| 126 | +4. **XSS:** Sanitize user input, use React's built-in escaping |
| 127 | + |
| 128 | +## 📚 Educational Resources |
| 129 | + |
| 130 | +- [GitHub Advanced Security Documentation](https://docs.github.com/en/code-security) |
| 131 | +- [CodeQL Documentation](https://codeql.github.com/docs/) |
| 132 | +- [Secret Scanning Patterns](https://docs.github.com/en/code-security/secret-scanning/secret-scanning-patterns) |
| 133 | +- [Dependabot Documentation](https://docs.github.com/en/code-security/dependabot) |
| 134 | + |
| 135 | +## 🎓 Learning Objectives |
| 136 | + |
| 137 | +After working through this demo, you should understand: |
| 138 | +1. How GitHub automatically detects security vulnerabilities |
| 139 | +2. The difference between Secret Scanning, Dependabot, and CodeQL |
| 140 | +3. How to interpret and remediate security alerts |
| 141 | +4. Best practices for secure coding |
| 142 | +5. How to configure security policies for your repositories |
| 143 | + |
| 144 | +--- |
| 145 | + |
| 146 | +**Remember:** This repository is for educational purposes only. Never deploy vulnerable code to production! |
0 commit comments