Security Scanning in CI Pipeline
This document describes the security scanning setup for the Anchorpipe project, including CodeQL, Dependabot, SAST, and SCA tools.
Overview
Anchorpipe uses multiple security scanning tools to identify and remediate vulnerabilities:
- CodeQL: Static analysis for JavaScript/TypeScript code
- Dependabot: Automated dependency updates and vulnerability alerts
- SAST: Static Application Security Testing (npm audit)
- SCA: Software Composition Analysis (Snyk)
CodeQL Analysis
Configuration
CodeQL is configured in .github/workflows/codeql.yml and runs:
- On every push to
main - On every pull request targeting
main - Weekly on Mondays at 00:00 UTC
- Manually via
workflow_dispatch
Features
- Languages: JavaScript and TypeScript
- Queries: Security and quality queries (
+security-and-quality) - Results: Uploaded to GitHub Security tab
- PR Annotations: Critical findings automatically annotated on PRs
Viewing Results
- Go to the Security tab in the repository
- Click on Code scanning alerts
- Filter by severity, language, or query
Suppressing False Positives
To suppress a false positive:
- Open the CodeQL alert in the Security tab
- Click Dismiss
- Select reason: False positive or Used in tests
- Add a comment explaining why it's safe to ignore
Dependabot
Configuration
Dependabot is configured in .github/dependabot.yml and monitors:
- npm packages (root and all workspaces)
- Docker images (in
apps/web) - GitHub Actions (workflow files)
Update Schedule
- Frequency: Weekly on Mondays at 09:00 UTC
- Limit: Maximum 10 open pull requests
- Grouping: Security updates are prioritized separately
Security Updates
Security updates are automatically:
- Labeled with
dependenciesandauto-update - Grouped separately from regular updates
- Prioritized for review
Viewing Alerts
- Go to the Security tab
- Click on Dependabot alerts
- Review vulnerable dependencies
Resolving Vulnerabilities
- Automatic PR: Dependabot creates a PR with the fix
- Manual Update: Update the dependency in
package.jsonand runnpm install - Review PR: Test the update and merge if safe
SAST (Static Application Security Testing)
npm audit
The security-scan.yml workflow runs npm audit to detect:
- Known vulnerabilities in npm dependencies
- Outdated packages with security issues
- Direct and transitive dependency vulnerabilities
Severity Levels
- Critical: Blocks PR merge
- High: Blocks PR merge
- Moderate: Non-blocking (warning only)
- Low: Non-blocking (warning only)
Viewing Results
- Check the Security Scanning (SAST/SCA) workflow run
- View the npm audit job logs
- Download the
npm-audit-resultsartifact for detailed JSON
Resolving Issues
# Fix automatically (if possible)
npm audit fix
# Review and fix manually
npm audit
npm update <package-name>
# For breaking changes, review changelog first
npm update <package-name>@<version>
SCA (Software Composition Analysis)
Snyk Integration
Snyk provides additional vulnerability scanning beyond npm audit:
- License compliance: Check for problematic licenses
- Vulnerability database: More comprehensive than npm audit
- Remediation advice: Specific fix recommendations
Setup
- Get a Snyk token from https://app.snyk.io/account
- Add
SNYK_TOKENto repository secrets - The workflow will automatically use Snyk when the token is available
Viewing Results
- Check the Security Scanning (SAST/SCA) workflow run
- View the SCA job logs
- Download the
snyk-resultsartifact for detailed JSON
Resolving Issues
Snyk provides specific remediation advice:
# Install Snyk CLI locally
npm install -g snyk
# Authenticate
snyk auth
# Test and get fix advice
snyk test
# Apply fixes (if available)
snyk fix
Critical Issue Blocking
How It Works
Critical and high severity vulnerabilities block PR merges:
- Security scans run automatically on every PR
- If critical/high issues are found, the workflow fails
- PR status shows as "failing" with a comment explaining the issue
- PR cannot be merged until vulnerabilities are resolved
Bypassing (Not Recommended)
Do not bypass security checks unless absolutely necessary.
If you must bypass (e.g., false positive that can't be suppressed):
- Document the reason in the PR description
- Get explicit approval from security team
- Use GitHub's "bypass branch protection" feature (admin only)
Reports and Archiving
Artifact Retention
- npm audit results: 30 days
- Snyk results: 30 days
- CodeQL results: Stored in GitHub Security tab (permanent)
Accessing Archived Reports
- Go to the workflow run
- Click on Artifacts
- Download the relevant artifact (JSON format)
Suppressing False Positives
CodeQL
- Open the alert in Security tab
- Click Dismiss
- Select reason and add comment
npm audit
Add to .npmrc:
audit-level=moderate
Or suppress specific packages (not recommended):
{
"overrides": {
"package-name": "^1.2.3"
}
}
Snyk
Use .snyk policy file:
# .snyk
version: v1.0.0
ignore:
SNYK-JS-PACKAGE-123456:
- '*':
reason: False positive - used only in tests
expires: '2025-12-31T00:00:00.000Z'
Best Practices
-
Review Dependabot PRs promptly
- Security updates should be merged quickly
- Test thoroughly before merging
-
Don't ignore security warnings
- Even moderate/low severity issues should be addressed
- Create follow-up issues if not immediately fixable
-
Keep dependencies up to date
- Regular updates reduce attack surface
- Use
npm outdatedto check for updates
-
Monitor security alerts
- Subscribe to Security tab notifications
- Review weekly security reports
-
Document suppressions
- Always document why a false positive is suppressed
- Set expiration dates for suppressions
Troubleshooting
Scan Not Running
Problem: Security scans not appearing in workflow runs
Solutions:
- Check workflow file syntax (YAML validation)
- Verify branch protection rules allow workflows
- Check workflow permissions in repository settings
False Positives
Problem: Legitimate code flagged as vulnerable
Solutions:
- Suppress in CodeQL (Security tab)
- Add to
.snykpolicy (for Snyk) - Document in PR if temporary suppression needed
Slow Scans
Problem: Security scans taking too long
Solutions:
- Reduce scope (scan only changed files)
- Use caching for dependencies
- Run scans in parallel jobs
Token Issues
Problem: Snyk scan failing due to token
Solutions:
- Verify
SNYK_TOKENsecret is set - Check token hasn't expired
- Verify token has correct permissions
Related Documentation
- CI/CD Pipeline Setup - CI/CD pipeline configuration
- Security Best Practices - Security policy
- Foundation Guides - Foundation documentation
Support
For security scanning issues:
- CodeQL: Check GitHub CodeQL documentation
- Dependabot: Check Dependabot documentation
- Snyk: Check Snyk documentation
- General: Open an issue with label
area:security