Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass options from interceptor to parseRequest #55

Merged
merged 1 commit into from
Oct 25, 2021

Conversation

swift-nicholas
Copy link
Contributor

Issue

By default the parseRequest method called from @sentry/node package passes an empty object for parsing the express request.

This leads to in my case the user object not being parsed currectly from the request because of the following:

Referring to the code in https://github.com/getsentry/sentry-javascript/blob/master/packages/node/src/handlers.ts#L338

User by default is true so it will try and pull the keys from the object.

  if (options.user) {
    const extractedUser = req.user && isPlainObject(req.user) ? extractUserData(req.user, options.user) : {};

    if (Object.keys(extractedUser)) {
      event.user = {
        ...event.user,
        ...extractedUser,
      };
    }
  }

In extractUserData https://github.com/getsentry/sentry-javascript/blob/d3ca7a897263141e9f0821e8be2a8cb617638d4d/packages/node/src/handlers.ts#L167

If no keys are provided the following will be parsed.

const DEFAULT_USER_KEYS = ['id', 'username', 'email'];

In most jwt applications additional keys are povided and used.

Resolution

To fix this I pass SentryInterceptorOptions to @sentry/node parseRequest to allow the ability to provide user object keys outside of the default keys array.

Like so:

const data = Handlers.parseRequest(<any>{},http.getRequest(), this.options);

Example

This allows for the following implementation.

app.useGlobalInterceptors(new SentryInterceptor({
    user: [
      'iss',
      'sub',
      'aud',
      'iat',
      'exp',
      'azp',
      'scope',
      '<some other claim>',
  ]
  }))

Pass SentryInterceptorOptions to @sentry/node parseRequest to allow the ability to provide user object keys outside of the default keys array.
@ntegral ntegral merged commit 9aed2a1 into ntegral:master Oct 25, 2021
@ntegral
Copy link
Owner

ntegral commented Oct 25, 2021

Thanks @swift-nicholas

@swift-nicholas
Copy link
Contributor Author

@ntegral No problem, thanks for merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants