Skip to content

Commit 502288a

Browse files
feat(filters): add limit to 10 expressions, 1024 bytes (#5212)
Closes arcjet/arcjet#5820.
1 parent 5c414d6 commit 502288a

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed
342 Bytes
Binary file not shown.
342 Bytes
Binary file not shown.

analyze/test/analyze.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -311,6 +311,7 @@ test("matchFilters", async function (t) {
311311
{ allowed: false, matchedExpressions: [], undeterminedExpressions: [] },
312312
);
313313
});
314+
314315
await t.test("should deny w/o `allowIfMatch` and a match", async function () {
315316
assert.deepEqual(
316317
await matchFilters(
@@ -341,4 +342,64 @@ test("matchFilters", async function (t) {
341342
);
342343
},
343344
);
345+
346+
const tenExpressions = Array.from({ length: 10 }, function (_, index) {
347+
return "ip.src == 127.0.0." + index;
348+
});
349+
350+
await t.test("should work w/ `10` expressions", async function () {
351+
assert.deepEqual(
352+
await matchFilters(
353+
exampleContext,
354+
{ ip: "127.0.0.127" },
355+
tenExpressions,
356+
false,
357+
),
358+
{ allowed: true, matchedExpressions: [], undeterminedExpressions: [] },
359+
);
360+
});
361+
362+
await t.test("should fail w/ `11` expressions", async function () {
363+
await assert.rejects(
364+
matchFilters(
365+
exampleContext,
366+
{ ip: "127.0.0.127" },
367+
[...tenExpressions, "ip.src == 127.0.0.10"],
368+
false,
369+
),
370+
/Failed to match filters: only `10` expressions may be passed/,
371+
);
372+
});
373+
374+
await t.test("should work w/ `1024` bytes", async function () {
375+
const tenThousandTwentyFourBytes =
376+
'http.host eq "' + "a".repeat(1009) + '"';
377+
assert.equal(new Blob([tenThousandTwentyFourBytes]).size, 1024);
378+
379+
assert.deepEqual(
380+
await matchFilters(
381+
exampleContext,
382+
{ ip: "127.0.0.1" },
383+
[tenThousandTwentyFourBytes],
384+
false,
385+
),
386+
{ allowed: true, matchedExpressions: [], undeterminedExpressions: [] },
387+
);
388+
});
389+
390+
await t.test("should fail w/ `1025` bytes", async function () {
391+
const tenThousandTwentyFiveBytes =
392+
'http.host eq "' + "a".repeat(1010) + '"';
393+
assert.equal(new Blob([tenThousandTwentyFiveBytes]).size, 1025);
394+
395+
await assert.rejects(
396+
matchFilters(
397+
exampleContext,
398+
{ ip: "127.0.0.127" },
399+
[tenThousandTwentyFiveBytes],
400+
false,
401+
),
402+
/Failed to match filters: only `1024` bytes may be passed in expression/,
403+
);
404+
});
344405
});

0 commit comments

Comments
 (0)