-
Notifications
You must be signed in to change notification settings - Fork 2
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
feat: improved WAF init error reporting #44
Conversation
The `ddwaf_init` call attempts to provide more information about failure causes through the `diagnostics` object returned. This may be populated even when receiving a `NULL` handle. This PR attempts to obtain an error from diagnostics when available in order to provide improved error messaging to the callers. Additionally, if diagnostics include any "top-level" error (via the `DiagnosticEntry.Error` field), consider the WAF initialization as failed and return the specified error. Errors reported at the individual entity level are not considered in this new check, as they may stem from new rules using operators that are not yet available in the current WAF library version, and that should be okay. This saves all users of the WAF from having to manually check for these error conditions in all places, which is cumbersome and error-prone.
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.
Requires some adjustement to allow using a handle in case of a partially accepted rule.
// wafInit initializes a new WAF with the provided ruleset, configuration and info objects. A | ||
// cgoRefPool ensures that the provided input values are not moved or garbage collected by the Go | ||
// runtime during the WAF call. | ||
func (waf *wafDl) wafInit(ruleset *wafObject, config *wafConfig, info *wafObject, refs cgoRefPool) wafHandle { |
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.
If you do it here you can also do it in wafRun
I guess
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.
Except wafRun requires some of the data to live as long as the context does, but not all of them... I actually have some (perhaps better?) ideas there, so I'll probably end up making another PR with changes to the cgoRefPool
ergonomics...
// Start off with a perfectly valid input... | ||
rules := makeValidRuleset() | ||
// And corrupt data for one particular field... | ||
rules[field] = 1337.42 |
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.
hack3r
The
ddwaf_init
call attempts to provide more information about failure causes through thediagnostics
object returned. This may be populated even when receiving aNULL
handle.This PR attempts to obtain an error from diagnostics when available in order to provide improved error messaging to the callers.