x
Some checks failed
Code scanning - action / CodeQL-Build (push) Has been cancelled

This commit is contained in:
Ricardo Garim 2025-12-26 11:33:12 -03:00
parent 7f7928aef1
commit 312ec65b8c
No known key found for this signature in database
GPG Key ID: A3F76697AB7411CD
4 changed files with 21 additions and 11 deletions

View File

@ -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';

View File

@ -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) {

View File

@ -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, '-')}`;
}
}

View File

@ -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';