-
Notifications
You must be signed in to change notification settings - Fork 77
chore(ci): add security workflow with dependency audit, CodeQL, and secret scanning #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,118 @@ | ||
| name: Security | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| push: | ||
| branches: [main, dev, stg] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| security-events: write # CodeQL needs this to upload SARIF results | ||
|
|
||
| jobs: | ||
|
|
||
| # ── 1. Dependency audit ──────────────────────────────────────────────────── | ||
| # Blocks on HIGH/CRITICAL in production dependencies (what ships to users). | ||
| # Dev-only vulns (vitest, esbuild) are reported but do not fail the build. | ||
| audit: | ||
| name: Dependency Audit | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🔒 Security & Privacy | 🟠 Major | ⚡ Quick win Pin third-party actions to full commit SHAs. All actions ( As per path instructions, "All third-party actions must be pinned to a full 40-char commit SHA." Example pin for checkout- - uses: actions/checkout@v5
+ - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v5.0.0Also applies to: 45-45, 46-46, 61-61, 63-63, 68-68, 76-76, 88-88, 90-90, 110-115 🧰 Tools🪛 zizmor (1.26.1)[warning] 22-22: credential persistence through GitHub Actions artifacts (artipacked): does not set persist-credentials: false (artipacked) 🤖 Prompt for AI AgentsSource: Path instructions |
||
|
|
||
| - uses: actions/setup-node@v5 | ||
| with: | ||
| node-version: 22 | ||
| cache: 'npm' | ||
|
|
||
| - run: npm ci | ||
|
|
||
| - name: Audit production dependencies (blocking) | ||
| run: npm audit --omit=dev --audit-level=high | ||
|
|
||
| - name: Audit all dependencies (informational) | ||
| run: npm audit --audit-level=high || true | ||
|
|
||
| # ── 2. Dependency review on PRs ─────────────────────────────────────────── | ||
| # Blocks PRs that introduce new vulnerable packages. | ||
| # Uses GITHUB_TOKEN automatically — no external API key needed. | ||
| dependency-review: | ||
| name: Dependency Review | ||
| runs-on: ubuntu-latest | ||
| if: github.event_name == 'pull_request' | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| - uses: actions/dependency-review-action@v4 | ||
| with: | ||
| fail-on-severity: high | ||
|
|
||
| # ── 3. CodeQL static analysis ───────────────────────────────────────────── | ||
| # Catches classes of bugs the linter/typechecker miss: | ||
| # CWE-22 path traversal (F-003, F-009) | ||
| # CWE-918 SSRF (F-002) | ||
| # CWE-73 external file path control (F-008) | ||
| # CWE-116 improper output encoding (F-004, F-006) | ||
| # Free for public repos. Uses GITHUB_TOKEN — no external key. | ||
| codeql: | ||
| name: CodeQL | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
|
|
||
| - uses: actions/setup-node@v5 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@v3 | ||
| with: | ||
| languages: javascript-typescript | ||
| queries: security-extended | ||
|
|
||
| - run: npm ci && npm run build | ||
|
|
||
| - name: Analyze | ||
| uses: github/codeql-action/analyze@v3 | ||
| with: | ||
| category: '/language:javascript-typescript' | ||
|
|
||
| # ── 4. ESLint with security rules ───────────────────────────────────────── | ||
| # Runs eslint-plugin-security against src/ using eslint.security.config.mjs. | ||
| # Separate from the main lint job so security findings surface distinctly. | ||
| # No API key — pure local analysis. | ||
| lint-security: | ||
| name: ESLint Security | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
|
|
||
| - uses: actions/setup-node@v5 | ||
| with: | ||
| node-version: 22 | ||
| cache: 'npm' | ||
|
|
||
| - run: npm ci | ||
|
|
||
| - name: Install security plugin | ||
| run: npm install --no-save eslint-plugin-security | ||
|
|
||
| - name: Run security lint | ||
| run: npx eslint src/ --config eslint.security.config.mjs --format stylish | ||
|
|
||
| # ── 5. Secret scanning ──────────────────────────────────────────────────── | ||
| # Scans git history for accidentally committed secrets (API keys, tokens). | ||
| # gitleaks is open source, no account or API key required. | ||
| secret-scan: | ||
| name: Secret Scan | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - uses: actions/checkout@v5 | ||
| with: | ||
| fetch-depth: 0 # full history needed for git log scan | ||
|
|
||
| - name: Scan for secrets with gitleaks | ||
| uses: gitleaks/gitleaks-action@v2 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # GITLEAKS_LICENSE not set — free mode scans public repos without limit | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,39 @@ | ||||||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||||||
| * Security-focused ESLint config used by CI security job only. | ||||||||||||||||||||||||||||||
| * Run: npx eslint src/ --config eslint.security.config.mjs | ||||||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||||||
| * Requires eslint-plugin-security to be installed: | ||||||||||||||||||||||||||||||
| * npm install --no-save eslint-plugin-security | ||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||
| import security from 'eslint-plugin-security'; | ||||||||||||||||||||||||||||||
| import tseslint from 'typescript-eslint'; | ||||||||||||||||||||||||||||||
| import globals from 'globals'; | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| export default tseslint.config( | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| ignores: ['dist/**', 'coverage/**', 'node_modules/**', 'sandbox/**'], | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| security.configs.recommended, | ||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||
| languageOptions: { | ||||||||||||||||||||||||||||||
| ecmaVersion: 2022, | ||||||||||||||||||||||||||||||
| sourceType: 'module', | ||||||||||||||||||||||||||||||
| globals: { ...globals.node }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| rules: { | ||||||||||||||||||||||||||||||
| // Block non-literal paths in fs calls — catches CWE-22, CWE-73 | ||||||||||||||||||||||||||||||
| 'security/detect-non-literal-fs-filename': 'error', | ||||||||||||||||||||||||||||||
| // Warn on object injection via bracket notation with user input | ||||||||||||||||||||||||||||||
| 'security/detect-object-injection': 'warn', | ||||||||||||||||||||||||||||||
| // Warn on timing-unsafe comparisons (token equality checks) | ||||||||||||||||||||||||||||||
| 'security/detect-possible-timing-attacks': 'warn', | ||||||||||||||||||||||||||||||
| // Error on non-literal RegExp (ReDoS) | ||||||||||||||||||||||||||||||
| 'security/detect-non-literal-regexp': 'warn', | ||||||||||||||||||||||||||||||
| // Error on child_process with non-literal args | ||||||||||||||||||||||||||||||
| 'security/detect-child-process': 'error', | ||||||||||||||||||||||||||||||
| // Disable rules that generate too much noise for a CLI codebase | ||||||||||||||||||||||||||||||
| 'security/detect-non-literal-require': 'off', | ||||||||||||||||||||||||||||||
| 'security/detect-unsafe-regex': 'warn', | ||||||||||||||||||||||||||||||
|
Comment on lines
+30
to
+36
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win Comment/severity mismatches. The comment on Line 30 says "Error on non-literal RegExp (ReDoS)" but the rule is set to Proposed fix- // Error on non-literal RegExp (ReDoS)
+ // Warn on non-literal RegExp (ReDoS)
'security/detect-non-literal-regexp': 'warn',
// Error on child_process with non-literal args
'security/detect-child-process': 'error',
- // Disable rules that generate too much noise for a CLI codebase
+ // Disable/reduce noisy rules for a CLI codebase
'security/detect-non-literal-require': 'off',
'security/detect-unsafe-regex': 'warn',📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🔒 Security & Privacy | 🟠 Major | ⚡ Quick win
Scope
security-events: writeto the CodeQL job only.security-events: writeis only required by thecodeqljob to upload SARIF results, yet it's granted workflow-wide, givingaudit,dependency-review,lint-security, andsecret-scanunnecessary write access. Static analysis flags this as excessive-permissions.As per path instructions, "Prefer least-privilege
permissions:blocks."Proposed fix
🧰 Tools
🪛 zizmor (1.26.1)
[warning] 11-11: overly broad permissions (excessive-permissions): security-events: write is overly broad at the workflow level
(excessive-permissions)
🤖 Prompt for AI Agents
Sources: Path instructions, Linters/SAST tools