Skip to content

Fix rasp.rule.match metric always reporting block:N/A#11723

Merged
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
rasp-rule-match-fix
Jun 25, 2026
Merged

Fix rasp.rule.match metric always reporting block:N/A#11723
gh-worker-dd-mergequeue-cf854d[bot] merged 2 commits into
masterfrom
rasp-rule-match-fix

Conversation

@jandro996

@jandro996 jandro996 commented Jun 24, 2026

Copy link
Copy Markdown
Member

What Does This Do

  • Moves WafMetricCollector.raspRuleMatch() call in WAFModule to after the WAF action loop so that flow.isBlocking() reflects the actual blocking decision (it always returned false before the loop because no action had been set yet)
  • Adds boolean blocked parameter to raspRuleMatch(RuleType, boolean)
  • Doubles raspRuleMatchCounter array size to RuleType.getNumValues() * 2, using index formula ruleType.ordinal() * 2 + (blocked ? 1 : 0) to track blocked and non-blocked counts independently per rule type
  • Updates prepareMetrics() to drain both the blocked slot (ordinal*2+1) and non-blocked slot (ordinal*2) per RuleType, emitting separate rasp.rule.match metrics for each outcome
  • Adds block: tag to both variant and non-variant branches of RaspRuleMatch
  • Guards flow.setAction(rba) against null return from createBlockRequestAction/createRedirectRequestAction (prevents NPE on flow.isBlocking() when action data is malformed)

Motivation

rasp.rule.match was always emitted with block:N/A (APPSEC-62729). Root cause: the metric was recorded before the WAF action loop in WAFModule.runWAF(). At that point flow.isBlocking() always returns false because blocking actions are only set via flow.setAction() inside the loop. Moving the call to after the loop fixes the tag.

Additional Notes

The counter-doubling pattern follows the existing aiGuardRequest canonical reference already present in WafMetricCollector.java (same index formula, same drain pattern). RuleType.getNumValues() is unchanged — the array size is the caller's responsibility.

setRaspMatched(true) (a state flag consumed during action processing) intentionally stays in its original position before the loop; only the metric recording call moves.

Contributor Checklist

Jira ticket: APPSEC-62729

Note: Once your PR is ready to merge, add it to the merge queue by commenting /merge. /merge -c cancels the queue request. /merge -f --reason "reason" skips all merge queue checks; please use this judiciously, as some checks do not run at the PR-level. For more information, see this doc.

rasp.rule.match was always reporting block:N/A because raspRuleMatch()
was called before the action loop; flow.isBlocking() is only valid
after setAction() runs inside the loop.

- Move raspRuleMatch() call to after the action loop (setRaspMatched stays in place)
- Add boolean blocked param; double counter array for per-outcome tracking
- Update prepareMetrics() to drain both blocked/non-blocked slots per RuleType
- Add block: tag to both variant and non-variant RaspRuleMatch branches
- Guard flow.setAction(rba) against null return from createBlockRequestAction/createRedirectRequestAction
@jandro996 jandro996 changed the title fix: report correct block outcome tag in rasp.rule.match metric Fix rasp.rule.match metric always reporting block:N/A Jun 24, 2026
@jandro996 jandro996 added type: bug fix Bug fix comp: asm waf Application Security Management (WAF) labels Jun 24, 2026
@jandro996
jandro996 marked this pull request as ready for review June 24, 2026 12:59
@jandro996
jandro996 requested a review from a team as a code owner June 24, 2026 12:59

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 9de4c7a700

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@jandro996
jandro996 added this pull request to the merge queue Jun 25, 2026
@dd-octo-sts

dd-octo-sts Bot commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

/merge

@gh-worker-devflow-routing-ef8351

gh-worker-devflow-routing-ef8351 Bot commented Jun 25, 2026

Copy link
Copy Markdown

View all feedbacks in Devflow UI.

2026-06-25 08:15:14 UTC ℹ️ Start processing command /merge


2026-06-25 08:15:19 UTC ℹ️ MergeQueue: pull request added to the queue

The expected merge time in master is approximately 1h (p90).


2026-06-25 09:19:59 UTC ℹ️ MergeQueue: This merge request was merged

@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 25, 2026
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot merged commit b622864 into master Jun 25, 2026
586 of 589 checks passed
@gh-worker-dd-mergequeue-cf854d
gh-worker-dd-mergequeue-cf854d Bot deleted the rasp-rule-match-fix branch June 25, 2026 09:19
@github-actions github-actions Bot added this to the 1.64.0 milestone Jun 25, 2026
TophrC-dd pushed a commit that referenced this pull request Jun 29, 2026
fix: report correct block outcome tag in rasp.rule.match metric

rasp.rule.match was always reporting block:N/A because raspRuleMatch()
was called before the action loop; flow.isBlocking() is only valid
after setAction() runs inside the loop.

- Move raspRuleMatch() call to after the action loop (setRaspMatched stays in place)
- Add boolean blocked param; double counter array for per-outcome tracking
- Update prepareMetrics() to drain both blocked/non-blocked slots per RuleType
- Add block: tag to both variant and non-variant RaspRuleMatch branches
- Guard flow.setAction(rba) against null return from createBlockRequestAction/createRedirectRequestAction

Merge branch 'master' into rasp-rule-match-fix

Co-authored-by: devflow.devflow-routing-intake <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: asm waf Application Security Management (WAF) type: bug fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants