-
Notifications
You must be signed in to change notification settings - Fork 20
feat: adds event ACL #161
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
feat: adds event ACL #161
Changes from all commits
586957f
0681618
1acf9df
63c3dee
c656ed6
c6cce83
77d9186
fb50013
1948ad3
bbcead8
41ab281
f02fdbb
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 | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -911,8 +911,16 @@ export class StateService { | |||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| async getServersInRoom(roomId: string) { | ||||||||||||||||||||||||||||||||||||||
| return this.getMembersOfRoom(roomId).then((members) => | ||||||||||||||||||||||||||||||||||||||
| members.map((member) => member.split(':').pop()!), | ||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||
| const members = await this.getMembersOfRoom(roomId); | ||||||||||||||||||||||||||||||||||||||
| if (!members.length) { | ||||||||||||||||||||||||||||||||||||||
| throw new Error(`No members found in room ${roomId}`); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return members.map((member) => { | ||||||||||||||||||||||||||||||||||||||
| const server = member.split(':').pop(); | ||||||||||||||||||||||||||||||||||||||
| if (!server) { | ||||||||||||||||||||||||||||||||||||||
| throw new Error(`Invalid member format of room ${roomId}: ${member}`); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| return server; | ||||||||||||||||||||||||||||||||||||||
| }); | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+918
to
+924
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. Bug: incorrect server parsing for ports/IPv6; dedupe servers
Apply this diff: - return members.map((member) => {
- const server = member.split(':').pop();
- if (!server) {
- throw new Error(`Invalid member format of room ${roomId}: ${member}`);
- }
- return server;
- });
+ const servers = new Set<string>();
+ for (const member of members) {
+ const idx = member.indexOf(':');
+ if (idx < 0 || idx === member.length - 1) {
+ throw new Error(`Invalid member format in room ${roomId}: ${member}`);
+ }
+ // Everything after the first ":" is the server name; it may contain ":" (port/IPv6).
+ const server = member.slice(idx + 1);
+ servers.add(server);
+ }
+ return [...servers];📝 Committable suggestion
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| export const errCodes: Record< | ||
| string, | ||
| { errcode: string; error: string; status: 401 | 403 | 500 } | ||
| > = { | ||
| M_UNAUTHORIZED: { | ||
| errcode: 'M_UNAUTHORIZED', | ||
| error: 'Invalid or missing signature', | ||
| status: 401, | ||
| }, | ||
| M_FORBIDDEN: { | ||
| errcode: 'M_FORBIDDEN', | ||
| error: 'Access denied', | ||
| status: 403, | ||
| }, | ||
| M_UNKNOWN: { | ||
| errcode: 'M_UNKNOWN', | ||
| error: 'Internal server error while processing request', | ||
| status: 500, | ||
| }, | ||
| }; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,4 +1,8 @@ | ||
| import { ConfigService, EventService } from '@hs/federation-sdk'; | ||
| import { | ||
| ConfigService, | ||
| EventAuthorizationService, | ||
| EventService, | ||
| } from '@hs/federation-sdk'; | ||
| import { EventID } from '@hs/room'; | ||
| import { Elysia } from 'elysia'; | ||
| import { container } from 'tsyringe'; | ||
|
|
@@ -10,10 +14,12 @@ import { | |
| SendTransactionBodyDto, | ||
| SendTransactionResponseDto, | ||
| } from '../../dtos'; | ||
| import { canAccessEvent } from '../../middlewares/acl.middleware'; | ||
|
|
||
| export const transactionsPlugin = (app: Elysia) => { | ||
| const eventService = container.resolve(EventService); | ||
| const configService = container.resolve(ConfigService); | ||
| const eventAuthService = container.resolve(EventAuthorizationService); | ||
|
|
||
| return app | ||
| .put( | ||
|
|
@@ -62,6 +68,7 @@ export const transactionsPlugin = (app: Elysia) => { | |
| }; | ||
| }, | ||
| { | ||
| use: canAccessEvent(eventAuthService), | ||
|
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. 💡 Verification agent 🧩 Analysis chainVerify Elysia supports per‑route 🌐 Web query: 💡 Result: Short answer: No — Elysia does not provide a per-route "use" option to attach a plugin to a single route. The official route documentation describes route options for things like local schema/hooks but does not list a "use" property, and the plugin docs describe attaching plugins via app.use (instance‑level) or using guards/plugins as instances, not a per‑route options "use". [1][2] Sources:
Remove per‑route Confirmed: route options expose a route-level beforeHandle for auth/validation; plugins are registered via .use on an instance and scoping is done with group/guard. (elysiajs.com) File: packages/homeserver/src/controllers/federation/transactions.controller.ts (line ~68) — replace
🤖 Prompt for AI Agents |
||
| params: GetEventParamsDto, | ||
| response: { | ||
| 200: GetEventResponseDto, | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.