-
Notifications
You must be signed in to change notification settings - Fork 13.1k
refactor(federation): add isAuthenticated and canAccessResource middlewares #37067
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
8b80b32
9d5fb7e
390a3b9
5f37df7
25fccaa
bedb24f
281b200
b00fa81
b43e6fe
2e4a6fe
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -6,7 +6,7 @@ import { Router } from '@rocket.chat/http-router'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { ajv } from '@rocket.chat/rest-typings/dist/v1/Ajv'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { MatrixMediaService } from '../../services/MatrixMediaService'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { canAccessMedia } from '../middlewares'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import { canAccessResourceMiddleware } from '../middlewares/canAccessResource'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const MediaDownloadParamsSchema = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| type: 'object', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -75,79 +75,76 @@ async function getMediaFile(mediaId: string, serverName: string): Promise<{ file | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| export const getMatrixMediaRoutes = (homeserverServices: HomeserverServices) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { config, federationAuth } = homeserverServices; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const router = new Router('/federation'); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/v1/media/download/:mediaId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params: isMediaDownloadParamsProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200: isBufferResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return new Router('/federation') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/v1/media/download/:mediaId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params: isMediaDownloadParamsProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200: isBufferResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['Federation', 'Media'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['Federation', 'Media'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| canAccessMedia(federationAuth), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async (c) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { mediaId } = c.req.param(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { serverName } = config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: Add file streaming support | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await getMediaFile(mediaId, serverName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| canAccessResourceMiddleware(federationAuth, 'media'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async (c) => { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { mediaId } = c.req.param(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { serverName } = config; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // TODO: Add file streaming support | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const result = await getMediaFile(mediaId, serverName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if (!result) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 404, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: { errcode: 'M_NOT_FOUND', error: 'Media not found' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { file, buffer } = result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mimeType = file.type || 'application/octet-stream'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const fileName = file.name || mediaId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const multipartResponse = createMultipartResponse(buffer, mimeType, fileName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 404, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: { errcode: 'M_NOT_FOUND', error: 'Media not found' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 200, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...SECURITY_HEADERS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'content-type': multipartResponse.contentType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'content-length': String(multipartResponse.body.length), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: multipartResponse.body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 500, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: { errcode: 'M_UNKNOWN', error: 'Internal server error' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const { file, buffer } = result; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const mimeType = file.type || 'application/octet-stream'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const fileName = file.name || mediaId; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| const multipartResponse = createMultipartResponse(buffer, mimeType, fileName); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 200, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| headers: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ...SECURITY_HEADERS, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'content-type': multipartResponse.contentType, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 'content-length': String(multipartResponse.body.length), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: multipartResponse.body, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } catch (error) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 500, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: { errcode: 'M_UNKNOWN', error: 'Internal server error' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| router.get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/v1/media/thumbnail/:mediaId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params: isMediaDownloadParamsProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['Federation', 'Media'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async () => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 404, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errcode: 'M_UNRECOGNIZED', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error: 'This endpoint is not implemented on the homeserver side', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| .get( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| '/v1/media/thumbnail/:mediaId', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| params: isMediaDownloadParamsProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| response: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404: isErrorResponseProps, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| tags: ['Federation', 'Media'], | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return router; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| canAccessResourceMiddleware(federationAuth, 'media'), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| async (_c) => ({ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| statusCode: 404, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| body: { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errcode: 'M_UNRECOGNIZED', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| error: 'This endpoint is not implemented on the homeserver side', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+132
to
+149
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Status code mismatch: use 501 for unimplemented endpoints. The endpoint returns a 404 status code with an error message stating "This endpoint is not implemented on the homeserver side." This is semantically incorrect—404 indicates "resource not found," while 501 indicates "not implemented." Apply this diff to use the correct status code: .get(
'/v1/media/thumbnail/:mediaId',
{
params: isMediaDownloadParamsProps,
response: {
- 404: isErrorResponseProps,
+ 501: isErrorResponseProps,
},
tags: ['Federation', 'Media'],
},
canAccessResourceMiddleware(federationAuth, 'media'),
async (_c) => ({
- statusCode: 404,
+ statusCode: 501,
body: {
errcode: 'M_UNRECOGNIZED',
error: 'This endpoint is not implemented on the homeserver side',
},
}),
);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,9 @@ | |
| import { Router } from '@rocket.chat/http-router'; | ||
| import { ajv } from '@rocket.chat/rest-typings/dist/v1/Ajv'; | ||
|
|
||
| import { canAccessResourceMiddleware } from '../middlewares/canAccessResource'; | ||
| import { isAuthenticatedMiddleware } from '../middlewares/isAuthenticated'; | ||
|
|
||
| const UsernameSchema = { | ||
| type: 'string', | ||
| pattern: '^@[A-Za-z0-9_=\\/.+-]+:(.+)$', | ||
|
|
@@ -148,7 +151,7 @@ | |
| required: ['roomId', 'userId'], | ||
| }; | ||
|
|
||
| // @ts-ignore | ||
|
Check warning on line 154 in ee/packages/federation-matrix/src/api/_matrix/profiles.ts
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const isMakeJoinParamsProps = ajv.compile(MakeJoinParamsSchema); | ||
|
|
||
|
|
@@ -174,7 +177,7 @@ | |
| }, | ||
| }; | ||
|
|
||
| // @ts-ignore | ||
|
Check warning on line 180 in ee/packages/federation-matrix/src/api/_matrix/profiles.ts
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const isMakeJoinQueryProps = ajv.compile(MakeJoinQuerySchema); | ||
|
|
||
|
|
@@ -260,7 +263,7 @@ | |
| required: ['room_version', 'event'], | ||
| }; | ||
|
|
||
| // @ts-ignore | ||
|
Check warning on line 266 in ee/packages/federation-matrix/src/api/_matrix/profiles.ts
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const isMakeJoinResponseProps = ajv.compile(MakeJoinResponseSchema); | ||
|
|
||
|
|
@@ -350,9 +353,10 @@ | |
| const isEventAuthResponseProps = ajv.compile(EventAuthResponseSchema); | ||
|
|
||
| export const getMatrixProfilesRoutes = (services: HomeserverServices) => { | ||
| const { profile } = services; | ||
| const { profile, federationAuth } = services; | ||
|
|
||
| return new Router('/federation') | ||
| .use(isAuthenticatedMiddleware(federationAuth)) | ||
| .get( | ||
| '/v1/query/profile', | ||
| { | ||
|
|
@@ -414,14 +418,13 @@ | |
| tags: ['Federation'], | ||
| license: ['federation'], | ||
| }, | ||
| async (c) => { | ||
| const { userId } = c.req.param(); | ||
|
|
||
| const response = await profile.getDevices(userId); | ||
|
|
||
| async (_c) => { | ||
| return { | ||
| body: response, | ||
| statusCode: 200, | ||
| body: { | ||
| errcode: 'M_UNRECOGNIZED', | ||
| error: 'This endpoint is not implemented on the homeserver side', | ||
| }, | ||
| statusCode: 501, | ||
| }; | ||
| }, | ||
| ) | ||
|
|
@@ -436,6 +439,7 @@ | |
| tags: ['Federation'], | ||
| license: ['federation'], | ||
| }, | ||
| canAccessResourceMiddleware(federationAuth, 'room'), | ||
| async (c) => { | ||
| const { roomId, userId } = c.req.param(); | ||
| const url = new URL(c.req.url); | ||
|
|
@@ -467,6 +471,7 @@ | |
| tags: ['Federation'], | ||
| license: ['federation'], | ||
| }, | ||
| canAccessResourceMiddleware(federationAuth, 'room'), | ||
| async (c) => { | ||
| const { roomId } = c.req.param(); | ||
| const body = await c.req.json(); | ||
|
|
@@ -489,6 +494,7 @@ | |
| tags: ['Federation'], | ||
| license: ['federation'], | ||
| }, | ||
| canAccessResourceMiddleware(federationAuth, 'room'), | ||
| async (c) => { | ||
| const { roomId, eventId } = c.req.param(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,6 +2,8 @@ | |
| import { Router } from '@rocket.chat/http-router'; | ||
| import { ajv } from '@rocket.chat/rest-typings/dist/v1/Ajv'; | ||
|
|
||
| import { canAccessResourceMiddleware } from '../middlewares/canAccessResource'; | ||
|
|
||
| const UsernameSchema = { | ||
| type: 'string', | ||
| pattern: '^@[A-Za-z0-9_=\\/.+-]+:(.+)$', | ||
|
|
@@ -46,7 +48,7 @@ | |
| required: ['roomId', 'stateKey'], | ||
| }; | ||
|
|
||
| // @ts-ignore | ||
|
Check warning on line 51 in ee/packages/federation-matrix/src/api/_matrix/send-join.ts
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const isSendJoinParamsProps = ajv.compile(SendJoinParamsSchema); | ||
|
|
||
|
|
@@ -183,7 +185,7 @@ | |
| ], | ||
| }; | ||
|
|
||
| // @ts-ignore | ||
|
Check warning on line 188 in ee/packages/federation-matrix/src/api/_matrix/send-join.ts
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const isSendJoinEventProps = ajv.compile(SendJoinEventSchema); | ||
|
|
||
|
|
@@ -217,12 +219,12 @@ | |
| required: ['event', 'state', 'auth_chain', 'members_omitted', 'origin'], | ||
| }; | ||
|
|
||
| // @ts-ignore | ||
|
Check warning on line 222 in ee/packages/federation-matrix/src/api/_matrix/send-join.ts
|
||
| // eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
| const isSendJoinResponseProps = ajv.compile(SendJoinResponseSchema); | ||
|
|
||
| export const getMatrixSendJoinRoutes = (services: HomeserverServices) => { | ||
| const { sendJoin } = services; | ||
| const { sendJoin, federationAuth } = services; | ||
|
|
||
| return new Router('/federation').put( | ||
| '/v2/send_join/:roomId/:stateKey', | ||
|
|
@@ -235,6 +237,7 @@ | |
| tags: ['Federation'], | ||
| license: ['federation'], | ||
| }, | ||
| canAccessResourceMiddleware(federationAuth, 'room'), | ||
| async (c) => { | ||
sampaiodiego marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const { roomId, stateKey } = c.req.param(); | ||
| const body = await c.req.json(); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.