Repository navigation
chore: block secrets with a pre-commit hook and a CI scan #161
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
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,10 @@ | ||
| # Verified false positives only: fake Slack tokens used as fixtures in test/setup-slack.test.ts | ||
| # (placeholder digits like A0123456789-1234567890). Fingerprint = commit:file:rule:line. | ||
| 141d0949f621d27b4f55319ba74b5992e6e29c7b:test/setup-slack.test.ts:slack-app-token:19 | ||
| 141d0949f621d27b4f55319ba74b5992e6e29c7b:test/setup-slack.test.ts:slack-app-token:37 | ||
| 141d0949f621d27b4f55319ba74b5992e6e29c7b:test/setup-slack.test.ts:slack-app-token:86 | ||
| 141d0949f621d27b4f55319ba74b5992e6e29c7b:test/setup-slack.test.ts:slack-legacy-workspace-token:36 | ||
| 16ed51f1b97aa99586ffb85af9f563236546d9cd:test/setup-slack.test.ts:slack-app-token:19 | ||
| 16ed51f1b97aa99586ffb85af9f563236546d9cd:test/setup-slack.test.ts:slack-app-token:37 | ||
| 16ed51f1b97aa99586ffb85af9f563236546d9cd:test/setup-slack.test.ts:slack-app-token:94 | ||
| 16ed51f1b97aa99586ffb85af9f563236546d9cd:test/setup-slack.test.ts:slack-legacy-workspace-token:36 |
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,3 @@ | ||
| # Block commits that contain secrets (see CONTRIBUTING.md). | ||
| scripts/scan-staged-secrets.sh | ||
| .githooks/pre-commit |
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,2 @@ | ||
| node_modules/ | ||
| package-lock.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,22 @@ | ||
| { | ||
| "rules": [ | ||
| { | ||
| "id": "@secretlint/secretlint-rule-preset-recommend", | ||
| "rules": [ | ||
| { | ||
| "id": "@secretlint/secretlint-rule-slack", | ||
| "options": { | ||
| "allows": [ | ||
| "/^(xox[a-z]|xapp)-[a-z-]+$/", | ||
| "/^xapp-1-A0123456789-1234567890-/", | ||
| "/^xapp-1-A1-1-[a-z]+$/", | ||
| "/^xapp-N-AXXXX-/", | ||
| "/^xoxb-12345678-90ABCDEF-rest1234$/", | ||
| "/^xoxb-99999-99999-/" | ||
| ] | ||
| } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } |
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 @@ | ||
| # Contributing | ||
|
|
||
| ## Setup | ||
|
|
||
| ```bash | ||
| npm ci # also installs the git hooks (husky, via the "prepare" script) | ||
| npm run typecheck | ||
| HOME=$(mktemp -d) npm test | ||
| ``` | ||
|
|
||
| ## Secret scanning | ||
|
|
||
| Secrets must never reach the repository. Two layers enforce it: | ||
|
|
||
| - **Pre-commit hook** (`.husky/pre-commit`, installed by `npm ci`). It scans the | ||
| *staged* version of every added or changed file with | ||
| [secretlint](https://github.com/secretlint/secretlint) (`.secretlintrc.json`, | ||
| recommended preset), then runs the pattern check in `.githooks/pre-commit` | ||
| (Telegram, Anthropic, OpenAI, AWS, npm). A hit blocks the commit and prints | ||
| the file and line with the value masked. Nothing needs to be installed | ||
| besides the npm dev dependencies. | ||
| - **CI** (`secret-scan` job in `.github/workflows/test.yml`). It runs a pinned, | ||
| checksum-verified [gitleaks](https://github.com/gitleaks/gitleaks) over the | ||
| full git history on every push to `main` and every pull request. | ||
|
|
||
| If the hook blocks you, remove the secret, rotate it if it was real, and commit | ||
| again. Do not bypass with `git commit --no-verify`: CI scans every commit, so a | ||
| secret that slips past the hook still fails the build, and it is already in | ||
| history by then. | ||
|
|
||
| False positives (fake tokens in tests): prefer an obviously fake value. If a | ||
| test needs a realistic shape, allow that exact shape in `.secretlintrc.json` | ||
| (the Slack rule's `allows` list) and, for a commit gitleaks flags, add its | ||
| fingerprint (`commit:file:rule:line`) to `.gitleaksignore` after checking it. | ||
|
|
||
| To run the history scan locally, download gitleaks from its releases page and run | ||
| `gitleaks git --redact --log-opts=HEAD .`. | ||
|
|
||
| Set `HUSKY=0` to skip installing hooks (e.g. in a packaging environment). |
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.
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.
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.
When
package-lock.jsoncontains a credential-bearing private dependency URL or another secret, this ignore rule skips it in the staged secretlint scan; the fallback.githooks/pre-commitchecks only a few token assignments and key prefixes, so such credentials can pass the pre-commit hook. Scan the lockfile too, or replace this blanket exclusion with targeted suppressions.Useful? React with 👍 / 👎.