Skip to content

Commit a76ab3c

Browse files
committed
fix(notifications): registerAuthRoute did not implement any validation logic
1 parent ea8c0b6 commit a76ab3c

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

packages/notifications/src/drivers/realtime/PusherRealtimeDriver.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import type { PusherTransportConfig, RealtimeNotificationPayload } from '../../types'
2+
import { RequestException, env } from '@arkstack/common'
23

34
import type { RealtimeDriver } from '../../Contracts/RealtimeDriver'
4-
import { env } from '@arkstack/common'
55

66
/** The slice of the `pusher` server SDK this driver uses. */
77
interface PusherClient {
@@ -112,6 +112,7 @@ export class PusherRealtimeDriver implements RealtimeDriver {
112112
async registerAuthRoute(
113113
authEndpoint: string = '/realtime/auth',
114114
middleware?: unknown | unknown[],
115+
channelPrefix?: string
115116
): Promise<void> {
116117
const client = await this.client()
117118
const drivers = {
@@ -130,10 +131,15 @@ export class PusherRealtimeDriver implements RealtimeDriver {
130131
: [middleware, auth]
131132
)
132133

133-
Router.post(authEndpoint, ({ clearRequest }: any) => {
134+
Router.post(authEndpoint, ({ clearRequest, req }: any) => {
134135
const channel = clearRequest.input('channel_name')
135136
const socketId = clearRequest.input('socket_id')
136137

138+
const expected = channelPrefix ??
139+
`${config('notifications.drivers.realtime.channel_prefix', 'user.')}${req.user?.id ?? clearRequest.user?.id}`
140+
141+
RequestException.abortIf(channel !== expected, 'Channel access denied', 403)
142+
137143
return client.authorizeChannel(socketId, channel)
138144
}).middleware(Array.from(middlewares))
139145

0 commit comments

Comments
 (0)