Skip to content

Add C API to retrieve matched rules from a transaction#3551

Merged
airween merged 6 commits intoowasp-modsecurity:v3/masterfrom
meirdev:v3/matched-rules-c-api
Apr 27, 2026
Merged

Add C API to retrieve matched rules from a transaction#3551
airween merged 6 commits intoowasp-modsecurity:v3/masterfrom
meirdev:v3/matched-rules-c-api

Conversation

@meirdev
Copy link
Copy Markdown
Contributor

@meirdev meirdev commented Apr 22, 2026

references

Required for: owasp-modsecurity/ModSecurity-nginx#374

Comment thread src/transaction.cc Outdated
@airween airween added the 3.x Related to ModSecurity version 3.x label Apr 22, 2026
@airween
Copy link
Copy Markdown
Member

airween commented Apr 22, 2026

Tests on Windows were failed, could you check them?

@airween
Copy link
Copy Markdown
Member

airween commented Apr 26, 2026

@meirdev - thanks for the changes. There are three new issues in Sonarcloud, could you take a look at them?

Also, please pick up the recent changes from v3/master.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds new ModSecurity C API entry points to let connectors query which rules matched during a transaction, intended to support downstream integration needs (referenced by the ModSecurity-nginx PR).

Changes:

  • Add msc_get_matched_rules_count(Transaction*) to return the number of stored rule match/message records on a transaction.
  • Add msc_get_matched_rule_id(Transaction*, size_t index) to fetch the rule ID for the N-th stored record.
  • Update public header to expose the new APIs and include <stdint.h> for int64_t.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/transaction.cc Implements the two new C API functions for matched-rule querying.
headers/modsecurity/transaction.h Exposes the new C API declarations (and adds <stdint.h> include).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/transaction.cc Outdated
Comment thread src/transaction.cc Outdated
@airween
Copy link
Copy Markdown
Member

airween commented Apr 26, 2026

@meirdev: and also please take a look at the Copilot suggestions.

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Apr 26, 2026

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@meirdev
Copy link
Copy Markdown
Contributor Author

meirdev commented Apr 26, 2026

There are three new issues in Sonarcloud, could you take a look at them?

Regarding the two remaining issues in SonarCloud: all the other extern "C" functions are inside the namespace, and I don't want to write these two differently.

@airween
Copy link
Copy Markdown
Member

airween commented Apr 27, 2026

Regarding the two remaining issues in SonarCloud: all the other extern "C" functions are inside the namespace, and I don't want to write these two differently.

Ah, you're totally right - thank you.

@airween
Copy link
Copy Markdown
Member

airween commented Apr 27, 2026

@meirdev thank you, merging now.

@airween airween merged commit 84783d0 into owasp-modsecurity:v3/master Apr 27, 2026
98 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Related to ModSecurity version 3.x

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants