Skip to content

Commit 312ec65

Browse files
committed
x
1 parent 7f7928a commit 312ec65

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

ee/packages/federation-matrix/src/FederationMatrix.ts

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,14 @@ import {
88
UserStatus,
99
} from '@rocket.chat/core-typings';
1010
import type { MessageQuoteAttachment, IMessage, IRoom, IUser, IRoomNativeFederated } from '@rocket.chat/core-typings';
11-
import {
12-
eventIdSchema,
13-
roomIdSchema,
14-
userIdSchema,
15-
federationSDK,
16-
FederationRequestError,
17-
FederationValidationError,
18-
} from '@rocket.chat/federation-sdk';
11+
import { eventIdSchema, roomIdSchema, userIdSchema, federationSDK, FederationRequestError } from '@rocket.chat/federation-sdk';
1912
import type { EventID, UserID, FileMessageType, PresenceState } from '@rocket.chat/federation-sdk';
2013
import { Logger } from '@rocket.chat/logger';
2114
import { Users, Subscriptions, Messages, Rooms, Settings } from '@rocket.chat/models';
2215
import emojione from 'emojione';
2316

2417
import { isFederationDomainAllowed } from './api/middlewares/isFederationDomainAllowed';
18+
import { FederationValidationError } from './errors/FederationValidationError';
2519
import { toExternalMessageFormat, toExternalQuoteMessageFormat } from './helpers/message.parsers';
2620
import { MatrixMediaService } from './services/MatrixMediaService';
2721

ee/packages/federation-matrix/src/api/middlewares/isFederationDomainAllowed.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import { Settings } from '@rocket.chat/core-services';
2-
import { extractDomainFromId } from '@rocket.chat/federation-sdk';
32
import { createMiddleware } from 'hono/factory';
43
import mem from 'mem';
54

5+
import { extractDomainFromMatrixUserId } from '../../FederationMatrix';
6+
67
// cache for 60 seconds
78
const getAllowList = mem(
89
async () => {
@@ -39,7 +40,7 @@ export async function isFederationDomainAllowed(domains: string[]): Promise<bool
3940

4041
export async function isFederationDomainAllowedForUsernames(usernames: string[]): Promise<boolean> {
4142
// filter out local users (those without ':' in username) and extract domains from external users
42-
const domains = usernames.filter((username) => username.includes(':')).map((username) => extractDomainFromId(username));
43+
const domains = usernames.filter((username) => username.includes(':')).map((username) => extractDomainFromMatrixUserId(username));
4344

4445
// if no federated users, allow (all local users)
4546
if (domains.length === 0) {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Local copy to avoid broken import chain in homeserver's federation-sdk
2+
export class FederationValidationError extends Error {
3+
public error: string;
4+
5+
constructor(
6+
public code: 'POLICY_DENIED' | 'CONNECTION_FAILED' | 'USER_NOT_FOUND',
7+
public userMessage: string,
8+
) {
9+
super(userMessage);
10+
this.name = 'FederationValidationError';
11+
this.error = `federation-${code.toLowerCase().replace(/_/g, '-')}`;
12+
}
13+
}

ee/packages/federation-matrix/src/index.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@ import 'reflect-metadata';
22

33
export { FederationMatrix, validateFederatedUsername } from './FederationMatrix';
44

5-
export { generateEd25519RandomSecretKey, FederationValidationError } from '@rocket.chat/federation-sdk';
5+
export { generateEd25519RandomSecretKey } from '@rocket.chat/federation-sdk';
6+
7+
export { FederationValidationError } from './errors/FederationValidationError';
68

79
export { getFederationRoutes } from './api/routes';
810

0 commit comments

Comments
 (0)