-
Notifications
You must be signed in to change notification settings - Fork 26
feat: add body field to filters
#5505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
|
Merging to
|
arcjet-rei
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Neat! Good job turning this around quickly. I'll need to review arcjet/arcjet#6412 as well, but the other piece of this is figuring out where we want to shim the remaining work of making this available to users into the roadmap. For now, I'll come back to approve this after looking at the monorepo PR.
analyze/index.ts
Outdated
| ): Promise<FilterResult> { | ||
| const coreImports = createCoreImports(); | ||
| const analyze = await initializeWasm(coreImports); | ||
| const body = await context.getBody(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I understanding correctly that we always read the request body if a filter rule is configured?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I looked at using the existing lookups (like ip_lookup), but those are global functions.
I do not know of an an alternative way to optionally pass things into, per call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not feasible to statically analyze the wirefilter body at say startup and determine if the body is needed? I worry this could maybe have a perf impact for folks with existing filters?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it not feasible to statically analyze the wirefilter body at say startup and determine if the body is needed?
It is not efficient. Optional data is implemented as external functions that are imported. However, that doesn't allow asynchronicity so this will take extra thought.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The simplest solution that comes to mind (note that I'm not advocating for it, I'm just contributing it for brainstorming purposes) would be to create a new rule type that is the same as a filter rule only it adds reading the body (e.g. FilterWithBody). It's not the most ergonomic solution from a DX perspective, because it requires people to notice that they're adding matching on a body, but if we tailored the error logs with this in mind it wouldn't be too bad.
|
I'm going to convert this to a draft while we consider how to resolve the concerns @qw-in and I have about the performance hit on each filter rule (even without using |
|
Yes, it is possible to only read the body if needed, by:
Although b) would theoretically be fastest (only one call into webassembly and no calls out of it), I think c) is the ideal scenario, and a) may be good enough until c) is feasible. Real world benchmarks are difficult, because giant bodies will be slow to read and take much more time than calling into/out of WebAssembly, if for example this CVE WAF idea would be automatically applied to every Arcjet user. If 1 out of 10 Running the benchmark I commited, the results on my machine are:
|
related to PRD-8