← Back to list

How GitHub Detects Leaked Secrets at Massive Scale — A Deep Dive into the Architecture Behind…

Every experienced engineer has done it at least once:  a quick test key, a temporary token, a config file pushed “just for now”.

Arvind Kumar · 2026-01-21 13:03 · 22 claps · 4.0 min read paywalled
#system-design-interview #distributed-systems #github-secret-scanning #github #software-engineering
Open on Medium ↗
Wiki topics: 🔓 · Open Source 🏛️ · Architecture

How GitHub Detects Leaked Secrets at Massive Scale — A Deep Dive into the Architecture Behind GitHub Secret Scanning

Every experienced engineer has done it at least once: a quick test key, a temporary token, a config file pushed “just for now”.

What’s surprising is not that secrets leak — it’s that GitHub reliably detects them, at global scale, in near real time.

This article is a deep technical dive into how GitHub Secret Scanning works, focusing on:

  • The system design principles behind it
  • Why regex alone is not enough
  • How false positives are controlled
  • High-Level Design (HLD)
  • Low-Level Design (LLD)
  • How this can be extended into a standalone Spring Boot service you can simulate locally

Full story for non-members | Microservices E-Book | Spring Boot E-Book | Join Whatsapp Group for Daily Tech Bytes | Youtube | LinkedIn

Problem Statement

GitHub hosts:

  • 100M+ repositories
  • Millions of commits per day
  • Multiple content surfaces (code, PRs, issues, discussions, wikis)

The goal:

Detect real, exploitable secrets before attackers do, without breaking developer workflows or flooding users with false alerts.

This is a streaming security problem, not a static scan.

Screenshot of the email that is received when secrets detected

Screenshot of the email that is received when secrets detected

First Principle: Secrets Are Structured

Secrets are not random strings.

They usually have:

  • Fixed or bounded length
  • Known prefixes or formats
  • High entropy
  • Vendor-specific validation rules

Example:

  • AWS Access Keys
  • Stripe API keys
  • New Relic license keys
  • GitHub tokens

This allows deterministic detection.

Where Detection Happens

Secret scanning is triggered at write time, not as a background batch job.

Surfaces scanned:

  • Git pushes (commit diffs)
  • Pull requests
  • Issues
  • Discussions
  • Wikis

This ensures detection occurs before indexing, caching, or wide replication.

High-Level Architecture (HLD)

At a high level, GitHub Secret Scanning behaves like a distributed streaming pipeline.

Each stage aggressively filters data to reduce cost and noise.

Why This Scales

1. Content Chunking

GitHub never scans entire repositories.

Instead:

  • Diffs and text blobs are split into small, independent chunks
  • Each chunk is scanned independently
  • No long-lived state is required

This allows horizontal scaling.

2. Stateless Workers

The scanner workers:

  • Do not need repo context
  • Do not store secrets
  • Only process text → emit signals

This enables:

  • Elastic scaling
  • Failure isolation
  • Simple deployment

Detection Pipeline Explained

Step 1: Pattern Scanning (Deterministic)

This is the fastest stage.

  • Highly optimized regex engines
  • Vendor-specific patterns
  • Multiple pattern variants per secret type

This stage catches candidates, not confirmed secrets.

Step 2: Entropy Analysis

Many strings look like secrets but aren’t.

Entropy checks help eliminate:

  • Sample keys
  • Dummy values
  • Low-randomness placeholders

High entropy is a strong signal of a real credential.

Step 3: Context Validation

The same string means different things depending on context.

Signals used:

  • File type (YAML, ENV, JSON)
  • Nearby keywords (key, token, license)
  • Assignment syntax
  • Configuration directories

This dramatically reduces false positives.

Step 4: Partner Verification (Critical)

For supported vendors, GitHub verifies:

“Is this key real and active?”

This may involve:

  • Hash-based lookups
  • Partial token verification
  • Vendor-side confirmation

This step turns a suspicion into a high-confidence alert.

Why Attackers Don’t Win the Race

Attackers scan GitHub too.

GitHub wins because:

  • Detection happens before public indexing
  • Alerts may trigger vendor revocation automatically
  • Scanning is upstream of search engines

This timing advantage is everything.

Role of Machine Learning

ML is not the primary detection mechanism.

ML is used for:

  • False positive reduction
  • Pattern evolution
  • Alert prioritization
  • Remediation suggestions

Core detection remains deterministic and explainable.

High-Level Design for a Standalone Secret Scanner

Let’s design a simplified, GitHub-inspired system.

This can be built as a standalone microservice.

Low-Level Design (LLD)

1. Ingestion Layer

  • REST endpoint or Kafka consumer
  • Accepts diffs or raw text
  • Produces scan tasks

2. Chunk Processor

  • Splits input into bounded chunks
  • Normalizes content

3. Pattern Engine

  • Pluggable regex definitions
  • Vendor-specific pattern registry

4. Entropy Checker

  • Shannon entropy calculation
  • Threshold-based filtering

5. Context Analyzer

  • File type detection
  • Keyword proximity scoring

6. Alert Service

  • Severity classification
  • Persistence
  • Notification hooks

LLD Component Diagram

Spring Boot Simulation Strategy

You can simulate this locally using:

  • Spring Boot
  • Kafka (optional, for event ingestion)
  • YAML-based pattern registry

Flow:

  1. Submit a diff via REST
  2. Run it through the pipeline
  3. Emit alerts to logs or DB

This mirrors real-world security tooling.

Why This System Is Hard to Build

This problem combines:

  • Distributed systems
  • Security engineering
  • Performance optimization
  • Vendor coordination
  • Privacy guarantees

Failures are costly:

  • False positives erode trust
  • False negatives cause breaches

That balance is what makes this system impressive.

Closing Thoughts

GitHub Secret Scanning is not just a security feature.

It is:

  • A real-time streaming system
  • A globally distributed detection engine
  • A silent safety net for developers

Most developers only notice it when it fires — which is exactly how good infrastructure should behave.

Liked this deep dive story? If Yes Please 👏 Clap | 📤 Share | 🔔 Follow

=======

Below is a collection of all the stories in one place

[embed]List: Microserices/ Distribtued Systems Concepts | Curated by Arvind Kumar | Medium Microserices/ Distribtued Systems Concepts · Microserices/ Distribtued Systems Concepts which are super helpful for…medium.com


메타데이터
post_id
bc1588bf9a0e
slug
how-github-detects-leaked-secrets-at-massive-scale-a-deep-dive-into-the-architecture-behind-bc1588bf9a0e
url
https://medium.com/@codefarm0/how-github-detects-leaked-secrets-at-massive-scale-a-deep-dive-into-the-architecture-behind-bc1588bf9a0e
canonical_url
https://medium.com/@codefarm0/how-github-detects-leaked-secrets-at-massive-scale-a-deep-dive-into-the-architecture-behind-bc1588bf9a0e
author_url
https://medium.com/@codefarm0
status
ok
fetched_at
2026-08-02 00:12:56