-
Notifications
You must be signed in to change notification settings - Fork 85
Chore/security ci pipeline #220
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
Open
OkeyAmy
wants to merge
5
commits into
TestSprite:main
Choose a base branch
from
OkeyAmy:chore/security-ci-pipeline
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
019595d
chore(ci): add security workflow, ESLint security config, and sandbox…
OkeyAmy 7d4cf44
Merge branch 'TestSprite:main' into chore/security-ci-pipeline
OkeyAmy eb2bd3e
Merge branch 'TestSprite:main' into chore/security-ci-pipeline
OkeyAmy a5b26d8
apply security review fixes to workflows and lint config
OkeyAmy dbbd7af
update
OkeyAmy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,117 @@ | ||
| name: Security | ||
|
|
||
| on: | ||
| pull_request: | ||
| types: [opened, synchronize, reopened] | ||
| push: | ||
| branches: [main, dev, stg] | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| 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@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 | ||
|
|
||
| - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # 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@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 | ||
| - uses: actions/dependency-review-action@2031cfc080254a8a887f58cffee85186f0e49e48 # v4.9.0 | ||
| 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 | ||
| permissions: | ||
| contents: read | ||
| security-events: write # needed to upload SARIF results | ||
| steps: | ||
| - uses: actions/checkout@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 | ||
|
|
||
| - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 | ||
| with: | ||
| node-version: 22 | ||
|
|
||
| - name: Initialize CodeQL | ||
| uses: github/codeql-action/init@02c5e83432fe5497fd85b873b6c9f16a8578e1d9 # v3 | ||
| with: | ||
| languages: javascript-typescript | ||
| queries: security-extended | ||
|
|
||
| - run: npm ci && npm run build | ||
|
|
||
| - name: Analyze | ||
| uses: github/codeql-action/analyze@02c5e83432fe5497fd85b873b6c9f16a8578e1d9 # 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@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 | ||
|
|
||
| - uses: actions/setup-node@a0853c24544627f65ddf259abe73b1d18a591444 # v5 | ||
| with: | ||
| node-version: 22 | ||
| cache: 'npm' | ||
|
|
||
| - run: npm ci | ||
|
|
||
| - 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@93cb6efe18208431cddfb8368fd83d5badbf9bfd # v5 | ||
| with: | ||
| fetch-depth: 0 # full history needed for git log scan | ||
|
|
||
| - name: Scan for secrets with gitleaks | ||
| uses: gitleaks/gitleaks-action@dcedce43c6f43de0b836d1fe38946645c9c638dc # v2 | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| # GITLEAKS_LICENSE not set — free mode scans public repos without limit |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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', | ||
| // 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/reduce noisy rules for a CLI codebase | ||
| 'security/detect-non-literal-require': 'off', | ||
| 'security/detect-unsafe-regex': 'warn', | ||
| }, | ||
| }, | ||
| ); | ||
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.