-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
chore(security): add secretlint pre-commit hook + CI scan #708
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
Merged
Changes from all commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| name: Secret Scan | ||
|
|
||
| on: | ||
| pull_request: | ||
| branches: [main] | ||
| push: | ||
| branches: [main] | ||
|
|
||
| # Minimal permissions: secretlint only needs to read repository contents. | ||
| # The workflow does not comment on PRs, upload artifacts, or modify state. | ||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| secretlint: | ||
| name: secretlint | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| # Full history lets secretlint see any new files introduced in a PR | ||
| fetch-depth: 0 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: '20' | ||
| cache: 'npm' | ||
|
|
||
| - name: Install dependencies | ||
| run: npm ci --ignore-scripts | ||
|
|
||
| - name: Run secretlint | ||
| # Scan everything except what .secretlintignore excludes. The pre-commit | ||
| # hook only scans staged files (fast); this CI job is the authoritative | ||
| # check that catches anything that slipped through --no-verify. | ||
| run: npx secretlint --maskSecrets "**/*" "**/.*" | ||
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,34 @@ | ||
| #!/usr/bin/env sh | ||
| # Pre-commit: block accidentally committed secrets. | ||
| # | ||
| # Uses secretlint against staged files only (fast). If secretlint is not | ||
| # installed (e.g. contributor skipped `npm install`), the hook fails open | ||
| # with a warning — CI will still run the authoritative check. | ||
| # | ||
| # To skip this hook locally (NOT recommended): `git commit --no-verify`. | ||
|
|
||
| # Collect list of staged files that would be added/modified (exclude deletions) | ||
| STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMR) | ||
|
|
||
| if [ -z "$STAGED_FILES" ]; then | ||
| exit 0 | ||
| fi | ||
|
|
||
| if ! command -v npx >/dev/null 2>&1; then | ||
| echo "⚠️ husky/pre-commit: npx not found, skipping secret scan" | ||
| exit 0 | ||
| fi | ||
|
|
||
| # Run secretlint on the staged files. --maskSecrets hides any detected values | ||
| # from the terminal output so developers don't accidentally copy them. | ||
| echo "$STAGED_FILES" | xargs npx --no-install secretlint --maskSecrets | ||
| EXIT_CODE=$? | ||
|
|
||
| if [ $EXIT_CODE -ne 0 ]; then | ||
| echo "" | ||
| echo "❌ Secret scanner blocked the commit." | ||
| echo " If this is a false positive, add the file to .secretlintignore" | ||
| echo " or the rule to .secretlintrc.json. To bypass (NOT recommended):" | ||
| echo " git commit --no-verify" | ||
| exit 1 | ||
| fi |
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,35 @@ | ||
| # Large build/data artifacts — no source content, no secret risk | ||
| dist/ | ||
| data/nodes.db | ||
| ui-apps/dist/ | ||
| node_modules/ | ||
|
|
||
| # Local environment files (already gitignored, but secretlint doesn't read | ||
| # .gitignore). Listing here keeps local scans consistent with CI. | ||
| .env | ||
| .env.* | ||
|
|
||
| # Local clones of upstream n8n-docs (already gitignored). These are upstream | ||
| # documentation with example credentials in markdown; not our code to fix. | ||
| n8n-docs/ | ||
| temp/ | ||
|
|
||
| # Package lock files contain integrity hashes and registry URLs that trip | ||
| # high-entropy rules. They are machine-generated and reviewed separately. | ||
| package-lock.json | ||
| ui-apps/package-lock.json | ||
|
|
||
| # Extracted/imported test fixtures (mock data, not real secrets) | ||
| tests/extracted-nodes-db/ | ||
| tests/node-storage-export.json | ||
|
|
||
| # Tests that deliberately contain fake tokens to exercise our own | ||
| # credential-scanner and telemetry redaction code paths. These fixtures | ||
| # are what proves those features work. | ||
| tests/unit/services/credential-scanner.test.ts | ||
| tests/unit/telemetry/telemetry-events.test.ts | ||
|
|
||
| # Template fixtures (user workflow JSON; any embedded credentials are | ||
| # mock data from public n8n.io templates — scanned separately by the | ||
| # sanitize-templates script) | ||
| data/workflow-patterns.json |
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,7 @@ | ||
| { | ||
| "rules": [ | ||
| { | ||
| "id": "@secretlint/secretlint-rule-preset-recommend" | ||
| } | ||
| ] | ||
| } |
Oops, something went wrong.
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.