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

fix WAF update rules version #4798

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/dd-trace/src/appsec/waf/waf_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ class WAFManager {
update (newRules) {
this.ddwaf.update(newRules)

this.rulesVersion = this.ddwaf.diagnostics.ruleset_version

Reporter.reportWafUpdate(this.ddwafVersion, this.rulesVersion)
}

Expand Down
12 changes: 9 additions & 3 deletions packages/dd-trace/test/appsec/waf/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ describe('WAF Manager', () => {
DDWAF.prototype.constructor.version = sinon.stub()
DDWAF.prototype.dispose = sinon.stub()
DDWAF.prototype.createContext = sinon.stub()
DDWAF.prototype.update = sinon.stub()
DDWAF.prototype.update = sinon.stub().callsFake(function (newRules) {
if (newRules?.metadata?.rules_version) {
this.diagnostics.ruleset_version = newRules?.metadata?.rules_version
}
})
DDWAF.prototype.diagnostics = {
ruleset_version: '1.0.0',
rules: {
Expand Down Expand Up @@ -181,6 +185,9 @@ describe('WAF Manager', () => {

it('should call Reporter.reportWafUpdate', () => {
const rules = {
metadata: {
rules_version: '4.2.0'
},
rules_data: [
{
id: 'blocked_users',
Expand All @@ -197,8 +204,7 @@ describe('WAF Manager', () => {

waf.update(rules)

expect(Reporter.reportWafUpdate).to.be.calledOnceWithExactly(wafVersion,
DDWAF.prototype.diagnostics.ruleset_version)
expect(Reporter.reportWafUpdate).to.be.calledOnceWithExactly(wafVersion, '4.2.0')
})
})

Expand Down
Loading