Skip to content

Commit 7c1057f

Browse files
committed
chore: harden secret scanning
1 parent f1d00cd commit 7c1057f

6 files changed

Lines changed: 106 additions & 1 deletion

File tree

.githooks/pre-commit

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ -n "${CI:-}" ]]; then
6+
exit 0
7+
fi
8+
9+
if git diff --cached --quiet; then
10+
exit 0
11+
fi
12+
13+
if ! command -v gitleaks >/dev/null 2>&1; then
14+
echo "gitleaks is required for commits in this repo. Install it with: brew install gitleaks"
15+
exit 1
16+
fi
17+
18+
gitleaks protect --staged --source . --redact --no-banner

.github/workflows/gitleaks.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Gitleaks
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches:
7+
- main
8+
9+
jobs:
10+
scan:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- name: Checkout repository
15+
uses: actions/checkout@v4
16+
17+
- name: Install gitleaks
18+
run: |
19+
set -euo pipefail
20+
version=8.30.0
21+
curl -sSL "https://github.com/gitleaks/gitleaks/releases/download/v${version}/gitleaks_${version}_linux_x64.tar.gz" | tar -xz gitleaks
22+
chmod +x gitleaks
23+
echo "$PWD" >> "$GITHUB_PATH"
24+
25+
- name: Scan tracked files
26+
run: bash scripts/security-scan.sh

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
# Dependencies
22
node_modules/
33

4+
# Local env files and backups
5+
.env
6+
.env.*
7+
.env*~
8+
*~
9+
410
# Configuration files are stored securely in:
511
# ~/.config/hyper-post/signup-data.json (credentials & templates)
612
# ~/.config/hyper-post/config.json (default template settings)

package.json

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,12 @@
2525
"db:push": "prisma db push",
2626
"db:studio": "prisma studio",
2727
"db:migrate": "prisma migrate dev",
28-
"db:seed": "tsx prisma/seed.ts"
28+
"db:seed": "tsx prisma/seed.ts",
29+
"setup-hooks": "bash scripts/setup-git-hooks.sh",
30+
"security:scan": "bash scripts/security-scan.sh",
31+
"security:audit": "gitleaks detect --source . --redact",
32+
"security:scan:staged": "gitleaks protect --staged --source . --redact",
33+
"postinstall": "bash scripts/setup-git-hooks.sh"
2934
},
3035
"keywords": [
3136
"social-media",

scripts/security-scan.sh

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if ! command -v git >/dev/null 2>&1; then
6+
echo "git is required to run the tracked-file secret scan"
7+
exit 1
8+
fi
9+
10+
if ! command -v gitleaks >/dev/null 2>&1; then
11+
echo "gitleaks is required to run the tracked-file secret scan. Install it with: brew install gitleaks"
12+
exit 1
13+
fi
14+
15+
repo_root=$(git rev-parse --show-toplevel)
16+
tmpdir=$(mktemp -d)
17+
18+
cleanup() {
19+
rm -rf "$tmpdir"
20+
}
21+
22+
trap cleanup EXIT
23+
24+
while IFS= read -r -d '' path; do
25+
mkdir -p "$tmpdir/$(dirname "$path")"
26+
cp "$repo_root/$path" "$tmpdir/$path"
27+
done < <(git -C "$repo_root" ls-files -z)
28+
29+
gitleaks detect --source "$tmpdir" --no-git --redact --no-banner

scripts/setup-git-hooks.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
if [[ -n "${CI:-}" ]]; then
6+
exit 0
7+
fi
8+
9+
if ! command -v git >/dev/null 2>&1; then
10+
exit 0
11+
fi
12+
13+
if ! git rev-parse --show-toplevel >/dev/null 2>&1; then
14+
exit 0
15+
fi
16+
17+
repo_root=$(git rev-parse --show-toplevel)
18+
cd "$repo_root"
19+
20+
git config core.hooksPath .githooks
21+
printf 'Configured git hooks for %s\n' "$repo_root"

0 commit comments

Comments
 (0)