Our auth error page looks its message up in an object literal, so ?reason=constructor renders a card with no title
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 <…
The error page for sign-in links reads a reason from the query string and displays a corresponding explanation. If the reason is unknown, it shows a generic "Something went wrong" message. The page's reason-checking logic is written as a lookup in an object literal, which inherits properties from Object.prototype. This includes keys like constructor, toString, hasOwnProperty, valueOf, and __proto__.
As a result, an unknown reason like "constructor" renders a card with only the logo and a "Sign in instead" button, because the primary action of the object is undefined.
This bug slipped through review because the lookup only reads three fields of the object, and an untrusted query string is highly unlikely to appear by accident. A safer approach would be to only count own keys in the object, use a Map instead of an object literal, or create an object with no prototype. These changes would prevent the lookup from reading inherited keys and ensure the page displays the intended content.
Rewritten by urgent.news; may contain errors — check the original.
Source: dev.to