Skip to content

ci: harden PR security — Semgrep, Gitleaks, CodeQL extended, dep review#10

Merged
patlux merged 9 commits into
mainfrom
test-security-audit
May 28, 2026
Merged

ci: harden PR security — Semgrep, Gitleaks, CodeQL extended, dep review#10
patlux merged 9 commits into
mainfrom
test-security-audit

Conversation

@patlux

@patlux patlux commented May 28, 2026

Copy link
Copy Markdown
Owner

What

Complete security pipeline for external contributor PRs. Guards against the specific attack vectors a malicious contributor could exploit in a pi extension.

Pipeline summary

Job Tool Threat blocked
CodeQL SAST codeql-action@v3 + security-extended, security-and-quality Injection, XSS, logic flaws
Semgrep 20 custom rules (.semgrep/pi-extension-audit.yaml) pi-extension-specific attacks
Gitleaks gitleaks/gitleaks-action@v2 + custom config (.gitleaks.toml) Hardcoded secrets
Dependency review actions/dependency-review-action@v4 Malicious/new packages in PR diff
npm audit npm audit --audit-level=moderate CVE'd dependencies
Script check can-i-ignore-scripts Install-time malware execution

Attack vectors covered by Semgrep rules

Rule What it catches
pi-extension-data-exfiltration-fetch Contributor adds fetch() to send auth keys to attacker server
pi-extension-logging-secrets console.log(apiKey) — credentials leak via pi output
pi-extension-secret-in-error-message Errors include raw auth tokens surfaced to user
pi-extension-api-base-override Changing API_BASE to redirect auth headers to attacker
pi-extension-auth-header-manipulation Overriding Authorization header via options spread
pi-extension-shell-execution exec/spawn/fork in src/ — arbitrary code on user machine
pi-extension-untrusted-dynamic-require require('unknown-package') — supply chain attack
pi-extension-postinstall-script postinstall script in package.json — runs on npm install
pi-extension-auth-path-traversal join(homedir(), '../.ssh') — reading SSH keys
pi-extension-unexpected-fetch Direct fetch() in src/ (bypassing injectable fetchImpl)
pi-extension-eval-like eval(), new Function(), code injection
pi-extension-env-leak Reading process.env vars outside COMMANDCODE_* namespace
pi-extension-oauth-callback-hardcode Hardcoded key in OAuth callback response

Gitleaks custom patterns (.gitleaks.toml)

  • Command Code API keys (user_*) inline or in auth files
  • pi auth.json credential structure in source
  • Hardcoded Bearer tokens
  • OAuth callback URL manipulation

Test trigger file

tests/test-security-triggers.ts simulates a real attacker PR with:

  • Auth file read + fetch exfiltration to attacker server
  • Hardcoded AWS/GitHub tokens
  • eval() injection
  • exec() shell execution
  • Dynamic require('unknown-malicious-package')
  • console.log(apiKey)

Remove this file after CI verification.

Actions needed after merge

  1. Enable Dependency graph in repo Settings → Security (free, required for dep review)
  2. Verify Gitleaks license — personal repo doesn't need one
  3. Run CI once on main to establish baseline

Add three security audit jobs to the CI workflow:
- CodeQL SAST (JavaScript/TypeScript analysis)
- Gitleaks (secret scanning on every commit)
- npm-audit-action (dependency vulnerability checking)

tests/test-security-triggers.ts intentionally contains flagged patterns
to validate the scanners fire correctly. It will be removed after
verification.
@github-advanced-security

Copy link
Copy Markdown

You are seeing this message because GitHub Code Scanning has recently been set up for this repository, or this pull request contains the workflow file for the Code Scanning tool.

What Enabling Code Scanning Means:

  • The 'Security' tab will display more code scanning analysis results (e.g., for the default branch).
  • Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results.
  • You will be able to see the analysis results for the pull request's branch on this overview once the scans have completed and the checks have passed.

For more information about GitHub Code Scanning, check out the documentation.

…cy review

Explicit attacker-focused security pipeline:

- Semgrep with 20 custom rules targeting pi extension threats:
  exfiltration (fetch/XMLHttpRequest), secret logging, API base override,
  auth header manipulation, shell execution, dynamic requires, postinstall
  scripts, auth path traversal, eval/Function injection, env leaks

- Gitleaks custom config (.gitleaks.toml) with project-specific patterns:
  Command Code API keys, pi auth.json credential structures, bearer tokens,
  OAuth callback URLs

- Dependency review action — flags malicious licenses, new packages, known
  vulnerability severity in PR diffs

- CodeQL upgraded to security-extended + security-and-quality query suites

- can-i-ignore-scripts check — audits install-time execution risk

- Dependency review fails on high-severity, blocks merge

test-security-triggers.ts: full attacker simulation — server exfil, shell
exec, dynamic require, code injection

Remove test-security-triggers.ts after CI verification.
@patlux patlux changed the title ci: add security audit workflow (CodeQL, Gitleaks, npm audit) ci: harden PR security — Semgrep, Gitleaks, CodeQL extended, dep review May 28, 2026
Comment thread tests/test-security-triggers.ts Fixed
Comment thread tests/test-security-triggers.ts Fixed
Comment thread tests/test-security-triggers.ts Fixed
Comment thread tests/test-security-triggers.ts Fixed
@github-actions

Copy link
Copy Markdown

Dependency Review

The following issues were found:
  • ✅ 0 vulnerable package(s)
  • ✅ 0 package(s) with incompatible licenses
  • ✅ 0 package(s) with invalid SPDX license definitions
  • ⚠️ 6 package(s) with unknown licenses.
See the Details below.

License Issues

.github/workflows/ci.yml

PackageVersionLicenseIssue Type
actions/dependency-review-action4.*.*NullUnknown License
github/codeql-action/analyze3.*.*NullUnknown License
github/codeql-action/autobuild3.*.*NullUnknown License
github/codeql-action/init3.*.*NullUnknown License
github/codeql-action/upload-sarif3.*.*NullUnknown License
gitleaks/gitleaks-action2.*.*NullUnknown License
Allowed Licenses: MIT, Apache-2.0, BSD-2-Clause, BSD-3-Clause, ISC, 0BSD

OpenSSF Scorecard

PackageVersionScoreDetails
actions/actions/dependency-review-action 4.*.* 🟢 7.7
Details
CheckScoreReason
Code-Review🟢 10all changesets reviewed
Security-Policy🟢 9security policy file detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Maintained🟢 1030 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Packaging⚠️ -1packaging workflow not detected
Token-Permissions🟢 9detected GitHub workflow tokens with excessive permissions
Binary-Artifacts🟢 10no binaries found in the repo
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Pinned-Dependencies⚠️ 1dependency not pinned by hash detected -- score normalized to 1
License🟢 10license file detected
Fuzzing⚠️ 0project is not fuzzed
Signed-Releases⚠️ -1no releases found
Branch-Protection🟢 6branch protection is not maximal on development and all release branches
SAST🟢 9SAST tool detected but not run on all commits
actions/github/codeql-action/analyze 3.*.* UnknownUnknown
actions/github/codeql-action/autobuild 3.*.* UnknownUnknown
actions/github/codeql-action/init 3.*.* UnknownUnknown
actions/github/codeql-action/upload-sarif 3.*.* UnknownUnknown
actions/gitleaks/gitleaks-action 2.*.* 🟢 3
Details
CheckScoreReason
Code-Review🟢 3Found 6/19 approved changesets -- score normalized to 3
Packaging⚠️ -1packaging workflow not detected
Dangerous-Workflow🟢 10no dangerous workflow patterns detected
Maintained⚠️ 00 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Binary-Artifacts🟢 10no binaries found in the repo
Token-Permissions⚠️ 0detected GitHub workflow tokens with excessive permissions
CII-Best-Practices⚠️ 0no effort to earn an OpenSSF best practices badge detected
Pinned-Dependencies⚠️ 0dependency not pinned by hash detected -- score normalized to 0
License🟢 9license file detected
Signed-Releases⚠️ -1no releases found
Fuzzing⚠️ 0project is not fuzzed
Security-Policy⚠️ 0security policy file not detected
Branch-Protection⚠️ 0branch protection not enabled on development/release branches
SAST⚠️ 0SAST tool is not run on all commits -- score normalized to 0

Scanned Files

  • .github/workflows/ci.yml

@patlux patlux merged commit 21d712a into main May 28, 2026
10 checks passed
@patlux patlux deleted the test-security-audit branch May 28, 2026 21:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants