Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions .github/workflows/gitleaks.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Secret Scanning with Gitleaks

on:
push:
branches:
- main
- develop
pull_request:
branches:
- main
- develop

jobs:
gitleaks:
name: Scan for Secrets
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags

- name: Run Gitleaks
uses: gitleaks/gitleaks-action@v2
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITLEAKS_LICENSE: ${{ secrets.GITLEAKS_LICENSE }} # Optional: for Gitleaks Pro

- name: Upload Gitleaks Report
if: failure()
uses: actions/upload-artifact@v4
with:
name: gitleaks-report
path: gitleaks-report.json
retention-days: 30
71 changes: 71 additions & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
title = "VacciChain Gitleaks Configuration"

[extend]
# Use default gitleaks rules as base
useDefault = true

# Custom rules for VacciChain-specific secrets
[[rules]]
id = "stellar-secret-key"
description = "Stellar Secret Key"
regex = '''S[A-Z0-9]{55}'''
tags = ["stellar", "secret", "key"]

[[rules]]
id = "stellar-private-key"
description = "Stellar Private Key (alternative format)"
regex = '''(?i)(stellar[_-]?secret|stellar[_-]?private)[_-]?key["\s:=]+[A-Z0-9]{56}'''
tags = ["stellar", "secret", "key"]

[[rules]]
id = "jwt-secret"
description = "JWT Secret"
regex = '''(?i)(jwt[_-]?secret|jwt[_-]?key)["\s:=]+[A-Za-z0-9+/=]{32,}'''
tags = ["jwt", "secret"]

[[rules]]
id = "soroban-secret"
description = "Soroban Secret Key"
regex = '''(?i)(soroban[_-]?secret|soroban[_-]?key)["\s:=]+[A-Za-z0-9+/=]{32,}'''
tags = ["soroban", "secret"]

[[rules]]
id = "api-key-generic"
description = "Generic API Key"
regex = '''(?i)(api[_-]?key|apikey)["\s:=]+[A-Za-z0-9_\-]{20,}'''
tags = ["api", "key"]

# Allowlist for false positives
[allowlist]
description = "Allowlist for known false positives"
paths = [
'''\.env\.example$''',
'''env\.example$''',
'''\.md$''',
'''test_.*\.js$''',
'''.*\.test\.js$''',
'''.*\.spec\.js$''',
'''__mocks__/.*''',
]

# Allowlist specific patterns that are not real secrets
regexes = [
'''EXAMPLE_.*''',
'''TEST_.*''',
'''DEMO_.*''',
'''your-.*-here''',
'''replace-with-.*''',
'''<.*>''',
'''SXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX''',
]

# Stop words that indicate example/placeholder values
stopwords = [
"example",
"sample",
"test",
"demo",
"placeholder",
"your-secret-here",
"replace-me",
]
10 changes: 10 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
repos:
- repo: https://github.com/gitleaks/gitleaks
rev: v8.18.4
hooks:
- id: gitleaks
name: Detect hardcoded secrets
description: Detect hardcoded secrets using Gitleaks
entry: gitleaks protect --verbose --redact --staged
language: golang
pass_filenames: false
147 changes: 147 additions & 0 deletions PR_DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
# Add Secret Scanning Protection with Gitleaks

## Summary
Implements comprehensive secret scanning protection to prevent accidental commits of sensitive credentials (Stellar secret keys, JWT secrets, API tokens, etc.) to the repository.

## Problem Statement
Previously, no automated protection existed against accidentally committing sensitive credentials like:
- Stellar secret keys (S...)
- JWT secrets
- Private keys
- API tokens
- Soroban secrets

This posed a significant security risk as leaked credentials could compromise the entire VacciChain system.

## Solution
Implemented multi-layered secret scanning using Gitleaks:

### 1. **GitHub Actions CI/CD** (`.github/workflows/gitleaks.yml`)
- Runs on every push to main/develop branches
- Runs on every pull request to main/develop
- Blocks PRs if secrets are detected
- Uploads detailed reports as artifacts for investigation

### 2. **Pre-commit Hooks** (`.pre-commit-config.yaml`)
- Scans staged files before commit
- Blocks commits containing secrets locally
- Provides immediate feedback to developers
- Prevents secrets from ever reaching the repository

### 3. **Custom Configuration** (`.gitleaks.toml`)
- VacciChain-specific secret patterns:
- Stellar secret keys: `S[A-Z0-9]{55}`
- JWT secrets
- Soroban secrets
- Generic API keys
- Allowlist for false positives (example files, tests, documentation)
- Optimized for minimal false positives

### 4. **Setup Scripts**
- `scripts/setup-git-hooks.sh` - For Linux/macOS users
- `scripts/setup-git-hooks.ps1` - For Windows users
- Automated installation of gitleaks and pre-commit
- One-command setup for new developers

### 5. **Documentation** (`docs/secret-scanning-setup.md`)
- Complete setup guide
- Usage instructions
- Troubleshooting tips
- Best practices

## Changes Made

### New Files
- `.gitleaks.toml` - Gitleaks configuration with custom rules
- `.github/workflows/gitleaks.yml` - GitHub Actions workflow
- `.pre-commit-config.yaml` - Pre-commit hook configuration
- `scripts/setup-git-hooks.sh` - Linux/macOS setup script
- `scripts/setup-git-hooks.ps1` - Windows setup script
- `docs/secret-scanning-setup.md` - Complete documentation

## Testing

### Local Testing
```bash
# Test the setup script
./scripts/setup-git-hooks.sh

# Test manual scanning
gitleaks detect --source . --verbose --redact

# Test pre-commit hook
git add .
git commit -m "test"
```

### CI/CD Testing
- GitHub Actions workflow will run automatically on this PR
- Verify workflow passes successfully
- Check that gitleaks scans complete without errors

## Acceptance Criteria Met

βœ… **Gitleaks runs on every PR and push to main**
- Implemented in `.github/workflows/gitleaks.yml`
- Configured for main and develop branches

βœ… **Pre-commit hook configured to block secret commits locally**
- Implemented in `.pre-commit-config.yaml`
- Setup scripts provided for easy installation

βœ… **Scan covers required secret types**
- Stellar secret keys (S...)
- JWT secrets
- Private keys
- API tokens
- Custom Soroban patterns

βœ… **Historical commit scan capability**
- Command provided in documentation
- Can be run manually: `gitleaks detect --source . --log-opts="--all"`

## Deployment Steps

1. **Merge this PR**
2. **All developers run setup script**:
- Linux/macOS: `./scripts/setup-git-hooks.sh`
- Windows: `.\scripts\setup-git-hooks.ps1`
3. **Run historical scan** (one-time):
```bash
gitleaks detect --source . --log-opts="--all" --verbose
```
4. **Rotate any found secrets** immediately

## Security Impact
- **High**: Prevents credential leaks before they happen
- **Proactive**: Catches secrets at commit time, not after push
- **Comprehensive**: Multiple layers of protection (local + CI/CD)

## Performance Impact
- Pre-commit hook adds ~1-3 seconds per commit
- GitHub Actions adds ~30-60 seconds to CI/CD pipeline
- Minimal impact, significant security benefit

## Breaking Changes
None. This is purely additive security enhancement.

## Documentation
- Complete setup guide in `docs/secret-scanning-setup.md`
- Inline comments in configuration files
- Setup scripts with helpful output messages

## Follow-up Tasks
- [ ] Run historical scan on entire repository
- [ ] Rotate any secrets found in historical scan
- [ ] Add secret scanning badge to README
- [ ] Schedule periodic security audits
- [ ] Consider adding additional secret patterns as needed

## Related Issues
Closes #[issue-number] - Add secret scanning protection

---

**Priority**: High
**Effort**: Small
**Security Impact**: Critical
18 changes: 15 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,19 @@ cp .env.example .env
# Fill in your Stellar keys and contract IDs
```

### 2. Deploy the contract
### 2. Setup secret scanning protection

```bash
# Linux/macOS
./scripts/setup-git-hooks.sh

# Windows
.\scripts\setup-git-hooks.ps1
```

This installs [Gitleaks](https://github.com/gitleaks/gitleaks) pre-commit hooks to prevent accidental commits of Stellar secret keys, JWT secrets, and other credentials. See [docs/secret-scanning-setup.md](docs/secret-scanning-setup.md) for details.

### 3. Deploy the contract

```bash
cd contracts
Expand All @@ -268,13 +280,13 @@ make deploy # deploy to testnet, outputs CONTRACT_ID
make test # run contract unit tests
```

### 3. Run with Docker
### 4. Run with Docker

```bash
docker compose up --build
```

### 4. Run locally (without Docker)
### 5. Run locally (without Docker)

```bash
# Backend
Expand Down
Loading
Loading