Skip to content
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

Merged
merged 9 commits into from
Nov 14, 2023

Conversation

RomainMuller
Copy link
Contributor

@RomainMuller RomainMuller commented Nov 9, 2023

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.

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.
@RomainMuller RomainMuller requested a review from a team November 9, 2023 12:54
waf.go Outdated Show resolved Hide resolved
RomainMuller added a commit to DataDog/dd-trace-go that referenced this pull request Nov 9, 2023
handle.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@Julio-Guerra Julio-Guerra left a 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.

waf.go Outdated Show resolved Hide resolved
// 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 {
Copy link
Contributor

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

Copy link
Contributor Author

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...

decoder.go Outdated Show resolved Hide resolved
handle.go Outdated Show resolved Hide resolved
handle.go Outdated Show resolved Hide resolved
handle.go Outdated Show resolved Hide resolved
// Start off with a perfectly valid input...
rules := makeValidRuleset()
// And corrupt data for one particular field...
rules[field] = 1337.42
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hack3r

@RomainMuller RomainMuller merged commit 5e0e1c8 into main Nov 14, 2023
61 checks passed
@RomainMuller RomainMuller deleted the romain.marcadier/safer-waf branch November 14, 2023 12:44
eliottness pushed a commit to DataDog/dd-trace-go that referenced this pull request Nov 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants