From 0ac087b82aedb247b44c5bbb1b4e268683368d3a Mon Sep 17 00:00:00 2001 From: jbloxham Date: Tue, 24 Sep 2019 15:44:51 -0700 Subject: [PATCH 1/2] Extract prototyped data in `extractUserData` I have a slightly unusual express server setup in which the client provides their user ID in the `req.user` field, then a middleware replaces this with the corresponding user entry from a database, thus populating `req.user.email` and `req.user.id`. Unfortunately, it turns out that sentry is unable to extract these fields automatically, because they are defined in the prototype of the `req.user` object, and thus are ignored by `hasOwnProperty`. Changing this to a simple `in` operator fixes this issue. I don't see a good reason why `hasOwnProperty` should be preferred to `in` here, as the extracted fields are configurable anyways. --- packages/node/src/handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 706149d528d7..8c1b76a55859 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -143,7 +143,7 @@ function extractUserData(req: { [key: string]: any }, keys: boolean | string[]): const attributes = Array.isArray(keys) ? keys : DEFAULT_USER_KEYS; attributes.forEach(key => { - if ({}.hasOwnProperty.call(req.user, key)) { + if (key in req.user)) { user[key] = (req.user as { [key: string]: string })[key]; } }); From 33dbd03359ced3474e23efd185b085b2e961799a Mon Sep 17 00:00:00 2001 From: jbloxham Date: Tue, 24 Sep 2019 16:18:05 -0700 Subject: [PATCH 2/2] typo --- packages/node/src/handlers.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/node/src/handlers.ts b/packages/node/src/handlers.ts index 8c1b76a55859..b1c72ef3c422 100644 --- a/packages/node/src/handlers.ts +++ b/packages/node/src/handlers.ts @@ -143,7 +143,7 @@ function extractUserData(req: { [key: string]: any }, keys: boolean | string[]): const attributes = Array.isArray(keys) ? keys : DEFAULT_USER_KEYS; attributes.forEach(key => { - if (key in req.user)) { + if (key in req.user) { user[key] = (req.user as { [key: string]: string })[key]; } });