EventsDB: throw an error if `since` and `until` are too large
This commit is contained in:
parent
f98ebd359a
commit
3dd25feddc
|
@ -32,6 +32,9 @@ async function handleEvent(event: DittoEvent, signal: AbortSignal): Promise<void
|
||||||
if (event.created_at >= 2_147_483_647) {
|
if (event.created_at >= 2_147_483_647) {
|
||||||
throw new RelayError('blocked', 'event too far in the future');
|
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 (!(await verifyEventWorker(event))) return;
|
||||||
if (encounterEvent(event)) return;
|
if (encounterEvent(event)) return;
|
||||||
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
debug(`NostrEvent<${event.kind}> ${event.id}`);
|
||||||
|
|
|
@ -93,6 +93,20 @@ class EventsDB implements NStore {
|
||||||
async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<NostrEvent[]> {
|
async query(filters: NostrFilter[], opts: { signal?: AbortSignal; limit?: number } = {}): Promise<NostrEvent[]> {
|
||||||
filters = await this.expandFilters(filters);
|
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 (opts.signal?.aborted) return Promise.resolve([]);
|
||||||
if (!filters.length) return Promise.resolve([]);
|
if (!filters.length) return Promise.resolve([]);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue