We have a page for sign-in links that did not work. It reads a reason from the query string and shows a matching explanation: an expired email link gets "Link expired" and a button back to sign up; a used or invalid one gets "Access denied" and a button to sign in; anything else gets a generic "Something went wrong".

The lookup is the shape every one of us has written:

const reasons: Record<string, { title: string; description: string; action: ReactNode }> = { otp_expired: { ... }, access_denied: { ... }, }; const content = (reason && reasons[reason]) || fallback; 

It reads well and it has a bug that no type checker will find.

What an object literal contains

reasons has two keys you wrote. It also has every property of Object.prototype, because a literal inherits from it: constructor, toString, hasOwnProperty, valueOf, and __proto__. reasons['constructor'] is not undefined. It is a function, which is truthy, so reasons[reason] || fallback takes the left side and content becomes Object.

Then the page reads content.title, content.description and content.action off a function. All three are undefined. React renders nothing for each, and the card is drawn around the gap.

See it

Open the page with a real reason, ?reason=otp_expired, and you get the title, the explanation and the button. Open it with an unknown word, ?reason=nope, and the fallback appears as intended. Now open ?reason=constructor. The response is a normal 200 and the card has the logo, the red icon, no heading, no sentence, and a single "Sign in instead" button, because the primary action was the other undefined.

I checked four names against the live page: constructor, __proto__, toString and hasOwnProperty. All four give the empty card. Nothing is exposed and nothing breaks, since the page only reads three fields, and no visitor will arrive here by accident. It is a bug you can only reach by typing it, which is exactly why a lookup like this survives review.

The fixes, smallest first

// 1. Only own keys count const content = (reason && Object.hasOwn(reasons, reason) ? reasons[reason] : null) ?? fallback; // 2. A Map has no inherited keys const reasons = new Map([['otp_expired', {...}], ['access_denied', {...}]]); const content = reasons.get(reason ?? '') ?? fallback; // 3. An object with no prototype const reasons = Object.assign(Object.create(null), { otp_expired: {...} }); 

Object.hasOwn is the one I would use for a change this small. It needs no new data structure and says what you meant. A Map is the better choice when the keys come from a user in more than one place.

Our own code already knows this. A different file in the same repository, for school email domains, guards its dictionary lookup with Object.hasOwn(index, candidate). It was written for a lookup keyed on email addresses, where the input is plainly hostile. The error page's input looked like a fixed vocabulary, because the only code that links to it is ours, so nobody treated it as untrusted. A query string is always untrusted, whoever wrote the link.

The wider habit

Any time a string from outside indexes into an object, ask what keys the object has besides the ones you typed. The usual places are error-code tables, feature-flag maps, translation dictionaries and route tables. Searching for Record<string, in code that reads searchParams finds most of them in a minute.

CogniPrep is a practice site for employer assessments. If you want a page that does not look anything up from the address bar, the pricing page and the homepage are both ordinary.