checkValidity() returned false. My calculator answered anyway.
The concrete mix calculator on my site has a field called sand. Its input carries min="20" max="55", default 38. I set it to 1000000 in the console, dispatched input, and asked the browser what it thought: document.qu
The concrete mix calculator on my site has a field called sand. Its input carries min="20" max="55", default 38. I set it to 1000000 in the console, dispatched input, and asked the browser what it thought:
document.querySelector('#f_sand').checkValidity(); // false
The browser was clear. The value is out of range. It says so, and every form API treats the page as unsubmittable.
The table below the input updated anyway:
Cement content 474585 kg/m³
Water 250176 kg/m³
Sand -7223614292 kg/m³
Gravel 7222891931 kg/m³
Ratio cement:sand:gravel 1 : -15220.90 : 15219.38
Negative seven billion kilograms of sand per cubic metre. Rendered in the same typeface as a correct answer, under a heading that says "Sand".
I have 234 of these calculators, and some are used by people who price concrete for a living. So I swept all of them to find out how many answer a question the browser has already refused.
The bounds live in the wrong object
Each page ships a window.CALC block: a field list, and a compute function that takes one argument:
compute: function (v) {
var mw = 195 + (v.slump - 75) / 20 * 5;
var mc = mw / wc;
var agg = 2400 - mw - mc;
var ms = agg * v.sand / 100; // ← this is what went negative
...
}
v is a plain object of numbers, and it doesn't contain the bounds — they aren't in the CALC block at all. The template writes them as attributes on the <input> elements.
I parsed all 245 English pages: 1,085 number fields, and not one carries a min or max in the object compute receives. The same pages emit 355 max attributes into the markup.
The arithmetic has no access to the constraint. A compute that wanted to refuse would have nothing to refuse against. The only code that touches both is the reader:
var raw = String(el.value).replace(/\s/g, '').replace(',', '.');
var n = parseFloat(raw);
if (raw === '' || !isFinite(n)) { bad = true; n = 0; }
v[f.id] = n * uFactor(f.id);
It checks for empty and non-finite. It never asks el.validity, never compares to min/max, never consults f. The attribute and the function are two strangers sharing a page.
Of the 1,080 number fields in the sweep, 728 declare no upper bound at all — a floor of 0 and nothing else. For those, a million metres of excavation depth is inside the declared domain. The page never said it wasn't.
Which is how a 10 × 6 m pit produced this:
Cut volume 145205280060000000.0 m³
Cut (bank) 145205280060000000.0 m³
Backfill (compacted) 145205280059999968.0 m³
Bank soil needed (0.90 compaction) 161339200066666624.0 m³
Spoil off-site (bank) 0.0 m³
Two rows describing the same volume, 32 m³ apart. That is not a rounding bug — at 1.45 × 10^17, the float64 spacing is exactly 32 (the value sits just above 2^57, where the ULP is 2^(57−52)). The arithmetic is doing precisely what it was told. The input was never checked, so the scale was never sane, and the last digit is now noise.
Three checks that look right and aren't
The finite check. I added a guard in November that converts NaN and Infinity to an em dash and appends "N lines can't be worked out because an input is 0." Run over the sweep's output, it caught 127 of the 129 non-finite values. (The two it misses are composite strings like 1 : NaN — the regex is anchored, so NaN embedded in a ratio slips through.)
But it only catches failures that announce themselves. A negative mass is finite. Zero is finite. 145205280060000000.0 is finite. Of the 239 flags that came from legal inputs, 207 survive that guard and are printed as answers. The one failure mode I handled was the loudest and the least dangerous.
The quiet one: brick-count computes wall area as Math.max(0, len * hgt - open). Set openings to 1,000,000 m² on a 10 × 3 m wall and it clamps to zero — then every downstream row follows it down:
Bricks required (incl. waste) 0 blocks
Wall area 0.00 m²
Cement (32.5) 0 kg
No warning, because nothing is NaN. A wall of zero bricks is a syntactically perfect answer to a nonsense question, and it will get copied into a quote.
The sign check. 191 of my flags were negative numbers, which felt like a clean rule until I looked at what they were attached to. unit-temperature converting from Kelvin reports −253.15 °C. That is correct. 124 of the 191 sit on units where negative is meaningful — degrees, percentages, deltas, strength deficits. A sign rule has to be per-unit, and then it is no longer a one-line check.
The magnitude check. I originally flagged anything above 1e12, a number I picked because it was big. It catches the 88 numbers above 1e12 and is blind to the interesting cases: an answer of 300 when the truth is 300,000 passes any threshold chosen without data.
All three share a deeper problem: none of them asks the only question that matters. Is this number possible for this unit?
The check that needed no theory
Every calculator has a default state a human chose. That is a sample, and 234 is enough to bootstrap a ceiling per unit: run every page at defaults, bucket the printed numbers by unit, take p95, multiply by 100.
| Unit | p95 at defaults | Ceiling |
|---|---|---|
| m³ | 971 | 97,100 |
| kg | 14,060 | 1,406,000 |
| m² | 1,680 | 168,000 |
| kg/m³ | 1,212 | 121,200 |
| 元 (CNY) | 600,000 | 60,000,000 |
Money gets its own multiplier, or none — a 100× band is a defensible claim about a volume and a silly one about an invoice.
Then any finite number above its unit's ceiling, or below zero on a unit that cannot be negative, is not an answer:
const CEIL = { 'm³': 97100, 'kg': 1406000, 'm²': 168000, 'kg/m³': 121200 };
const SIGNED = new Set(['°C', '°F', '%', 'MPa', 'kPa', '']); // negative is a real value here
function verdict(value, unit) {
const n = Number(String(value).replace(/,/g, ''));
if (!isFinite(n)) return 'nan';
const cap = CEIL[unit];
if (cap !== undefined && Math.abs(n) > cap) return 'over';
if (!SIGNED.has(unit) && n < 0) return 'negative';
return 'ok';
}
On the same 5,405 cases this flagged 2,049 numbers — 4.4× what the domain rule found, and it never needed to know whether the input was legal. That is the whole point: it works on the 728 fields that have no ceiling to compare against.
A rule that fires on working pages is worse than no rule, so I ran it against every default state. Mine fired once: pump-head printing 70,314 in a row with no unit. The empty-string bucket mixes counts, ratios and money, so I now skip it. One flag on 234 working pages is the price of a rule that catches 2,049 numbers no page could plausibly produce; zero would have meant the ceiling was too loose.
Reproducing it
The sweep took 206 ms for 5,405 cases: compute is pure and the pages are static.
- Extract
window.CALCfrom each page — thefieldsarray, and thecomputesource. Pullmin/maxfrom the modules that generate the template, not from the DOM. - For every number field, inject four values: the declared minimum,
1e6,0,-5. For every select, walk its options. - Run it in Node, no browser:
const fn = new Function('"use strict";' + spec.compute + '\nreturn compute;')();
const out = fn(values);
- Classify every printed number, then split the flags by one question: was the injected value inside the page's own declared domain?
That split is the part I got wrong first: my raw sweep found 465 flags and I nearly published all of them. Then I checked legality: 226 of the 465 came from inputs the page never claimed to accept. Feeding -5 into a field with min="500" and getting NaN is not a bug in the site, it is a bug in my fuzzer. Throw those away. The 239 that remain, spread over 74 pages, are the ones where the page said "this is fine" and then produced something impossible.
What I'd tell you to check on your own site
- If a limit exists only as an attribute, treat it as absent. Grep your compute layer for the string
min— if it is zero occurrences, your bound is a comment. - Add the bound to the object the function receives, and have the wrapper refuse before the arithmetic starts. A function that can be called with impossible arguments eventually will be.
- Validate the output against the unit, not the input.
Math.maxturning a contradiction into a zero is the failure that reaches production, because zero looks like a result. - Before you trust a fuzzer, count how many of its findings come from inputs your spec rejects. Mine was 48%.
The pages in this post are live — the concrete mix calculator is the page from the opening. Set Sand to 1000000 and watch checkValidity() go false while the table keeps talking.
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.