Security - add throttle in message resend#16070
Conversation
Greptile OverviewGreptile SummaryAdded rate limiting to workspace invitation resending to prevent abuse, but critically missed adding the same throttling to the main
Confidence Score: 1/5
Important Files ChangedFile Analysis
Sequence DiagramsequenceDiagram
participant Client
participant Resolver as WorkspaceInvitationResolver
participant Service as WorkspaceInvitationService
participant Throttler as ThrottlerService
participant Cache as CacheStorage
participant DB as AppTokenRepository
participant Email as EmailService
Note over Client,Email: resendWorkspaceInvitation Flow (WITH throttling)
Client->>Resolver: resendWorkspaceInvitation(appTokenId)
Resolver->>Service: resendWorkspaceInvitation(appTokenId, workspace, sender)
Service->>Throttler: throttleInvitationSending(workspaceId)
Throttler->>Cache: get token bucket state
Cache-->>Throttler: {tokens, lastRefillAt}
alt Rate limit exceeded
Throttler-->>Service: throw ThrottlerException
Service-->>Resolver: throw WorkspaceInvitationException
Resolver-->>Client: Error: Too many invitations sent
else Rate limit ok
Throttler->>Cache: update token bucket
Service->>DB: findOne(appTokenId)
DB-->>Service: appToken
Service->>DB: delete(appToken.id)
Service->>Service: sendInvitations([email], workspace, sender)
Service->>Email: send invitation email
Email-->>Service: email sent
Service-->>Resolver: SendInvitationsOutput
Resolver-->>Client: success
end
Note over Client,Email: sendInvitations Flow (MISSING throttling)
Client->>Resolver: sendInvitations(emails[])
Resolver->>Service: sendInvitations(emails, workspace, sender)
Note right of Service: ⚠️ No throttle check here!
Service->>DB: createWorkspaceInvitation(email)
Service->>Email: send invitation emails
Service-->>Resolver: SendInvitationsOutput
Resolver-->>Client: success
|
There was a problem hiding this comment.
Additional Comments (1)
-
packages/twenty-server/src/engine/core-modules/workspace-invitation/services/workspace-invitation.service.ts, line 255-260 (link)logic: throttling is missing here. the
sendInvitationsmethod is the main entry point for sending invitations but doesn't callthrottleInvitationSending, whileresendWorkspaceInvitationdoes. this creates a security gap where attackers can spam invitations throughsendInvitationswhile onlyresendWorkspaceInvitationis rate-limitedadd throttling at the start of this method:
4 files reviewed, 2 comments
.../twenty-server/src/engine/core-modules/workspace-invitation/workspace-invitation.resolver.ts
Outdated
Show resolved
Hide resolved
|
🚀 Preview Environment Ready! Your preview environment is available at: http://bore.pub:6314 This environment will automatically shut down when the PR is closed or after 5 hours. |
|
@ijreilly At first, i protect the sendInvitation method but you can't invite twice the same user. |
|
At first I protected sending invitations (not just resending) but while testing I figured that you couldn't "sendInvitations" to the same user. |
17e3aa6 to
485b225
Compare
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
Outdated
Show resolved
Hide resolved
packages/twenty-server/src/engine/core-modules/twenty-config/config-variables.ts
Outdated
Show resolved
Hide resolved
|
Hey @etiennejouan! After you've done the QA of your Pull Request, you can mark it as done here. Thank you! |
closes https://github.com/twentyhq/private-issues/issues/356