This gate uses a local score to choose PoW difficulty rather than rejecting directly on score. Solving still costs time, energy and device resources. Provide cancellation, timeout and alternatives for slow devices and accessibility needs.
1. Work out what that manual step was actually deciding
In the original flow, a reader submits a mailbox request and an administrator approves it. That action contains two decisions:
- Whether to create the mailbox — defending against automated bulk registration;
- Whether to grant outbound sending (
send_allowed, default0).
Mailbox creation consumes quota, storage and operations work; outbound mail can also affect domain reputation and other users. This design separates those authorisations.
So the automation covers only the first. Passing the proof of work sets the request to approved with a default quota, while send_allowed stays at 0 and is still granted separately from the back end.
Outbound sending deliberately remains under manual approval. When a manual step bundles several decisions, split them, examine the worst consequence of each, and choose which to automate. Automating a decision that needs manual handling adds risk.
2. Hash vectors and payload agreement
crypto.subtle.digest returns a Promise, with per-call scheduling overhead and device-dependent throughput. This example uses synchronous SHA-256 in a Worker. Vetted WASM or batched implementations are alternatives; hand-written hashing is not mandatory for PoW.
A hash bug may disagree only on certain lengths or inputs without throwing. Record input bytes, digests, encoding and verification results to localise mismatches.
So this implementation cannot be accepted on the grounds that it runs. It has to be checked against vectors. The worker source is extracted from the JS and run standalone under node:
- The original 21 digest vectors include 55/56/63/64/65 bytes. A 55-byte input plus 0x80 and the eight-byte length fits one block; 56 bytes requires another. These are important boundaries, without a measured claim about where most bugs occur.
- 400 leading-zero-bit cases to check the difficulty predicate. Counting leading zero bits is unusually easy to get wrong across byte boundaries.
- The original mines in Node and checks Node crypto against the PHP payload convention. This checks core hashing and encoding; the PHP endpoint and authenticated request flow need separate tests.
Digest vectors, zero-bit predicates and payload comparisons cover different parts. Finite tests detect errors in their cases rather than proving every input correct. Also check the actual server path and failure handling.
3. Set difficulty using wait distributions
Under approximately independent uniform digests, difficulty d gives success probability 2^-d per candidate and geometric attempts with mean 2^d. The original rate record follows; the browser 40–60% figure is a Node-based estimate without a recorded browser/device benchmark.
node, single thread ~720,000 hashes/sec
browser worker 40-60% of that (~350,000/sec)
At an estimated 350,000 hashes/s, the table’s 0.4,6 and 24 seconds are means, not maxima. At 21 bits, the 95th percentile is about 18 seconds and the 99th about 28 seconds; slower devices take longer:
| Difficulty | Expected attempts | In-browser time | How it feels |
|---|---|---|---|
| 17 bits | 131k | ~0.4 s | imperceptible |
| 21 bits | 2.1M | ~6 s | clearly waiting, but acceptable |
| 8.4M | ~24 s | my original ceiling; far too long |
The original ceiling changed from 23 to 21 bits. Measure means, tail waits and cancellation on target devices. A single 0.05-second solve can simply find a valid candidate early.
Difficulty affects both user and attacker costs, so it is a security and experience parameter. Use target-device wait quantiles, attacker computation, service costs and alternative access paths to choose a ceiling.
4. IP scoring: only signals the site can observe itself
Difficulty comes from a local reputation score built only from what this site can see on its own:
| Signal | Points |
|---|---|
| Reverse DNS matches hosting-provider keywords | +30 |
| No PTR record | +5 |
| Recent failures | +10 each (cap 30) |
| Repeated solves in a short window | +8 each (cap 25) |
| New / young account | +15 / +8 |
| Missing or obviously automated user agent | +20 |
This design excludes three sources of signals:
- This design avoids external reputation APIs to reduce address disclosure; document other flows such as reverse DNS.
- This design uses locally explainable signals instead of third-party lists; other systems can assess source quality and appeal processes.
- This design assigns no country weight. Geography is not direct evidence of individual abuse; no comparative correlation data are supplied here.
Counter keys use HMAC(IP,salt), a linkable pseudonym. This does not establish anonymous operation or absence of raw IPs elsewhere; inspect logs, reverse DNS and other features separately and protect the HMAC key.
5. The score sets a price, never a verdict
The design requires that no score causes a rejection. A high score only means a harder puzzle.
Shared egress, CGNAT, age and UA can score normal users highly. The weights are implementation policy, with false positives requiring labelled examples and observed complaints to assess.
Higher difficulty avoids direct score-based rejection, but long waits, limited devices and expired challenges can still cause failure. Compare false positives, completion and wait distributions.
Compare heuristic delays, quotas and manual review as policy choices. Security and resource boundaries may also require explicit rejection.
6. Two kinds of puzzle must not be interchangeable
Two entry points on the site use this gate: the mailbox request, and a public IP reputation lookup tool. Their puzzles are not interchangeable — the challenge payload carries a purpose field compared verbatim at verification.
Without that, an attacker farms puzzles at the cheapest entry point (the public tool, low difficulty) and spends them at the most sensitive one (the mailbox request). The cheapest entry point ends up pricing the most sensitive one.
Sign purpose, difficulty, randomness and expiry into the challenge. Atomically check and commit successful use. The current get_transient/set_transient sequence is not atomic, so a sequential replay rejection does not establish concurrent replay protection. Limit issuance load too.
7. Access controls for the diagnostic endpoint
The site’s IP reputation tool tells you the score assigned to your current address and the weight of every signal that contributed. That disclosure is intentional — the gate’s security does not rest on keeping the signals secret.
The diagnostic endpoint consumes resources and reveals policy. PoW, rate limiting or other controls can price that access. PoW raises enumeration cost without guaranteeing that proxy pools cannot enumerate or mimic low-score signals.
This is easy to miss: a diagnostic tool that exposes your abuse-control criteria is itself part of your abuse control.
8. What was measured, and what was not
Measured:
curl user agent score 20
browser user agent score 0
fetch 17-bit puzzle -> solve 0.05s -> submit returns 200
replay the same puzzle 403 already_used
The original authenticated mailbox-request end-to-end test remains NOT_RUN. The 200 and already_used observations below concern the public tool path; they do not validate mailbox creation, quota, sending permissions or concurrent consumption.
References
- RFC 6234: SHA-256 specification and test vectors
- Back (2002), Hashcash — A Denial of Service Counter-Measure
- MDN: SubtleCrypto.digest (and why it is asynchronous)
Related: the IP reputation scorer (the tool described above), threat modelling for AI systems, and an auth gate covers paths, not data (another case of a control that looked like it was blocking something and was not).
