Skip to content
Hafiz Syed Shah Ali

All projects

Case study

Security CI Pipeline

Automatic security checks on every change to this site, including a custom gitleaks rule that found a leaked credential the default rules missed.

The problem

An old version of this site’s code had a Gmail app password in its git history. gitleaks with its default rules reported nothing; a manual review found it.1

A Google app password is 16 lowercase letters with no fixed prefix, so the default rules cannot match it. Until then, checks like this were done by hand. I replaced them with automatic checks that run on every change.

Reconstruction of the original scan (output shortened, secret redacted)
# Run 1: default rules
$ gitleaks git -v --redact
INF no leaks found

# Run 2: same command, after adding the custom rule
$ gitleaks git -v --redact
Secret:  [REDACTED]
RuleID:  gmail-app-password
WRN leaks found: 1

Requirements

  • Free tools only, and no secrets in CI.
  • The pipeline must not become a supply-chain risk itself.
  • A release ships only when every check passes.

What I built

  • Secret scan: gitleaks over the full history of every branch, on every push and daily, with the default rules plus two custom rules.1
  • Dependency audit: npm audit fails on critical vulnerabilities. Dependabot proposes updates every week.
  • Code scan: Semgrep with JavaScript, TypeScript, React and secrets rules fails on any finding. ESLint and the unit tests run in the same workflow.2
  • Live site checks: After every production deploy and daily: all eight security headers and the key CSP directives, the HSTS lifetime, the redirect to the canonical host, a security.txt that is present and not about to expire, and a published CV file that matches its SHA-256 hash in the repository.23
  • Pre-commit hook: gitleaks on the staged changes blocks a commit that contains a secret. It also blocks the commit if gitleaks is not installed.

How it works

  1. Commitpre-commit secret scan
  2. Pushsecret scan, dependency audit, code scan
  3. Gateevery check passes
  4. Deployproduction
  5. Live checksheaders, CSP, security.txt, CV hash
A local commit passes the pre-commit hook, then every push runs the secret scan, dependency audit and code scan in GitHub Actions. A production deploy happens only when all of them pass, and the live site checks run after it. Dependabot’s weekly updates go through the same checks.

Security decisions

  • Every GitHub Action is pinned to a full commit SHA; the Semgrep container is pinned by digest.1
  • Workflows get read-only access to the repository and need no secrets.1
  • The gitleaks binary is checked against its published checksum before it runs.1
  • A new package version is installed only after 7 days on the npm registry, and Dependabot uses the same cooldown. Security fixes are not delayed.4
  • A CI job checks that my private statistics dashboard is never in the build output.4
  • The custom rule: It matches 16 lowercase letters only when they are assigned to a password-like setting, in quotes or in .env and YAML style. Normal text does not match. A test script checks samples that must be found and samples that must not.1

Results

  • On the original commit, the default rules found nothing and the custom rule found the leak, with no false positives in the repository.1
  • The credential was revoked and the git history rebuilt.
  • Every release of this site runs the security workflows and ships only when all of them pass.
  • The custom rule now runs in CI and in the pre-commit hook.

What I’d do next

  • A nonce-based CSP would earn an A+ on securityheaders.com. Today the site keeps static pages and accepts 'unsafe-inline' for scripts as a known trade-off.2
  • Dev-only tooling has documented accepted risks that wait for upstream fixes. Dependabot will open the updates.