Skip to content

SESSION.counter is inaccurate #1273

@csutherl

Description

@csutherl

Using the SESSION collection configuration does not yield expected results for the SESSION counter, however the global counter works as expected. This issue affects both prefork and worker MPMs. Additionally, the tests that I am doing are all after applying the fix from PR #1224 because that PR corrects a lot of the concurrency issues that existed prior to the fix. One more piece of important information is that I can only seem to reliably reproduce this behavior on a physical machine; I guess because it's a concurrency issue that slower VMs I'm using just don't hit the race condition.

To reproduce, use the following mod_security configuration, start httpd with mod_security enabled, and make some requests.

# SESSION 
SecRule REQUEST_COOKIES:SESSIONID !^$  phase:5,id:118,nolog,pass,setsid:%{REQUEST_COOKIES.SESSIONID}
SecAction phase:5,id:119,nolog,pass,setvar:SESSION.my_counter=+1

I'm using the following loop to make 500 requests using five different sessions.

for i in `seq 1 500`;do
    curl -b "SESSIONID=testing$(shuf -i 1-5 -n 1)" localhost &>/dev/null &
done

After the requests are done, I'm checking the collection with modsec-sdbm-util to see if the counter values add up to the total number of requests, and they don't (I usually get ~490). Example:

# modsec-sdbm-util /var/lib/mod_security/default_SESSION -du | egrep '(^Key|my_counter)'
Key: "testing4", Value len: 212
                    my_counter: 99
Key: "testing2", Value len: 214
                    my_counter: 103
Key: "testing1", Value len: 214
                    my_counter: 104
Key: "testing5", Value len: 214
                    my_counter: 100
Key: "testing3", Value len: 212
                    my_counter: 90

The total number of all the my_counter variables should be equal to the number of requests.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions