You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on May 26, 2022. It is now read-only.
There are actually 2 bugs in just these 4 lines of code, whereby we may attempt to access the fields of an intermediate undefined object.
First, let's say that the initial !req evaluates to true. Because the initial logic is now adjoined with (!req.cookies && !req.cookies.token)) we will now attempt to evaluate !req.cookies, but req is undefined, and we blow up.
Second, the same logic applies within (!req.cookies && !req.cookies.token) itself, if req.cookies is undefined: !req.cookies evaluates to true, so we attempt to execute !req.cookies.token, and again blow up trying to access a property on an undefined object.
Because these are inside an if statement and not a try/catch, these cases will propagate to the GraphQL error response, which I assume is not the intent.
In the first case, one might argue that a missing req is violating the package's API, and thus no guarantees are provided / blowing up is fine. I'd tend to disagree, favoring the friendlier developer ergonomics of catching such cases and providing a useful error message.
In the second case, it's perfectly reasonable to not have a req.cookies object. In fact this is the default in express, absent a cookie-parsing middleware, which is how I ran into this issue when trying to upgrade.
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Looking at the code published in 2.2.0, I noticed a few issues.
The previous header retrieval logic took advantage of short-circuiting to avoid issues of attempting to access properties of an
undefined
object:At each stage of this predicate, the
||
ensures we're not attempting to access fields of anundefined
object.But as of 2.2.0:
There are actually 2 bugs in just these 4 lines of code, whereby we may attempt to access the fields of an intermediate
undefined
object.First, let's say that the initial
!req
evaluates totrue
. Because the initial logic is now adjoined with(!req.cookies && !req.cookies.token))
we will now attempt to evaluate!req.cookies
, butreq
isundefined
, and we blow up.Second, the same logic applies within
(!req.cookies && !req.cookies.token)
itself, ifreq.cookies
isundefined
:!req.cookies
evaluates totrue
, so we attempt to execute!req.cookies.token
, and again blow up trying to access a property on an undefined object.Because these are inside an
if
statement and not atry
/catch
, these cases will propagate to the GraphQL error response, which I assume is not the intent.In the first case, one might argue that a missing
req
is violating the package's API, and thus no guarantees are provided / blowing up is fine. I'd tend to disagree, favoring the friendlier developer ergonomics of catching such cases and providing a useful error message.In the second case, it's perfectly reasonable to not have a
req.cookies
object. In fact this is the default inexpress
, absent a cookie-parsing middleware, which is how I ran into this issue when trying to upgrade.The text was updated successfully, but these errors were encountered: