owasp-modsecurity / owasp-modsecurity/ModSecurity

Collection multi vars

Open
#2,442 6 comments 0 reactions 1 assignee View on GitHub

@martinhsv is already working on this.

Since Nov 11, 2020.

3.x
Dominant language
C++
Stars
9.8k
Forks
1.8k
Avg merge
2h 46m
Merged PRs (30d)
1

Description

Hello,

When saving a value on several variables (setvar), the value actually taken into account is only the last one.

I reproduced the problem by creating a regression rule.

Example:
[
{
"enabled":1,
"version_min":300000,
"title":"Testing multi variables :: m.set SESSION & GLOBAL (1/1)",
"resource":"lua",
"client":{
"ip":"200.249.12.31",
"port":123
},
"server":{
"ip":"200.249.12.31",
"port":80
},
"request":{
"headers":{
"Host":"localhost",
"User-Agent":"My sweet little browser",
"Accept":"/",
"Content-Length": "0"
},
"uri":"/whee?res=1",
"method":"GET",
"body": [ ]
},
"response":{
"headers":{},
"body":[
"no need."
]
},
"expected":{
"audit_log":"",
"debug_log":"Target value: "2" \(Variable: SESSION:::::test\)",
"error_log":""
},
"rules":[
"SecRuleEngine On",
"SecAction "id:1,pass,setvar:SESSION.test=2"",
"SecAction "id:2,pass,setvar:GLOBAL.test=1"",
"SecRule SESSION.test "@contains 2" "id:3,t:none""
]
}
]

Result:
Test name: Testing multi variables :: m.set SESSION & GLOBAL (1/1).
Reason:
Debug log was not matching the expected results.
Expecting: Target value: "2" (Variable: SESSION:::::test)
Debug log:
[1604518512] [] [4] Initializing transaction
[1604518512] [] [4] Transaction context created.
[1604518512] [] [4] Starting phase CONNECTION. (SecRules 0)
[1604518512] [] [9] This phase consists of 0 rule(s).
[1604518512] [] [4] Starting phase URI. (SecRules 0 + 1/2)
[1604518512] [/whee?res=1] [4] Adding request argument (GET): name "res", value "1"
[1604518512] [/whee?res=1] [4] Starting phase REQUEST_HEADERS. (SecRules 1)
[1604518512] [/whee?res=1] [9] This phase consists of 3 rule(s).
[1604518512] [/whee?res=1] [4] (Rule: 1) Executing unconditional rule...
[1604518512] [/whee?res=1] [4] Running [independent] (non-disruptive) action: setvar
[1604518512] [/whee?res=1] [8] Saving variable: SESSION:test with value: 2
[1604518512] [/whee?res=1] [4] Running (disruptive) action: pass.
[1604518512] [/whee?res=1] [8] Running action pass
[1604518512] [/whee?res=1] [4] (Rule: 2) Executing unconditional rule...
[1604518512] [/whee?res=1] [4] Running [independent] (non-disruptive) action: setvar
[1604518512] [/whee?res=1] [8] Saving variable: GLOBAL:test with value: 1
[1604518512] [/whee?res=1] [4] Running (disruptive) action: pass.
[1604518512] [/whee?res=1] [8] Running action pass
[1604518512] [/whee?res=1] [4] (Rule: 3) Executing operator "Contains" with param "2" against SESSION:test.
[1604518512] [/whee?res=1] [9] Target value: "1" (Variable: SESSION:::::test)
[1604518512] [/whee?res=1] [4] Rule returned 0.
[1604518512] [/whee?res=1] [9] Matched vars cleaned.
[1604518512] [/whee?res=1] [9] Appending request body: 0 bytes. Limit set to: 0.000000
[1604518512] [/whee?res=1] [4] Starting phase REQUEST_BODY. (SecRules 2)
[1604518512] [/whee?res=1] [9] This phase consists of 0 rule(s).
[1604518512] [/whee?res=1] [4] Starting phase RESPONSE_HEADERS. (SecRules 3)
[1604518512] [/whee?res=1] [9] This phase consists of 0 rule(s).
[1604518512] [/whee?res=1] [9] Appending response body: 9 bytes. Limit set to: 0.000000
[1604518512] [/whee?res=1] [4] Starting phase RESPONSE_BODY. (SecRules 4)
[1604518512] [/whee?res=1] [4] Response body is disabled, returning... 2
[1604518512] [/whee?res=1] [4] Starting phase LOGGING. (SecRules 5)
[1604518512] [/whee?res=1] [9] This phase consists of 0 rule(s).
[1604518512] [/whee?res=1] [8] Checking if this request is suitable to be saved as an audit log.
[1604518512] [/whee?res=1] [5] Audit log engine was not set.

I looked at the collection files, the m_name is not record when saving a value in the storeOrUpdateFirst function.

The key is then common for all types (GLOBAL, IP, ...)

Am I missing something?

Thank you

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.