Invental/Review lessons/Trust boundaries the server must hold

Trust boundaries the server must hold

User-chosen keys need a null-prototype object

Any object keyed by user input (URLs, names, ids) and loaded from JSON can be prototype-polluted: build it on Object.create(null) or use a Map.

01 · Before and afterThe pattern

TypeScript
// before: store[url][profile] = token  (url or profile may be "__proto__")
const raw = JSON.parse(text);
const store: Record<string, Record<string, string>> = Object.create(null);
for (const [url, profiles] of Object.entries(raw)) {
  store[url] = Object.assign(Object.create(null), profiles);
}
// or simply: new Map<string, Map<string, string>>()

02 · Run it on your appThe check

Does your CLI or service store anything in a plain object whose keys come from users, and have you tried the key __proto__?

If the honest answer is no or not sure, this is worth a look before it reaches production.

Want this checked on your code?

Tell us what you are building and what worries you. We match a senior reviewer to your code and confirm scope before anything starts.

— Get in touch
hi@invental.co ↗
— Or
— What to include

A link or short description of the code or system, what you want checked, your stack, and when you need the answer. No repository access is needed until scope is agreed.

— Or leave a note
We reply within one business day.