Merge branch 'since-limit' into 'main'

EventsDB: throw an error if `since` and `until` are too large

See merge request soapbox-pub/ditto!339
This commit is contained in:
Alex Gleason 2024-05-31 18:37:29 +00:00
commit a7ffe89107
2 changed files with 17 additions and 0 deletions

View File

@ -32,6 +32,9 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
if (event.created_at >= 2_147_483_647) {
throw new RelayError('blocked', 'event too far in the future');
}
if (event.kind >= 2_147_483_647) {
throw new RelayError('blocked', 'event kind too large');
}
if (!(await verifyEventWorker(event))) return;
if (encounterEvent(event)) return;
debug(`NostrEvent<${event.kind}> ${event.id}`);

View File

@ -93,6 +93,20 @@ class EventsDB implements NStore {
async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<NostrEvent[]> {
filters = await this.expandFilters(filters);
for (const filter of filters) {
if (filter.since && filter.since >= 2_147_483_647) {
throw new Error('since filter too far into the future');
}
if (filter.until && filter.until >= 2_147_483_647) {
throw new Error('until filter too far into the future');
}
for (const kind of filter.kinds ?? []) {
if (kind >= 2_147_483_647) {
throw new Error('kind filter too far into the future');
}
}
}
if (opts.signal?.aborted) return Promise.resolve([]);
if (!filters.length) return Promise.resolve([]);