-
Notifications
You must be signed in to change notification settings - Fork 13k
feat(federation): add verifyMatrixIds method and API #37080
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
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 |
|---|---|---|
|
|
@@ -944,4 +944,51 @@ export class FederationMatrix extends ServiceClass implements IFederationMatrixS | |
|
|
||
| void this.homeserverServices.edu.sendTypingNotification(room.federation.mrid, userMui, isTyping); | ||
| } | ||
|
|
||
| async verifyMatrixIds(matrixIds: string[]): Promise<{ [key: string]: string }> { | ||
| const results = Object.fromEntries( | ||
| await Promise.all( | ||
| matrixIds.map(async (matrixId) => { | ||
| // Split only on the first ':' (after the leading '@') so we keep any port in the homeserver | ||
| const separatorIndex = matrixId.indexOf(':', 1); | ||
| if (separatorIndex === -1) { | ||
| return [matrixId, 'UNABLE_TO_VERIFY']; | ||
| } | ||
| const userId = matrixId.slice(0, separatorIndex); | ||
| const homeserverUrl = matrixId.slice(separatorIndex + 1); | ||
|
|
||
| if (homeserverUrl === this.serverName) { | ||
| const user = await Users.findOneByUsername(userId.slice(1)); | ||
| return [matrixId, user ? 'VERIFIED' : 'UNVERIFIED']; | ||
| } | ||
|
|
||
| if (!homeserverUrl) { | ||
| return [matrixId, 'UNABLE_TO_VERIFY']; | ||
| } | ||
| try { | ||
| const result = await this.homeserverServices.request.get< | ||
| | { | ||
| avatar_url: string; | ||
| displayname: string; | ||
| } | ||
| | { | ||
| errcode: string; | ||
| error: string; | ||
| } | ||
| >(homeserverUrl, `/_matrix/federation/v1/query/profile`, { user_id: matrixId }); | ||
|
|
||
| if ('errcode' in result && result.errcode === 'M_NOT_FOUND') { | ||
| return [matrixId, 'UNVERIFIED']; | ||
| } | ||
|
|
||
| return [matrixId, 'VERIFIED']; | ||
| } catch (e) { | ||
|
Comment on lines
+980
to
+985
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. Do not mark errored Matrix profile queries as VERIFIED Any response that still contains an - if ('errcode' in result && result.errcode === 'M_NOT_FOUND') {
- return [matrixId, 'UNVERIFIED'];
- }
-
- return [matrixId, 'VERIFIED'];
+ if ('errcode' in result) {
+ if (result.errcode === 'M_NOT_FOUND') {
+ return [matrixId, 'UNVERIFIED'];
+ }
+
+ return [matrixId, 'UNABLE_TO_VERIFY'];
+ }
|
||
| return [matrixId, 'UNABLE_TO_VERIFY']; | ||
| } | ||
| }), | ||
| ), | ||
| ); | ||
|
|
||
| return results; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Make
matrixIdsmandatory in the query schemaRight now the AJV schema doesn’t mark
matrixIdsas required, so a request without that parameter is accepted andmatrixIdsisundefined. The handler then callsfederationService.verifyMatrixIds(matrixIds), which blows up at runtime because it tries to iterate overundefined. Please make the field required (and consider rejecting unexpected extras) so we respond with a 400 instead of a 500:query: ajv.compile<{ matrixIds: string[]; }>({ type: 'object', properties: { matrixIds: { type: 'array', items: { type: 'string' } }, }, + required: ['matrixIds'], + additionalProperties: false, }),📝 Committable suggestion
🤖 Prompt for AI Agents