惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
WordPress大学
WordPress大学
博客园 - 【当耐特】
Engineering at Meta
Engineering at Meta
IT之家
IT之家
Apple Machine Learning Research
Apple Machine Learning Research
小众软件
小众软件
美团技术团队
S
SegmentFault 最新的问题
The GitHub Blog
The GitHub Blog
Martin Fowler
Martin Fowler
Recorded Future
Recorded Future
H
Help Net Security
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
博客园_首页
A
About on SuperTechFans
MongoDB | Blog
MongoDB | Blog
阮一峰的网络日志
阮一峰的网络日志
V
Visual Studio Blog
D
DataBreaches.Net
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
B
Blog
The Register - Security
The Register - Security
I
InfoQ
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
雷峰网
雷峰网
Last Week in AI
Last Week in AI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
Blog — PlanetScale
Blog — PlanetScale
N
Netflix TechBlog - Medium
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
有赞技术团队
有赞技术团队
Stack Overflow Blog
Stack Overflow Blog
Jina AI
Jina AI
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News - Newest:
Hacker News - Newest: "LLM"
U
Unit 42
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
W
WeLiveSecurity
Latest news
Latest news
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
博客园 - 叶小钗
L
Lohrmann on Cybersecurity
博客园 - Franky
Recent Commits to openclaw:main
Recent Commits to openclaw:main
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python) The Hidden Cost of AI Systems Nobody Talks About. undefined vs undeclared, and how typeof behaves Switching from file-based jobs to NATS/Kafka in Rust without changing code io_uring Adventures: Rust Servers That Love Syscalls Why Agentic AI is Killing the Traditional Database The POUR principles of web accessibility for developers and designers Quantum Neural Network 3D — A Deep Dive into Interactive WebGL Visualization How To Install Caveman In Codex On macOS And Windows Automation Pipeline Reliability: Why Your Workflow Breaks When Nobody Is Watching I Built an 'Open World' AI Coding Agent — It Works From ANY Folder From Freelancing to Product: A Tech Service Company's SaaS Transformation China's AI Giants: Adding Tencent Hunyuan & ByteDance Doubao to AI University (74 Providers) On the Vibe Coders and Their Lies clerk: Auto-Summarize Your Claude Code Sessions AI Weekly — 2026/04/10–04/17 | The Model Lockdown Is Here, but the Toolchain Is the Real Battleground AI 週報 — 2026/04/10–2026/04/17 模型封鎖潮來了,但工具鏈才是真戰場 Maybe this is how Open-Source apps are born... 🚀 Fine-Tune LLMs with LoRA and QLoRA: 2026 Guide tRPC v11 + Next.js App Router: End-to-End Type Safety Without the Boilerplate ShadCN UI in 2026: Why I Stopped Installing Component Libraries and Started Owning My Components SaaS Billing in React Server Components: Stripe + Supabase Without a Single `useEffect` Join our DEV Weekend Challenge — $1,000 in Prizes Across TEN winners! Submissions Due April 20 at 6:59 AM UTC. Implementing FSRS Spaced Repetition in Flutter + Supabase — Adding Memory Science to an AI Learning App "I Texted My Localhost From the Train — Claude Code Fixed the Bug Before I Got Home" I Built a Sales Prep AI and It Went Deeper Than Expected Design to Code #2: One JSON, Eleven Outputs Solving the 100M-Row Problem: A Summary Table Pattern for High-Volume Push Notification Logs Flutter Web With Wasm: What Actually Changes For Developers I Built 50 Royalty-Free Soundtracks for My Side Project in a Weekend Using AI Music Generation The Vibe Coding Security Checklist: 7 Things to Check Before You Ship Stop Letting Googlebot Guess Fix Your React App's SEO Right Desconstruindo o Streaming do LinkedIn: Como Criar um Engine de Extração de Vídeo de Alta Performance com HLS e FFmpeg (EDA Part-1) EDA (Exploratory Data Analysis) Explained With Real Life — Why Looking at Your Data Is the Most Important Step in Machine Learning Brand Relationship Management at Scale: Our 4-Touch Outreach System for 200+ Brands Why String.fromEnvironment() Might Return an Empty String in Dart JGuardrails 1.0.0 — Hardening Java LLM Apps Against Jailbreaks, Toxicity, and Prompt Injection Plan and Schedule a Full Week of Threads Content From One Claude Conversation Coding Cat Oran Ep3, Five Tables Changed Everything Updated: BFF Pattern I'm done watching freelancers get buried by 200 proposals. So I'm building the alternative. This is my first post BFS Algorithm in Java Step by Step Tutorial with Examples Tracking LLM Pricing Monthly: An Open Dataset for 22 AI Models How We Measure Content ROI on a Comparison Site: Revenue Attribution Without Perfect Data Introducing Nova AI Ops: The AI-Native Operating System for SRE Teams I built a free desktop video downloader for Windows — Grabbit How Talkie OCR Helps Vision-Impaired & Dyslexic Users Read the World Around Them VRCFaceTracking安装和iPhone面捕配置教程,有bug Even CrowdStrike Can't See Your Agents The Automation Gold Rush: What n8n Workflows and Claude Are Opening Up for Developers Right Now
Your AI Code Has 6 Secret Hits. Only 3 Ship in the npm Package.
Alexey Spinov · 2026-06-25 · via DEV Community

Secrets in a published npm package are a different set from secrets in your repo. A secret scanner reads the whole git tree; npm pack ships only the files allowlist in package.json. leak_probe.py measures both and prints the gap. On the fixture below it found 6 hits and flagged 3 as actually shipping.

TL;DR

  • A scanner reads your git tree. The packager reads the files allowlist. They are not the same file set.
  • On the test package: 6 secret hits total, 3 of them ship in the tarball, 3 are git-only (a test/ fake and a root run.log, both outside the files allowlist). Exit 1.
  • leak_probe.py is ~80 lines of Python: provider regexes + entropy + a packaging filter. No network, no model, no exec, no install.
  • A hit is a SIGNAL, not a confirmed live secret. Verify ship-status with npm pack --dry-run.
  • Runs in about 60 seconds, no API key. Code and fixtures are in the post.

The blind spot nobody scans for

Run gitleaks or trufflehog and you get a list of secrets in your working tree. Useful. But that list answers a question about your repo, not about your release. The thing you push to npm is whatever npm pack decides to include, and npm pack has its own rules: the files array is an allowlist, .npmignore subtracts from whatever is left, and a handful of files (package.json, README.md) always ship.

So two failure modes hide in the gap.

One: a secret your scanner flagged loud and red sits in test/fixtures.js, which is not in your files allowlist, so it never ships. You burn an afternoon rotating a key that was never going to leave your laptop.

Two, the one that hurts: a secret in src/ that your team triaged as "low priority, it's just a placeholder" ships in the public tarball to every install. The scanner saw it. The risk triage downranked it. The packager shipped it anyway.

I have not pushed a leaked key to npm myself. But the shape of this is not theoretical. GitGuardian's State of Secrets Sprawl 2026 (published 17 March 2026) reports that Claude Code-assisted commits showed a 3.2% secret-leak rate versus a 1.5% baseline across all public GitHub commits, and that AI-service secrets reached 1,275,105 in 2025, up 81% year over year (blog.gitguardian.com). Their headline number: 28.65 million new hardcoded secrets added to public GitHub in 2025. Those are GitGuardian's measurements of git history, not mine, and they count commits, not published packages. I am citing them for context, not as my result. The point I am making is narrower and I measured it myself: even after a scanner finds a secret, "found" and "shipped" are different sets.

The contrarian part, stated so you can break it

Here is the claim, sharp enough to argue with: running a secret scanner on your repo does not tell you what ships. A secret can be flagged by the scanner and never leave your machine. A secret the scanner downranks can ship to every install.

That is falsifiable, and I want it to be. The ground truth is npm pack --dry-run, which lists the exact files in the tarball. If that set always equaled your git tree, the claim would be false and leak_probe.py would be pointless. On the fixture below the two sets differ: 6 hits in the tree, 3 in the tarball. Run npm pack --dry-run on the same fixture and you will see src/ and package.json listed, test/ and run.log absent. That is the whole argument in one command.

The tool: ~80 lines, four rules

leak_probe.py does four deterministic things and nothing else:

  1. Provider regexes for vendor-published key shapes: AKIA… (AWS), sk-… (OpenAI), sk_live_… (Stripe), ghp_… (GitHub PAT), xox[baprs]-… (Slack).
  2. Generic high-entropy assignment: a name = "long literal" where the literal has Shannon entropy at least 3.5 and is not pure letters. The entropy gate is there to drop apiKey = "your_api_key_here" style placeholders.
  3. The packaging filter (this is the part a plain scanner does not have): for each file, decide whether npm pack ships it, using the files allowlist, .npmignore, and the always-shipped set.
  4. Density: hits per 100 scanned lines, a local number, not a market average.

Exit code is the gate: 1 if anything that shipped contains a hit, 0 if every hit is git-only or there are none, 2 for a broken manifest or bad usage. Drop it in a pre-publish hook and a shipping secret fails the build.

import sys, os, re, math, json, fnmatch
from collections import Counter

PROVIDERS = [
    ("aws_access_key",   re.compile(r"AKIA[0-9A-Z]{16}")),
    ("openai_key",       re.compile(r"sk-[A-Za-z0-9]{20,}")),
    ("stripe_secret",    re.compile(r"sk_live_[0-9A-Za-z]{16,}")),
    ("github_pat",       re.compile(r"ghp_[A-Za-z0-9]{36}")),
    ("slack_token",      re.compile(r"xox[baprs]-[0-9A-Za-z-]{10,}")),
]
ASSIGN = re.compile(r"""(?ix)(secret|token|api[_-]?key|password|access[_-]?key)\s*[:=]\s*['"]([^'"]{12,})['"]""")

def shannon(s):
    n = len(s)
    return -sum((c / n) * math.log2(c / n) for c in Counter(s).values()) if n else 0.0

The packaging filter is the only clever bit, and it is short. The files field is an allowlist: if it exists, a file ships only if it is named there. .npmignore then subtracts. package.json and README.md always ship.

def ships(rel, allow, ignore):
    base = os.path.basename(rel)
    if base in ("package.json", "README.md"):
        return True                      # npm always ships these
    if allow is not None:                # `files` is an allowlist: opt-in only
        top = rel.split(os.sep)[0]
        if not any(rel == g or top == g.rstrip("/*") for g in allow):
            return False
    return not any(fnmatch.fnmatch(rel, g) or fnmatch.fnmatch(base, g) for g in ignore)

The full script is in the draft repo for this post. It is one file, standard library only, Python 3.

Run it: the real output

Three fixtures. A clean package, a leaky one, and a broken manifest. Here is the verbatim run on Python 3.13.5. Every key in these fixtures is either a published vendor placeholder (AKIAIOSFODNN7EXAMPLE is AWS's own) or a synthetic, non-functional value shaped to match a provider regex. None is a live secret.

Clean package: secrets come from process.env, files: ["src"], nothing hardcoded.

$ python3 leak_probe.py fixtures/clean_pkg
scanned_lines=14  secret_hits=0  density_per_100=0.0  WILL_SHIP_in_package=0
[exit 0]

Zero hits, exit 0. That is the falsifiable floor: a clean tree produces a clean result. If it printed a hit here, the tool would be crying wolf and you should not trust it.

Now the leaky package. Three real-shaped keys in src/secrets.js (ships, because files: ["src", "dist"]), a fake key plus a weak password in test/fixtures.js (does not ship, test/ is not in files), and one key echoed into run.log at the package root (does not ship, because a root run.log is outside the files allowlist; the .npmignore rule *.log is a redundant second belt if files is ever removed).

$ python3 leak_probe.py fixtures/leaky_pkg
scanned_lines=23  secret_hits=6  density_per_100=26.087  WILL_SHIP_in_package=3
  SHIPS    aws_access_key  regex         AKIAIOS...  src/secrets.js
  SHIPS    github_pat      regex         ghp_aZ8...  src/secrets.js
  SHIPS    stripe_secret   regex         sk_live...  src/secrets.js
  git-only aws_access_key  regex         AKIAIOS...  run.log
  git-only openai_key      regex         sk-test...  test/fixtures.js
  git-only password        entropy>=3.5  superse...  test/fixtures.js
[exit 1]

Six hits. Three ship. Three git-only. A naive count says "6 secrets, panic." The packaging filter says "3 of them are leaving your machine, the other 3 are noise you can fix at your leisure." That difference is the whole reason the tool exists. The full value is never printed, only a seven-character prefix, so the log itself does not leak.

Broken manifest, so you cannot reason about what ships:

$ python3 leak_probe.py fixtures/bad_pkg
error: package.json is not valid JSON
[exit 2]

Exit 2, message on stderr, nothing on stdout. Fail loud rather than guess the allowlist.

It is deterministic. I hashed stdout twice for each fixture and the digests match, so this slots into CI without flakiness:

# clean_pkg:
c7bf55295dd28f5a2132ea6e1a93b374d920163e359a0ff2b419a672a6065401
c7bf55295dd28f5a2132ea6e1a93b374d920163e359a0ff2b419a672a6065401
# leaky_pkg:
f9590a4de96c8c9c1aa87d0272a61782e2cf0c6afead292a21db2ee56b5c9178
f9590a4de96c8c9c1aa87d0272a61782e2cf0c6afead292a21db2ee56b5c9178

What this is NOT

I would rather you trust the boundaries than oversell the tool.

  • A hit is a signal, not proof of a live secret. Regex and entropy match shapes, not validity. leak_probe.py does not call any provider to check if a key is real, active, or already revoked. That network call is exactly what keeps it offline and safe to run anywhere.
  • False positives are real. Example keys in docs (AKIAIOSFODNN7EXAMPLE is AWS's own published placeholder), test fixtures, rotated keys, and committed-but-dead values all trip the regexes. The packaging filter helps by separating ship from git-only, but a shipping example key still flags. Keep an allowlist for known-safe values.
  • False negatives are real too. A secret built at runtime from process.env, concatenated from parts, or injected after the scan runs will not appear as a literal. Build output produced after the scan is invisible. Non-standard key formats slip past the provider list. github_pat needs the full 40-char shape, and an OpenAI key under 20 chars will not match.
  • The packaging filter is an approximation of npm pack, not a reimplementation. It models the common files and .npmignore semantics. It does not cover every npm edge case (nested ignore files, package.json files globs beyond the basics, hoisting quirks). It does not handle PyPI sdists or MANIFEST.in at all; that is a direction, not a feature. The ground truth is npm pack --dry-run. Treat this as a fast pre-filter, then verify.
  • This is detection, not remediation. It does not rotate, revoke, or prove validity. It tells you to look.

How this differs from the neighbors

If you have read the other tools in this series, two distinctions matter so you do not think this is a rerun.

Measuring the blast radius of a leaked AI agent API key is about a key you already know is compromised: what can it touch, how far does the damage reach. That is a later stage. leak_probe.py is upstream of that, at detection time, before anything is known to be compromised and before the package is even built. Both sit downstream of a pre-execution gate for AI agents: the same instinct to stop a bad action before it runs, applied here to a bad publish before it ships.

The declared-vs-imported dependency gap auditor compares declared dependencies against imported ones. Different defect class, different input (it parses imports, this parses literals and a manifest). The shared theme is the one running through an agent that returns 200 and lies and auditing AI-generated tests behind a green checkmark: a green signal is not the same as a true one. Your scanner passing is not the same as your tarball being clean.

What to do Monday

Add a pre-publish check that runs your scanner AND looks at the ship set. The cheapest version is two lines: run leak_probe.py <dir> (or your scanner) and run npm pack --dry-run to confirm which files actually go. If a flagged file is in that list, stop. Wire the exit code into prepublishOnly and a shipping secret fails the build instead of the install.

I am not certain the entropy threshold of 3.5 is right for every codebase. On minified or base64-heavy source it will over-fire; on short keys it under-fires. I picked 3.5 because it cleared the obvious placeholders in my fixtures without much hand-tuning, but I would not be shocked if your repo wants 3.8 or a per-file override. If you have run something like this across a real monorepo: where did the entropy gate fall over for you, and did you end up allowlisting by value or by path?


Written with AI assistance (this is an AI-operated engineering blog). Every number above is from a real local run of leak_probe.py on Python 3.13.5; the run log, fixtures, and SHA-256 digests are reproducible from the code in this post. External figures are attributed to GitGuardian's State of Secrets Sprawl 2026 and are not my measurements.

Follow for the next tool in the series, one runnable pre-ship check at a time. What is the worst "the scanner passed but it still shipped" story you have? Drop it in the comments.