Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/brown-bears-pay.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"nostream": patch
---

fix: maxLimit checks added to subscription message handler
8 changes: 8 additions & 0 deletions src/handlers/subscribe-message-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,14 @@ export class SubscribeMessageHandler implements IMessageHandler, IAbortable {
}
}

const maxLimit = subscriptionLimits?.maxLimit ?? 0
if (maxLimit > 0) {
const hasExcessiveLimit = filters.some((filter) => filter.limit !== undefined && filter.limit > maxLimit)
Comment thread
cameri marked this conversation as resolved.
if (hasExcessiveLimit) {
return `Limit too high: Filter limit must be less than or equal to ${maxLimit}`
}
}

if (
typeof subscriptionLimits?.maxSubscriptionIdLength === 'number' &&
subscriptionId.length > subscriptionLimits.maxSubscriptionIdLength
Expand Down
17 changes: 17 additions & 0 deletions test/unit/handlers/subscribe-message-handler.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,23 @@ describe('SubscribeMessageHandler', () => {
)
})

it('returns reason if filter limit exceeds max limit', () => {
Comment thread
cameri marked this conversation as resolved.
settingsFactory.returns({
limits: {
client: {
subscription: {
maxLimit: 50,
},
},
},
})
filters = [{ limit: 100 }]

expect((handler as any).canSubscribe(subscriptionId, filters)).to.equal(
'Limit too high: Filter limit must be less than or equal to 50',
)
})

it('returns reason if subscription id is too long', () => {
settingsFactory.returns({
limits: {
Expand Down
Loading