Skip to content

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

Open
meirdev wants to merge 3 commits intoowasp-modsecurity:v3/masterfrom
meirdev:v3/matched-rules-c-api
Open

Add C API to retrieve matched rules from a transaction#3551
meirdev wants to merge 3 commits intoowasp-modsecurity:v3/masterfrom
meirdev:v3/matched-rules-c-api

Conversation

@meirdev
Copy link
Copy Markdown

@meirdev meirdev commented Apr 22, 2026

references

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

Comment thread src/transaction.cc
* @retval 0 Index is out of range.
*
*/
extern "C" int64_t msc_get_matched_rule_id(Transaction *transaction,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This function returns only with one rule id, right?

In case of CRS, if it uses anomaly scoring model, this will return always with rule 949110, or similar ID (depends on intervention's phase).

Does it make sense?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Not exactly - the function returns a single rule ID, but I'm using msc_get_matched_rules_count to iterate through all matched rules.

Example of log from my tests:

["2026-04-22T06:44:46+00:00","172.20.0.1","36770","","178","localhost","0.000","POST","/etc/nginx/html/","","HTTP/1.1","http","1df077358d8536cd96324e994abf6256","","403","308","text/html","curl/8.5.0","","","1", "920273,941100,941110,941160,941390,941320,942131,942370,942431,942511,942432,949110"]

@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?

@sonarqubecloud
Copy link
Copy Markdown

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.

2 participants