Skip to content

API: invalid deviceId filter on webhook notifications returns 500 instead of 400 #276

Description

@vernu

GET /webhooks/notifications?deviceId=<anything invalid> returns a 500.

In findWebhookNotificationsForUser the deviceId filter is cast without a validity check (webhook.service.ts, ~line 219):

if (deviceId) {
  commonPipeline.push({
    $match: {
      'deviceData._id': new mongoose.Types.ObjectId(deviceId),
    },
  })
}

new ObjectId('abc') throws a BSONError, which bubbles up as an internal server error.

The sibling webhookSubscriptionId param in the same function already does it right (~line 98):

if (!mongoose.Types.ObjectId.isValid(webhookSubscriptionId)) {
  throw new HttpException('Invalid webhookSubscriptionId', HttpStatus.BAD_REQUEST)
}

Same check for deviceId, same 400 response.

Metadata

Metadata

Assignees

No one assigned

    Labels

    apiBackend APIbugSomething isn't workinggood first issueGood for newcomers

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions