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

feat(webhooks): send end user on connection creation #3065

Merged
merged 4 commits into from
Nov 27, 2024

Conversation

bodinsamuel
Copy link
Collaborator

@bodinsamuel bodinsamuel commented Nov 26, 2024

🤓☝️ Changes

Fixes https://linear.app/nango/issue/NAN-1880/send-back-the-end-user-profile-in-the-webhook

  • Send endUser in webhook on connection creation
    When we use a session token, we pass metadata, but when we receive a webhook, we get a random connectionId that is impossible to link to an actual user. Sending back the userId (or orgId) will allow customers to link this connectionId to an actual user without needing to do any additional work.

NB: we don't send it in any other webhook since the connectionId should have been linked already

🧪 How to tests?

  • Go to dashboard
  • Modify webhook url to your favorite webhook dumper
  • Allow webhook to be sent on connection creation
  • Create a new connection with the connect UI

Screenshot 2024-11-26 at 17 32 59

@bodinsamuel bodinsamuel self-assigned this Nov 26, 2024
Copy link

gitguardian bot commented Nov 26, 2024

⚠️ GitGuardian has uncovered 1 secret following the scan of your pull request.

Please consider investigating the findings and remediating the incidents. Failure to do so may lead to compromising the associated services or software components.

🔎 Detected hardcoded secret in your pull request
GitGuardian id GitGuardian status Secret Commit Filename
8205899 Triggered Generic Password 533ea50 packages/database/lib/getDbConfig.ts View secret
🛠 Guidelines to remediate hardcoded secrets
  1. Understand the implications of revoking this secret by investigating where it is used in your code.
  2. Replace and store your secret safely. Learn here the best practices.
  3. Revoke and rotate this secret.
  4. If possible, rewrite git history. Rewriting git history is not a trivial act. You might completely break other contributing developers' workflow and you risk accidentally deleting legitimate data.

To avoid such incidents in the future consider


🦉 GitGuardian detects secrets in your source code to help developers and security teams secure the modern development process. You are seeing this because you or someone else with access to this repository has authorized GitGuardian to scan your pull request.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably a leftover

// account?: DBTeam;
// environment?: DBEnvironment;
// user: Pick<DBUser, 'id' | 'email' | 'name'>;
// };
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tried to fix this type but opened a trap door (unfortunately I have wrote this type so I can only blame myself)
Will fix later

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow but I trust you

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This type is too loose meaning we can have connectSession with auth mode basic, which could lead to mistakes. Ideally, we have something stricter but when I wrote it I didn't anticipate this issue and now it seems some middleware does not enjoy the strictness when I tried to change it

@@ -98,7 +98,8 @@ async function handleCreateWebhook(integration: ProviderConfig, body: any, logCo
environment,
account,
auth_mode: 'APP',
operation: res.operation
operation: res.operation,
endUser: undefined // TODO fix this
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Github App webhook routing is weird, but it's an edge case

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

left over

Copy link

linear bot commented Nov 26, 2024

@bodinsamuel bodinsamuel requested a review from a team November 26, 2024 16:41
Copy link
Contributor

@nalanj nalanj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@@ -156,7 +157,8 @@ class ApiAuthController {
environment,
account,
auth_mode: 'API_KEY',
operation: updatedConnection.operation
operation: updatedConnection.operation,
endUser: isConnectSession ? res.locals['endUser'] : undefined
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why not directly res.locals['endUser']? is it not undefined if not isConnectSession?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true, I think I like the explicitness here and if (big if) I manage to fix the locals types endUser will be never in most case.

const { providerConfigKey } = req.params;
const receivedConnectionId = req.query['connection_id'] as string | undefined;
const connectionConfig = req.query['params'] != null ? getConnectionConfig(req.query['params']) : {};
const isConnectSession = res.locals['authType'] === 'connectSession';
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isConnectSession could almost be an attribute of RequestLocals

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe indeed

// account?: DBTeam;
// environment?: DBEnvironment;
// user: Pick<DBUser, 'id' | 'email' | 'name'>;
// };
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not sure I follow but I trust you

@bodinsamuel bodinsamuel enabled auto-merge (squash) November 27, 2024 09:18
@bodinsamuel bodinsamuel merged commit bd85a0d into master Nov 27, 2024
19 of 20 checks passed
@bodinsamuel bodinsamuel deleted the sam/24_11_26/fix/enduser-webhooks branch November 27, 2024 09:25
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.

3 participants