{"record":{"id":"3762f67601ef337e","repo":"RocketChat/Rocket.Chat","slug":"error-federated-users-in-non-federated-rooms","errorCode":"error-federated-users-in-non-federated-rooms","errorMessage":"Cannot add federated users to non-federated rooms","messagePattern":"Cannot add federated users to non-federated rooms","errorType":"error_code","errorClass":"MeteorError","httpStatus":null,"severity":"error","filePath":"apps/meteor/ee/server/hooks/federation/index.ts","lineNumber":105,"sourceCode":"\t\t// deletion came from federation — don't echo\n\t\tif (isUserNativeFederated(user)) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (FederationActions.shouldPerformFederationAction(room)) {\n\t\t\tawait FederationMatrix.deleteMessage(room.federation.mrid, message);\n\t\t}\n\t},\n\tcallbacks.priority.MEDIUM,\n\t'native-federation-after-delete-message',\n);\n\nbeforeAddUsersToRoom.add(async ({ usernames, inviter }, room) => {\n\tif (!FederationActions.shouldPerformFederationAction(room) && inviter) {\n\t\t// check if trying to invite a federated user to a non-federated room\n\t\tconst federatedUsernames = usernames.filter((u) => validateFederatedUsername(u));\n\t\tif (federatedUsernames.length > 0) {\n\t\t\tthrow new MeteorError('error-federated-users-in-non-federated-rooms', 'Cannot add federated users to non-federated rooms');\n\t\t}\n\t\treturn;\n\t}\n\n\t// we create local users before adding them to the room\n\tawait FederationMatrix.ensureFederatedUsersExistLocally(usernames);\n});\n\nbeforeAddUserToRoom.add(\n\tasync ({ user, inviter }, room) => {\n\t\tif (!user.username || !inviter) {\n\t\t\treturn;\n\t\t}\n\n\t\tif (!FederationActions.shouldPerformFederationAction(room)) {\n\t\t\treturn;\n\t\t}\n","sourceCodeStart":87,"sourceCodeEnd":123,"githubUrl":"https://github.com/RocketChat/Rocket.Chat/blob/f9d3ec372bb580fa8d036f94cf03925a478ef768/apps/meteor/ee/server/hooks/federation/index.ts#L87-L123","documentation":"Thrown by the `beforeAddUsersToRoom` federation hook when federation should NOT be performed for the room (`FederationActions.shouldPerformFederationAction(room)` is false), the inviter exists, AND one or more of the requested usernames validate as federated usernames (`validateFederatedUsername`). It prevents inviting external/federated users into a room that is not itself federated.","triggerScenarios":"Calling add-users-to-room with a username like `@user:remote.server` (passes `validateFederatedUsername`) on a room where `shouldPerformFederationAction(room)` returns false and an `inviter` is present.","commonSituations":"User tries to @-mention/invite a federated handle into a regular non-federated private channel; UI permits selecting a federated contact for a local-only room; federation disabled on the room after it was created.","solutions":["Enable federation on the target room before inviting federated users, or convert it to a federated room.","Remove federated usernames from the invite list when targeting a non-federated room.","Surface a clear UI message explaining federated users can only join federated rooms."],"exampleFix":null,"handlingStrategy":"validation","validationCode":"import { validateFederatedUsername } from '@rocket.chat/core-typings';\n\nfunction inviteContainsFederatedUsers(usernames: string[]): boolean {\n\treturn usernames.filter(validateFederatedUsername).length > 0;\n}\n\n// before adding users to a non-federated room:\nif (!isRoomFederated(room) && inviteContainsFederatedUsers(usernames)) {\n\tthrow new Error('Cannot invite federated users to a non-federated room');\n}","typeGuard":"function isFederatedUsersInNonFederatedRoomError(e: unknown): boolean {\n\treturn e instanceof Meteor.Error && (e as Meteor.Error).error === 'error-federated-users-in-non-federated-rooms';\n}","tryCatchPattern":"try {\n\tawait beforeAddUsersToRoom.run({ usernames, inviter }, room);\n} catch (e) {\n\tif (e instanceof Meteor.Error && e.error === 'error-federated-users-in-non-federated-rooms') {\n\t\t// remove federated usernames or federate the room first\n\t}\n\tthrow e;\n}","preventionTips":["Filter federated usernames out of invite lists for non-federated rooms.","Make the room federated before inviting external users.","Show clear UI guidance that federated users require federated rooms."],"tags":["federation","rooms","validation","ee","meteor-error"],"backgroundTag":null,"analyzedSha":"f9d3ec372bb580fa8d036f94cf03925a478ef768","analyzedAt":"2026-08-12T19:07:17.372Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}