-
Notifications
You must be signed in to change notification settings - Fork 0
codeql quick setup
CodeQL is GitHub's code analysis engine that identifies vulnerabilities and code quality issues in your repository. It scans for security flaws, suspicious patterns, and best practice violations.
Your repository must have:
- GitHub Advanced Security enabled (Enterprise, Pro, or Team plan)
- Public repository OR private with Advanced Security
-
.github/workflows/directory - GitHub Actions enabled
Your project now has CodeQL integrated into the unified-ci.yml workflow:
- ✅ JavaScript/TypeScript code
- ✅ Frontend code (
/frontend) - ✅ Backend code (
/backend) - ✅ Scripts and utilities
- ✅ VSCode extension code
- ❌
node_modules/directories - ❌ Build artifacts (
/dist,/build) - ❌ Test files and coverage
- ❌ Minified files
- ❌ Third-party code
The workflow includes required permissions:
permissions:
security-events: write # Allows CodeQL to report results
contents: read # Allows reading source code
actions: read # Allows reading GitHub ActionsGo to: Settings → Code security and analysis
Ensure enabled:
- ✅ Dependency graph (if applicable)
- ✅ Code scanning - CodeQL (or custom)
- ✅ Secret scanning (premium feature)
- ✅ Private vulnerability reporting (premium feature)
CodeQL runs automatically on:
- ✅ Push to
mainbranch - ✅ Pull requests to
mainbranch - ✅ Releases published
- ✅ Scheduled runs (configurable)
After workflow runs, results appear in:
Repository Dashboard
Security tab → Code scanning alerts
Pull Request Checks
- Inline annotations on PR
- Summary in checks section
- Allows dismissing or fixing
GitHub CLI
gh code-scanning view --repo OWNER/REPOMain configuration for CodeQL behavior:
- Paths to scan/ignore
- Languages to analyze
- Query sets to use
- Performance tuning
Workflow definition:
- When CodeQL runs
- What languages to scan
- How to handle results
- Integration with other checks
- 🔴 Error: Critical security vulnerability
- 🟡 Warning: Potential issue to investigate
- 🟢 Note: Informational, good practice
- SQL injection prevention
- Cross-site scripting (XSS)
- Command injection
- Sensitive data exposure
- Authentication bypass
- Dead code
- Unreachable code
- Resource leaks
- Type mismatches
- Potential null pointer exceptions
-
Review the Alert
- Click alert in GitHub
- Read description and CWE reference
- View code path leading to issue
-
Understand the Problem
- Check affected code
- Review usage patterns
- Check data flow
-
Implement Fix
- Use suggested remediation
- Apply security best practices
- Test thoroughly
-
Verify Fix
- Re-run CodeQL
- Confirm alert is resolved
- Close/dismiss alert if needed
// ❌ Bad
const query = `SELECT * FROM users WHERE id = ${userId}`;
// ✅ Good
const query = `SELECT * FROM users WHERE id = ?`;
db.query(query, [userId]);// ❌ Bad
element.innerHTML = userInput;
// ✅ Good
element.textContent = userInput;
// or use DOMPurify library// ❌ Bad
exec(`rm -rf ${path}`);
// ✅ Good
fs.rmSync(path, { recursive: true });- Open alert
- Click "Dismiss"
- Select reason (false positive, won't fix, etc.)
- Add comment (optional)
JavaScript/TypeScript:
// lgtm[js/sql-injection]
const query = `SELECT * FROM table WHERE id = ${id}`;To add scheduled runs, update workflow:
on:
schedule:
- cron: '30 2 * * 0' # Weekly Sunday 2:30 AM UTCFor interpreted languages like JavaScript:
build-mode: none # No build step neededFor compiled languages:
build-mode: autobuild # Or manual with stepsSolution: Check repository has Advanced Security enabled and workflow has security-events: write permission.
Solution:
- Check workflow ran successfully (Actions tab)
- Verify repository settings allow code scanning
- Wait for analysis to complete (can take several minutes)
Solution:
- Review alert severity levels
- Dismiss or fix high-confidence issues first
- Adjust query configuration in
codeql-config.yml
Solution:
- Reduce number of queries (use 'security-and-quality' instead of 'security-extended')
- Exclude large directories
- Increase runner resources (change
runs-on)
Create .github/codeql/custom-queries.ql files for organization-specific rules.
Add to workflow:
strategy:
matrix:
language: ['javascript-typescript', 'python', 'go']Block PRs on high-severity findings by adding branch protection rules.
- Regular Reviews: Check alerts weekly
- Fix Immediately: Don't accumulate technical debt
- Team Education: Share alerts with team
- Document Decisions: Comment on dismissed alerts
- Track Trends: Monitor alert counts over time
- Update Configuration: Refine rules as you learn patterns
For issues:
- Check logs in GitHub Actions
- Review this troubleshooting guide
- Open GitHub issue in CodeQL repository
- Contact GitHub Support (Enterprise)
Les contributions sont bienvenues ! Voir CONTRIBUTING.md
This documentation is automatically synced from the main repository.