I'm trying to access total number of cookies sent in response intercepted by mod-security and passed to LUA script.

Below is an example response from server

HTTP/1.1 200 OK
Date: Tue, 21 Aug 2018 13:54:35 GMT
Expires: -1
Cache-Control: private, max-age=0
Content-Type: text/html; charset=ISO-8859-1
Server: Apache
Set-Cookie: ONE=2018-08-21-13; expires=Thu, 20-Sep-2018 13:54:35 GMT; path=/; domain=.example.com
Set-Cookie: TWO=2018-08-21-13; expires=Thu, 20-Sep-2018 13:54:35 

Below is the modsecurity rule which calls LUA script

SecRuleScript "/etc/apache2/lua/logcookie.lua"

Below is the sample LUA script for accessing modsecurity variables.


function main()
    m.log(1,m.getvar("REQUEST_COOKIES.ONE")) //logs cookie ONE
    m.log(1,m.getvar("REQUEST_COOKIES.TWO")) //logs cookie TWO

I wanted to get the total number of cookies, And here is how i'm trying to accomplish which is not correct.

function main()
    totalcookies = m.getvar("&REQUEST_COOKIES") // which gives total

Let me know how to fix this.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.