Skip to content

Commit

Permalink
fix(server): Oauth callback crash due to query (#3277)
Browse files Browse the repository at this point in the history
<!-- Describe the problem and your solution --> 
This is more a hotfix. NAN-2491 is for followup but it's going to take
some time to do right.

We saw a crash last night around /oauth/callback. I was able to
reproduce with this request:

```
curl --request GET --url "https://api-staging.nango.dev/oauth/callback?state=m0626jB2-Mm63-78AR-y5pl-9639066q4c26"
```

This wraps the query that's crashing with a try catch so that we at
least get a response. It's a quick and dirty fix that will hopefully get
a followup of moving that controller to use asyncWrapper.

<!-- Issue ticket number and link (if applicable) -->

<!-- Testing instructions (skip if just adding/editing providers) -->

Before:

```
❯ curl --request GET --url "http://localhost:3003/oauth/callback?state=m0626jB2-Mm63-78AR-y5pl-9639066q4c26"
curl: (52) Empty reply from server
```

After:

```
❯ curl --request GET --url "http://localhost:3003/oauth/callback?state=m0626jB2-Mm63-78AR-y5pl-9639066q4c26"
{"error":{"message":"An unhandled error of type 'query_error' with payload '{}' has occurred","code":"unhandled_query_error","payload":{}}}%
```
  • Loading branch information
nalanj authored Jan 9, 2025
1 parent bf7cad7 commit fe5f37f
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/server/lib/controllers/oauth.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -829,7 +829,14 @@ class OAuthController {
return;
}

const session = await oAuthSessionService.findById(state as string);
let session;
try {
session = await oAuthSessionService.findById(state as string);
} catch (err) {
errorManager.report(err, { source: ErrorSourceEnum.PLATFORM, operation: LogActionEnum.AUTH });
errorManager.errRes(res, 'invalid_oauth_state');
return;
}

if (session == null) {
const e = new Error(`No session found for state: ${JSON.stringify(state)}`);
Expand Down

0 comments on commit fe5f37f

Please sign in to comment.