Skip to content

feat: populate firewall attributes and expose matched rules via verify#7

Merged
ArnabChatterjee20k merged 8 commits into
mainfrom
feat-case-insensitive-conditions
Jul 20, 2026
Merged

feat: populate firewall attributes and expose matched rules via verify#7
ArnabChatterjee20k merged 8 commits into
mainfrom
feat-case-insensitive-conditions

Conversation

@eldadfux

@eldadfux eldadfux commented Jul 18, 2026

Copy link
Copy Markdown
Member

Summary

Keeps evaluation centered on the existing Firewall::verify() API:

  1. Populate request values with setAttribute() / setAttributes()
  2. Register ordered Rule objects
  3. Call verify()
  4. Read getLastMatchedRule() for the matched rule and action metadata

Attribute alias resolution stays inside Firewall (requestPathpath, etc.). No condition-name rewriting. No parallel match()/matches() helpers.

Test plan

  • PHPUnit
  • Pint / PSR-12
  • PHPStan

Adds a `caseInsensitive` flag to `Condition` so value-based operators
(equal, notEqual, contains, notContains, startsWith, endsWith and their
negations) can compare strings without regard to letter casing.

This is useful for attributes whose values are case-insensitive by
nature, such as ISO country codes, where a rule authored with `il`
should still match a request resolved as `IL`.

- Flag defaults to false, preserving existing strict comparison behavior
- Round-trips through fromArray()/toArray()/encode()/decode()
- Only emitted in toArray() when enabled to keep payloads compact

Co-authored-by: Cursor <cursoragent@cursor.com>
@greptile-apps

greptile-apps Bot commented Jul 18, 2026

Copy link
Copy Markdown

Greptile Summary

This PR keeps rule evaluation centered on Firewall::verify() and exposes matched-rule metadata.

  • Documents verify() matched-rule behavior and return values.
  • Adds optional IDs to Rule objects.
  • Adds tests for populated request attributes, matched rules, and rule IDs.

Confidence Score: 5/5

This looks safe to merge.

  • No blocking issues found in the changed code.

Important Files Changed

Filename Overview
src/Firewall.php Updates the verify() documentation to describe matched-rule state and allow/block return behavior.
src/Rule.php Adds optional rule ID metadata through setId() and getId().
tests/FirewallTest.php Adds tests for attribute-based verification, matched-rule clearing, and reading rule IDs from the matched rule.

Reviews (6): Last reviewed commit: "feat: allow rules to carry an optional i..." | Re-trigger Greptile

Comment thread src/Condition.php Outdated
Canonicalize attributes so requestPath/RequestPath/path all resolve to
the same Firewall key (mirrors Firewall request* aliases + lowercase).

Co-authored-by: Cursor <cursoragent@cursor.com>
Comment thread src/Condition.php Outdated
eldadfux and others added 4 commits July 18, 2026 22:52
Keep attribute alias resolution inside Firewall so consumers populate request values through setAttribute() instead of rewriting condition names.

Co-authored-by: Cursor <cursoragent@cursor.com>
Keep condition comparisons case-sensitive while validating that request values flow through Firewall attributes.

Co-authored-by: Cursor <cursoragent@cursor.com>
@eldadfux eldadfux changed the title feat: add opt-in case-insensitive matching to conditions feat: evaluate conditions through populated firewall attributes Jul 18, 2026
Remove the conditions-only matches() helper. Consumers populate attributes,
register ordered rules, call verify(), then inspect getLastMatchedRule().

Co-authored-by: Cursor <cursoragent@cursor.com>
@eldadfux eldadfux changed the title feat: evaluate conditions through populated firewall attributes feat: populate firewall attributes and expose matched rules via verify Jul 18, 2026
Consumers can attach a stable id to matched rules so application-layer
metadata does not require a separate object map.

Co-authored-by: Cursor <cursoragent@cursor.com>
@ArnabChatterjee20k
ArnabChatterjee20k merged commit 1f1013d into main Jul 20, 2026
5 checks passed
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.

2 participants