Skip to content

Commit dfa2838

Browse files
fix: maxlimit check to subscription event requests (#600)
* fix: maxLimit checks added to subscription requests * docs(changeset): fix: maxLimit checks added to subscription message handler --------- Co-authored-by: Ricardo Cabral <me@ricardocabral.io>
1 parent 25d5405 commit dfa2838

3 files changed

Lines changed: 30 additions & 0 deletions

File tree

.changeset/brown-bears-pay.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"nostream": patch
3+
---
4+
5+
fix: maxLimit checks added to subscription message handler

src/handlers/subscribe-message-handler.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ export class SubscribeMessageHandler implements IMessageHandler, IAbortable {
116116
}
117117
}
118118

119+
const maxLimit = subscriptionLimits?.maxLimit ?? 0
120+
if (maxLimit > 0) {
121+
const hasExcessiveLimit = filters.some((filter) => filter.limit !== undefined && filter.limit > maxLimit)
122+
if (hasExcessiveLimit) {
123+
return `Limit too high: Filter limit must be less than or equal to ${maxLimit}`
124+
}
125+
}
126+
119127
if (
120128
typeof subscriptionLimits?.maxSubscriptionIdLength === 'number' &&
121129
subscriptionId.length > subscriptionLimits.maxSubscriptionIdLength

test/unit/handlers/subscribe-message-handler.spec.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,23 @@ describe('SubscribeMessageHandler', () => {
367367
)
368368
})
369369

370+
it('returns reason if filter limit exceeds max limit', () => {
371+
settingsFactory.returns({
372+
limits: {
373+
client: {
374+
subscription: {
375+
maxLimit: 50,
376+
},
377+
},
378+
},
379+
})
380+
filters = [{ limit: 100 }]
381+
382+
expect((handler as any).canSubscribe(subscriptionId, filters)).to.equal(
383+
'Limit too high: Filter limit must be less than or equal to 50',
384+
)
385+
})
386+
370387
it('returns reason if subscription id is too long', () => {
371388
settingsFactory.returns({
372389
limits: {

0 commit comments

Comments
 (0)