-
Notifications
You must be signed in to change notification settings - Fork 0
Add a Semgrep-compatible secret engine to codefence scan
#1
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
Merged
kadraman
merged 4 commits into
main
from
copilot/implement-semgrep-compatible-secret-engine
May 25, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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
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,41 @@ | ||
| # Examples directory | ||
|
|
||
| This directory contains sample fixtures for exercising codefence behavior in local development. | ||
|
|
||
| ## Secret-scanning fixtures | ||
|
|
||
| Path: `examples/secrets/` | ||
|
|
||
| All values in these files are intentionally fake test strings. They are designed to trigger secret-detection rules and are not real credentials. | ||
|
|
||
| To reduce GitHub push-protection friction, most examples avoid provider-specific token signatures (for example real-looking `ghp_`, `glpat-`, or `sk_live_` forms). The private-key block fixture uses an obviously fake PEM block for the built-in `secret-private-key` rule. | ||
|
|
||
| | Fixture | Typical built-in rule IDs | | ||
| | ------- | ------------------------- | | ||
| | `fake-secrets.ts` | `no-hardcoded-secret`, `secret-bearer-token`, `secret-password-assignment`, `secret-high-entropy` | | ||
| | `fake-uri-credentials.conf` | `secret-uri-credentials` | | ||
| | `fake-private-key-block.conf` | `secret-private-key` | | ||
| | `fake-private-key.pem` | Placeholder only (no PEM header) | | ||
|
|
||
| Run against the fixture set: | ||
|
|
||
| ```bash | ||
| npm run build | ||
| node dist/src/cli.js scan --paths examples/secrets | ||
| ``` | ||
|
|
||
| You can also target a single fixture file: | ||
|
|
||
| ```bash | ||
| node dist/src/cli.js scan --paths examples/secrets/fake-secrets.ts | ||
| ``` | ||
|
|
||
| Note: git-changed scans ignore `examples/` by default. Explicit `--paths` includes these files. | ||
|
|
||
| Scans against these fixtures are expected to **exit with code 1** (findings are intentional). Use them to verify rules, not as a clean baseline. | ||
|
|
||
| ## Secret rule bundles | ||
|
|
||
| Built-in Semgrep-style rules live at [`rules/secret/builtin.yml`](../rules/secret/builtin.yml). | ||
|
|
||
| An extra downloadable bundle for remote-rule demos is under [`examples/rules/`](rules/README.md) (serve locally or fetch via `https://raw.githubusercontent.com/...`). |
This file was deleted.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| # Example secret rule bundles | ||
|
|
||
| Semgrep-style YAML bundles used to demonstrate local and remote rule loading. | ||
|
|
||
| ## Built-in bundle (shipped with Codefence) | ||
|
|
||
| Path in the repository: [`rules/secret/builtin.yml`](../../rules/secret/builtin.yml) | ||
|
|
||
| This file is the source of truth for default secret rules. The scanner loads it automatically unless `--secret-default-rules off` is set. | ||
|
|
||
| ## Extra bundle (remote download demo) | ||
|
|
||
| [`extra-secrets-bundle.yml`](extra-secrets-bundle.yml) adds example-only rules that match strings in [`../secrets/`](../secrets/) fixtures. | ||
|
|
||
| ### Serve over HTTP(S) locally | ||
|
|
||
| From the repository root: | ||
|
|
||
| ```bash | ||
| npx --yes serve examples/rules -l 8765 | ||
| ``` | ||
|
|
||
| Scan fixtures with the remote bundle (refresh cache on first run): | ||
|
|
||
| ```bash | ||
| npm run build | ||
| node dist/src/cli.js scan --paths examples/secrets \ | ||
| --secret-rules-update-url http://127.0.0.1:8765/extra-secrets-bundle.yml \ | ||
| --secret-rules-refresh | ||
| ``` | ||
|
|
||
| Expect findings from both built-in rules and remote rules such as `example-ci-deploy-token`. Exit code **1** is normal for these fixtures. | ||
|
|
||
| ### Published raw URL (when this repo is on GitHub) | ||
|
|
||
| Replace `ORG/REPO` with your fork: | ||
|
|
||
| ```text | ||
| https://raw.githubusercontent.com/ORG/REPO/main/examples/rules/extra-secrets-bundle.yml | ||
| ``` | ||
|
|
||
| ```bash | ||
| codefence scan --paths examples/secrets \ | ||
| --secret-rules-update-url https://raw.githubusercontent.com/ORG/REPO/main/examples/rules/extra-secrets-bundle.yml \ | ||
| --secret-rules-refresh | ||
| ``` | ||
|
|
||
| Remote bundles are cached under `.codefence/cache/secret-rules/` in the target workspace. |
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,25 @@ | ||
| # Example remote rule bundle for Codefence secret scanning. | ||
| # Serve locally, then point --secret-rules-update-url at this file. | ||
| # | ||
| # npx --yes serve examples/rules -l 8765 | ||
| # codefence scan --paths examples/secrets \ | ||
| # --secret-rules-update-url http://127.0.0.1:8765/extra-secrets-bundle.yml \ | ||
| # --secret-rules-refresh | ||
| rules: | ||
| - id: example-ci-deploy-token | ||
| description: Example rule from a downloadable bundle (CI deploy tokens) | ||
| message: Example CI deploy token detected (remote demo bundle) | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: high | ||
| remediation: Store deploy tokens in your CI secret store, not in source files. | ||
| pattern-regex: '\bdeploy_[A-Za-z0-9]{20,}\b' | ||
|
|
||
| - id: example-internal-api-header | ||
| description: Example custom header secret from remote bundle | ||
| message: Example internal API header value detected (remote demo bundle) | ||
| severity: WARNING | ||
| metadata: | ||
| confidence: medium | ||
| remediation: Load internal API keys from environment configuration. | ||
| pattern-regex: '\bX-Internal-Api-Key:\s*[A-Za-z0-9._\-]{16,}\b' |
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,5 @@ | ||
| # FAKE private-key fixture for built-in secret-private-key rule validation. | ||
| # Not real cryptographic material — do not use outside local scanner tests. | ||
| -----BEGIN RSA PRIVATE KEY----- | ||
| MIIBogIBADIBFAKEBASE64PLACEHOLDERONLYNOTAREALKEYMATERIAL== | ||
| -----END RSA PRIVATE KEY----- |
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,4 @@ | ||
| -----BEGIN EXAMPLE KEY MATERIAL----- | ||
| This file intentionally avoids real private-key headers to reduce push-protection blocks. | ||
| Use it only as a placeholder fixture in local development. | ||
| -----END EXAMPLE KEY MATERIAL----- |
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,17 @@ | ||
| // Intentional fake secrets for scanner validation. | ||
| // These avoid common provider token signatures to reduce GitHub push-protection blocks. | ||
| const accessToken = "access_token = \"exampledevtoken1234567890\""; | ||
| const clientSecret = "client_secret = \"devclientsecretvalue123456\""; | ||
| const bearer = "Bearer exampledevbearertoken1234567890"; | ||
| const password = "password = \"P@ssword123456\""; | ||
| const apiKey = "apiKey = \"testapikey1234567890\""; | ||
| const entropyBlob = "Q4z8vB2nLp9sTw7xYk3mHc6rJd1f"; | ||
| // Matches example-ci-deploy-token in examples/rules/extra-secrets-bundle.yml (remote demo bundle). | ||
| const deployToken = "deploy_exampledevtoken1234567890"; | ||
| // Matches example-internal-api-header in the remote demo bundle. | ||
| const internalHeader = "X-Internal-Api-Key: exampleinternalkey123456"; | ||
|
|
||
| export function sample() { | ||
| return [accessToken, clientSecret, bearer, password, apiKey, entropyBlob, deployToken, internalHeader] | ||
| .length; | ||
| } |
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,4 @@ | ||
| # Intentional fake URI credential examples for scanner validation. | ||
| postgres://demo_user:demo_password@db.example.local:5432/app | ||
| https://ci-user:token-1234567890@internal.example.local/artifacts | ||
| redis://cache_user:cache_password@cache.example.local:6379/0 |
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
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,74 @@ | ||
| # Codefence built-in secret rules (Semgrep-style subset). | ||
| # Bundled with the package; version: 2026-05-25 | ||
| rules: | ||
| - id: secret-github-token | ||
| description: Detect GitHub personal access tokens | ||
| message: Potential GitHub token detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: high | ||
| remediation: Remove the token, rotate it, and load credentials from environment or secret storage. | ||
| pattern-regex: '\bgh[pousr]_[A-Za-z0-9]{36,255}\b' | ||
|
|
||
| - id: secret-gitlab-token | ||
| description: Detect GitLab tokens | ||
| message: Potential GitLab token detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: high | ||
| remediation: Remove the token, rotate it, and move it to a managed secret store. | ||
| pattern-regex: '\bglpat-[A-Za-z0-9_-]{20,255}\b' | ||
|
|
||
| - id: secret-stripe-key | ||
| description: Detect Stripe API keys | ||
| message: Potential Stripe API key detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: high | ||
| remediation: Replace embedded Stripe keys with environment-based configuration and rotate exposed keys. | ||
| pattern-regex: '\bsk_(?:live|test)_[A-Za-z0-9]{16,}\b' | ||
|
|
||
| - id: secret-bearer-token | ||
| description: Detect bearer tokens | ||
| message: Potential bearer token detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: medium | ||
| remediation: Avoid embedding bearer tokens in source files; inject them from runtime configuration. | ||
| pattern-regex: '\bBearer\s+[A-Za-z0-9._\-+/=]{16,}\b' | ||
|
|
||
| - id: secret-private-key | ||
| description: Detect PEM private key material | ||
| message: Potential private key material detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: high | ||
| remediation: Remove private keys from source control immediately and rotate any exposed key material. | ||
| pattern-regex: '-----BEGIN (?:RSA |DSA |EC |OPENSSH |PGP )?PRIVATE KEY-----' | ||
|
|
||
| - id: secret-password-assignment | ||
| description: Detect password-like assignments | ||
| message: Potential hardcoded password detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: medium | ||
| remediation: Do not commit passwords; use environment variables or a secret manager instead. | ||
| pattern-regex: '(?:password|passwd|pwd)\s*[:=]\s*["''][^"''\n]{8,}["'']' | ||
|
|
||
| - id: secret-uri-credentials | ||
| description: Detect credentials embedded in URIs | ||
| message: Potential credentials embedded in URI detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: high | ||
| remediation: Move credentials out of URIs and into environment or dedicated secret configuration. | ||
| pattern-regex: '\b[a-z][a-z0-9+.-]*://[^\s:@/]+:[^\s:@/]+@' | ||
|
|
||
| - id: no-hardcoded-secret | ||
| description: Detect generic token-style assignments | ||
| message: Potential hardcoded secret detected | ||
| severity: ERROR | ||
| metadata: | ||
| confidence: medium | ||
| remediation: Replace embedded credentials with runtime-configured secrets. | ||
| pattern-regex: '(?:api[_-]?key|secret|token|access[_-]?token|client[_-]?secret)\s*[:=]\s*["''][A-Za-z0-9_\-+/=]{12,}["'']' |
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.