Skip to content

Commit 6d24655

Browse files
committed
Release 3.6.0
1 parent 9717aaf commit 6d24655

18 files changed

Lines changed: 1058 additions & 521 deletions

.vs/slnx.sqlite

88 KB
Binary file not shown.

Examples/ApacheHandlerUsingConfigFromFile.lua

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
----------------------------------------------------------------------------------------------------
2-
-- ApacheHandlerSimple.lua
2+
-- ApacheHandlerUsingConfigFromFile.lua
33
----------------------------------------------------------------------------------------------------
4-
-- HANDLER: ApacheHandlerSimple
4+
-- HANDLER: ApacheHandlerUsingConfigFromFile
55
--
66
-- DESCRIPTION:
77
-- This Apache httpd Lua handler verifies that HTTP requests are allowed to be passed to the
@@ -14,6 +14,14 @@
1414
--... * QUEUEIT_INT_CONF_FILE: The local JSON file containing the integration configuration
1515
-- * QUEUEIT_ERROR_CODE: (optional) The response code to use instead of declining to act
1616
-- if request handling fails
17+
-- * QUEUEIT_COOKIE_OPTIONS_HTTPONLY: (optional) Set to true if you want cookies with httponly
18+
-- flag set. Only enable if this you use pure server-side integration
19+
-- e.g. not JS Hybrid
20+
-- * QUEUEIT_COOKIE_OPTIONS_SECURE: (optional) Set to true if you want cookies with secure
21+
-- flag set. Only enable if your website runs purely on https
22+
-- * QUEUEIT_COOKIE_OPTIONS_SAMESITE: (optional) Set to true if you want cookies with samesite
23+
-- flag set. Only use 'strict' if your queue protected site stays on
24+
-- same domain (no navigation to subdomains)
1725
-- Note that the integration configuration is read on every request. The JSON file containing
1826
-- The integration configuration should, for performance reasons, be available locally.
1927
--
@@ -25,7 +33,7 @@
2533
-- SetEnv QUEUEIT_SECRET_KEY "{SECRET_KEY}"
2634
-- SetEnv QUEUEIT_INT_CONF_FILE "{APP_FOLDER}/integration_config.json"
2735
-- SetEnv QUEUEIT_ERROR_CODE "400"
28-
-- LuaMapHandler "{URI_PATTERN}" "{APP_FOLDER}/Handlers/ApacheHandlerSimple.lua"
36+
-- LuaMapHandler "{URI_PATTERN}" "{APP_FOLDER}/Handlers/ApacheHandlerUsingConfigFromFile.lua"
2937
-- LuaPackagePath "{APP_FOLDER}/SDK/?.lua"
3038
-- LuaPackagePath "{APP_FOLDER}/Helpers/?/?.lua"
3139
-- LuaPackagePath "{APP_FOLDER}/Handlers/?.lua"
@@ -38,12 +46,12 @@
3846
----------------------------------------------------------------------------------------------------
3947

4048

41-
local DEBUG_TAG = "ApacheHandlerHelperSimple.lua"
49+
local DEBUG_TAG = "ApacheHandlerUsingConfigFromFile.lua"
4250

4351
local kuHandler = require("KnownUserApacheHandler")
4452
local file = require("file")
4553

46-
local function initRequiredHelpers(r)
54+
local function initRequiredHelpers(r, cookieOptions)
4755
local iHelpers = require("KnownUserImplementationHelpers")
4856

4957
iHelpers.request.getAbsoluteUri = function()
@@ -55,6 +63,8 @@ local function initRequiredHelpers(r)
5563
r:debug(string.format("[%s] Rebuilt request URL as: %s", DEBUG_TAG, fullUrl))
5664
return fullUrl
5765
end
66+
67+
iHelpers.response.cookieOptions = cookieOptions
5868
end
5969

6070
function handle(r)
@@ -65,15 +75,26 @@ function handle(r)
6575
-- catch errors if any occur
6676
local success, result = pcall(function()
6777

68-
-- get configuration from environment variables
78+
-- get configuration from environment variables
6979
local customerId = r.subprocess_env["QUEUEIT_CUSTOMER_ID"]
7080
local secretKey = r.subprocess_env["QUEUEIT_SECRET_KEY"]
7181
local intConfFile = r.subprocess_env["QUEUEIT_INT_CONF_FILE"]
7282
local errorCode = r.subprocess_env["QUEUEIT_ERROR_CODE"]
83+
local cookieOptions =
84+
{
85+
httpOnly = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_HTTPONLY"],
86+
secure = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_SECURE"],
87+
sameSite = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_SAMESITE"]
88+
}
89+
7390
r:debug(string.format("[%s] Environment variable QUEUEIT_CUSTOMER_ID: %s", DEBUG_TAG, customerId))
7491
r:debug(string.format("[%s] Environment variable QUEUEIT_SECRET_KEY: %s", DEBUG_TAG, secretKey))
7592
r:debug(string.format("[%s] Environment variable QUEUEIT_INT_CONF_FILE: %s", DEBUG_TAG, intConfFile))
7693
r:debug(string.format("[%s] Environment variable QUEUEIT_ERROR_CODE: %s", DEBUG_TAG, errorCode))
94+
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_HTTPONLY: %s", DEBUG_TAG, cookieOptions.httpOnly))
95+
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_SECURE: %s", DEBUG_TAG, cookieOptions.secure))
96+
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_SAMESITE: %s", DEBUG_TAG, cookieOptions.sameSite))
97+
7798
assert(customerId ~= nil, "customerId invalid")
7899
assert(secretKey ~= nil, "secretKey invalid")
79100
assert(intConfFile ~= nil, "config invalid")
@@ -90,7 +111,7 @@ function handle(r)
90111
r:debug(string.format("[%s] Value of variable errorCode: %s", DEBUG_TAG, errorCode))
91112

92113
-- initialize helper functions
93-
initRequiredHelpers(r)
114+
initRequiredHelpers(r, cookieOptions)
94115

95116
-- read integration configuration from file
96117
local intConfJson = file.readAll(intConfFile)

Handlers/KnownUserApacheHandler.lua

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,16 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
1313

1414
-- Implement required helpers
1515
-- ********************************************************************************
16+
iHelpers.system.getConnectorName = function()
17+
return apache2.version
18+
end
19+
1620
iHelpers.json.parse = function(jsonStr)
1721
local json = require("json")
1822
return json.parse(jsonStr)
1923
end
2024

21-
iHelpers.hash.hmac_sha256_encode = function(message, key)
25+
iHelpers.hash.hmac_sha256_encode = function(message, key)
2226
local sha2 = require("sha2")
2327
return sha2.hmac(sha2.sha256, key, message)
2428
end
@@ -65,7 +69,7 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
6569
startIndex, endIndex = string.find(v, name)
6670

6771
if(endIndex ~= nil) then
68-
return v:sub(endIndex + 1)
72+
return v:sub(endIndex + 1)
6973
end
7074
end
7175
end
@@ -87,6 +91,10 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
8791
-- because we want to support Apache version < 2.4.12
8892
-- where there is bug in that specific method
8993
iHelpers.response.setCookie = function(name, value, expire, domain)
94+
-- lua_mod only supports 1 Set-Cookie header (because 'err_headers_out' is a table).
95+
-- So calling this method (setCookie) multiple times will not work as expected.
96+
-- In this case final call will apply.
97+
9098
if (domain == nil) then
9199
domain = ""
92100
end
@@ -101,10 +109,13 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
101109
if expire ~= nil and type(expire) == "number" and expire > 0 then
102110
expire_text = '; Expires=' .. os.date("!%a, %d %b %Y %H:%M:%S GMT", expire)
103111
end
104-
112+
105113
request_rec.err_headers_out["Set-Cookie"] = name .. '=' .. value
106114
.. expire_text
107115
.. (domain ~= "" and '; Domain=' .. domain or '')
116+
.. (iHelpers.response.cookieOptions.httpOnly and '; HttpOnly' or '')
117+
.. (iHelpers.response.cookieOptions.secure and '; Secure' or '')
118+
.. (iHelpers.response.cookieOptions.sameSite and '; SameSite=' .. iHelpers.response.cookieOptions.sameSite or '')
108119
.. '; Path=/;'
109120

110121
end
@@ -119,8 +130,8 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
119130

120131
local queueitToken = request_rec:parseargs()["queueittoken"]
121132
local fullUrl = iHelpers.request.getAbsoluteUri()
122-
local currentUrlWithoutQueueitToken = fullUrl:gsub("([\\%?%&])(" .. knownUser.QUEUEIT_TOKEN_KEY .. "=[^&]*)", "")
123-
133+
local currentUrlWithoutQueueitToken = fullUrl:gsub("([\\%?%&])(" .. knownUser.QUEUEIT_TOKEN_KEY .. "=[^&]*)", "")
134+
124135
local validationResult = nil
125136
if (isIntegrationConfig) then
126137
validationResult = knownUser.validateRequestByIntegrationConfig(currentUrlWithoutQueueitToken, queueitToken, config, customerId, secretKey)
@@ -130,10 +141,10 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
130141

131142
if (validationResult:doRedirect()) then
132143
if (validationResult.isAjaxResult) then
133-
request_rec.err_headers_out[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult:getAjaxRedirectUrl()
144+
request_rec.err_headers_out[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult:getAjaxRedirectUrl()
134145
else
135-
request_rec.err_headers_out["Location"] = validationResult.redirectUrl
136-
return apache2.HTTP_MOVED_TEMPORARILY
146+
request_rec.err_headers_out["Location"] = validationResult.redirectUrl
147+
return apache2.HTTP_MOVED_TEMPORARILY
137148
end
138149
else
139150
-- Request can continue - we remove queueittoken form querystring parameter to avoid sharing of user specific token

SDK/ComparisonOperatorHelper.lua

Lines changed: 1 addition & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ local model = {
44
evaluate = function(opt, isNegative, isIgnoreCase, value, valueToCompare, valuesToCompare)
55
-- Private functions
66
local function contains(value, valueToCompare, isNegative, ignoreCase)
7-
if (valueToCompare == "*") then
7+
if (valueToCompare == "*" and (not utils.isNilOrEmpty(value))) then
88
return true
99
end
1010

@@ -55,37 +55,6 @@ local model = {
5555

5656
return isNegative
5757
end
58-
59-
local function endsWith(value, valueToCompare, isNegative, ignoreCase)
60-
if (ignoreCase) then
61-
value = string.upper(value)
62-
valueToCompare = string.upper(valueToCompare)
63-
end
64-
65-
local evaluation = utils.endsWith(value, valueToCompare)
66-
67-
if (isNegative) then
68-
return not evaluation
69-
else
70-
return evaluation
71-
end
72-
end
73-
74-
local function startsWith(value, valueToCompare, isNegative, ignoreCase)
75-
if (ignoreCase) then
76-
value = string.upper(value)
77-
valueToCompare = string.upper(valueToCompare)
78-
end
79-
80-
local evaluation = utils.startsWith(value, valueToCompare)
81-
82-
if (isNegative) then
83-
return not evaluation
84-
else
85-
return evaluation
86-
end
87-
end
88-
8958
if (value == nil) then
9059
value = ""
9160
end
@@ -102,12 +71,6 @@ local model = {
10271
if (opt == "Contains") then
10372
return contains(value, valueToCompare, isNegative, isIgnoreCase)
10473
end
105-
if (opt == "StartsWith") then
106-
return startsWith(value, valueToCompare, isNegative, isIgnoreCase)
107-
end
108-
if (opt == "EndsWith") then
109-
return endsWith(value, valueToCompare, isNegative, isIgnoreCase)
110-
end
11174
if (opt == "EqualsAny") then
11275
return equalsAny(value, valuesToCompare, isNegative, isIgnoreCase)
11376
end

SDK/IntegrationEvaluator.lua

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ local model = {
3737
if (utils.isTable(triggerPart) == false) then
3838
return false
3939
end
40-
4140
if (evaluateTriggerPart(triggerPart, currentPageUrl, request)) then
4241
return true
4342
end
@@ -48,7 +47,6 @@ local model = {
4847
if (utils.isTable(triggerPart) == false) then
4948
return false
5049
end
51-
5250
if (evaluateTriggerPart(triggerPart, currentPageUrl, request) == false) then
5351
return false
5452
end

0 commit comments

Comments
 (0)