agentleFS
randommoniclerandommonicle/claude-skills/constant-time-secret-compare/SKILL.md

constant-time-secret-compare

Skill27 starsChanged 19 days agoApache-2.0View on GitHub

Compare bearer tokens, API secrets, signatures, and password-equivalents with a constant-time comparison (hash both sides, then crypto.timingSafeEqual) — never == or short-circuiting string equality. Triggers when writing any code that checks a secret against a stored or expected value. Does not fire on comparing non-secret identifiers.

The file

Files
SKILL.md

Constant-time secret compare

String equality short-circuits on the first differing byte, so token == expected leaks how many leading bytes matched through response timing — an oracle an attacker can walk.

The rule

Hash both sides to fixed length, then compare constant-time:

import { createHash, timingSafeEqual } from 'node:crypto';
const h = (s) => createHash('sha256').update(s).digest();
const ok = timingSafeEqual(h(provided), h(expected));

Hashing first makes the buffers equal-length (timingSafeEqual throws on length mismatch — itself a leak) and keeps the comparison constant-time regardless of input size. Apply to bearer tokens, admin tokens, webhook signatures, and any password-equivalent. HMAC verification uses the same pattern on the computed and received MACs.

Why

It costs two lines and removes a whole attack class; equality comparison on secrets is the kind of defect that passes every functional test forever. Evidence: ICC CLAUDE.md known-issues (admin token compare, shipped fix).

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.