mirror of
https://github.com/RocketChat/Rocket.Chat.git
synced 2025-12-28 06:47:25 +00:00
This commit is contained in:
parent
7f7928aef1
commit
312ec65b8c
@ -8,20 +8,14 @@ import {
|
||||
UserStatus,
|
||||
} from '@rocket.chat/core-typings';
|
||||
import type { MessageQuoteAttachment, IMessage, IRoom, IUser, IRoomNativeFederated } from '@rocket.chat/core-typings';
|
||||
import {
|
||||
eventIdSchema,
|
||||
roomIdSchema,
|
||||
userIdSchema,
|
||||
federationSDK,
|
||||
FederationRequestError,
|
||||
FederationValidationError,
|
||||
} from '@rocket.chat/federation-sdk';
|
||||
import { eventIdSchema, roomIdSchema, userIdSchema, federationSDK, FederationRequestError } from '@rocket.chat/federation-sdk';
|
||||
import type { EventID, UserID, FileMessageType, PresenceState } from '@rocket.chat/federation-sdk';
|
||||
import { Logger } from '@rocket.chat/logger';
|
||||
import { Users, Subscriptions, Messages, Rooms, Settings } from '@rocket.chat/models';
|
||||
import emojione from 'emojione';
|
||||
|
||||
import { isFederationDomainAllowed } from './api/middlewares/isFederationDomainAllowed';
|
||||
import { FederationValidationError } from './errors/FederationValidationError';
|
||||
import { toExternalMessageFormat, toExternalQuoteMessageFormat } from './helpers/message.parsers';
|
||||
import { MatrixMediaService } from './services/MatrixMediaService';
|
||||
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import { Settings } from '@rocket.chat/core-services';
|
||||
import { extractDomainFromId } from '@rocket.chat/federation-sdk';
|
||||
import { createMiddleware } from 'hono/factory';
|
||||
import mem from 'mem';
|
||||
|
||||
import { extractDomainFromMatrixUserId } from '../../FederationMatrix';
|
||||
|
||||
// cache for 60 seconds
|
||||
const getAllowList = mem(
|
||||
async () => {
|
||||
@ -39,7 +40,7 @@ export async function isFederationDomainAllowed(domains: string[]): Promise<bool
|
||||
|
||||
export async function isFederationDomainAllowedForUsernames(usernames: string[]): Promise<boolean> {
|
||||
// filter out local users (those without ':' in username) and extract domains from external users
|
||||
const domains = usernames.filter((username) => username.includes(':')).map((username) => extractDomainFromId(username));
|
||||
const domains = usernames.filter((username) => username.includes(':')).map((username) => extractDomainFromMatrixUserId(username));
|
||||
|
||||
// if no federated users, allow (all local users)
|
||||
if (domains.length === 0) {
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
// Local copy to avoid broken import chain in homeserver's federation-sdk
|
||||
export class FederationValidationError extends Error {
|
||||
public error: string;
|
||||
|
||||
constructor(
|
||||
public code: 'POLICY_DENIED' | 'CONNECTION_FAILED' | 'USER_NOT_FOUND',
|
||||
public userMessage: string,
|
||||
) {
|
||||
super(userMessage);
|
||||
this.name = 'FederationValidationError';
|
||||
this.error = `federation-${code.toLowerCase().replace(/_/g, '-')}`;
|
||||
}
|
||||
}
|
||||
@ -2,7 +2,9 @@ import 'reflect-metadata';
|
||||
|
||||
export { FederationMatrix, validateFederatedUsername } from './FederationMatrix';
|
||||
|
||||
export { generateEd25519RandomSecretKey, FederationValidationError } from '@rocket.chat/federation-sdk';
|
||||
export { generateEd25519RandomSecretKey } from '@rocket.chat/federation-sdk';
|
||||
|
||||
export { FederationValidationError } from './errors/FederationValidationError';
|
||||
|
||||
export { getFederationRoutes } from './api/routes';
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user