Skip to content

Commit bcd2a9a

Browse files
committed
Release 3.6.4
1 parent ec1e04f commit bcd2a9a

21 files changed

Lines changed: 1849 additions & 1260 deletions

Examples/ApacheHandlerUsingConfigFromFile.lua

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,11 @@
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
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
1919
-- e.g. not JS Hybrid.
20-
-- * QUEUEIT_COOKIE_OPTIONS_SECURE: (optional) Set to "true" if you want cookies with secure
20+
-- * QUEUEIT_COOKIE_OPTIONS_SECURE: (optional) Set to "true" if you want cookies with secure
2121
-- flag set. Only enable if your website runs purely on https.
22-
-- * QUEUEIT_COOKIE_OPTIONS_SAMESITE: (optional) set to any of these values
23-
-- "none", "strict" or "lax" if response cookies should have samesite flag set.
24-
-- only use 'strict' if your queue protected site stays on same domain (no navigation to subdomains).
2522
-- Note that the integration configuration is read on every request. The JSON file containing
2623
-- The integration configuration should, for performance reasons, be available locally.
2724
--
@@ -35,7 +32,6 @@
3532
-- SetEnv QUEUEIT_ERROR_CODE "400"
3633
-- SetEnv QUEUEIT_COOKIE_OPTIONS_HTTPONLY "false"
3734
-- SetEnv QUEUEIT_COOKIE_OPTIONS_SECURE "false"
38-
-- SetEnv QUEUEIT_COOKIE_OPTIONS_SAMESITE "none"
3935
-- LuaMapHandler "{URI_PATTERN}" "{APP_FOLDER}/Handlers/ApacheHandlerUsingConfigFromFile.lua"
4036
-- LuaPackagePath "{APP_FOLDER}/SDK/?.lua"
4137
-- LuaPackagePath "{APP_FOLDER}/Helpers/?/?.lua"
@@ -58,10 +54,9 @@ local function initRequiredHelpers(r, cookieOptions)
5854
local iHelpers = require("KnownUserImplementationHelpers")
5955

6056
iHelpers.request.getAbsoluteUri = function()
61-
local fullUrl = string.format("%s://%s:%s%s",
57+
local fullUrl = string.format("%s://%s%s",
6258
r.is_https and "https" or "http",
6359
r.hostname,
64-
r.port,
6560
r.unparsed_uri)
6661
r:debug(string.format("[%s] Rebuilt request URL as: %s", DEBUG_TAG, fullUrl))
6762
return fullUrl
@@ -78,23 +73,21 @@ function handle(r)
7873
-- catch errors if any occur
7974
local success, result = pcall(function()
8075

81-
-- get configuration from environment variables
76+
-- get configuration from environment variables
8277
local customerId = r.subprocess_env["QUEUEIT_CUSTOMER_ID"]
8378
local secretKey = r.subprocess_env["QUEUEIT_SECRET_KEY"]
8479
local intConfFile = r.subprocess_env["QUEUEIT_INT_CONF_FILE"]
85-
local errorCode = r.subprocess_env["QUEUEIT_ERROR_CODE"]
80+
local errorCode = r.subprocess_env["QUEUEIT_ERROR_CODE"]
8681
local co_httpOnly = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_HTTPONLY"]
8782
local co_secure = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_SECURE"]
88-
local co_sameSite = r.subprocess_env["QUEUEIT_COOKIE_OPTIONS_SAMESITE"]
89-
83+
9084
r:debug(string.format("[%s] Environment variable QUEUEIT_CUSTOMER_ID: %s", DEBUG_TAG, customerId))
9185
r:debug(string.format("[%s] Environment variable QUEUEIT_SECRET_KEY: %s", DEBUG_TAG, secretKey))
9286
r:debug(string.format("[%s] Environment variable QUEUEIT_INT_CONF_FILE: %s", DEBUG_TAG, intConfFile))
9387
r:debug(string.format("[%s] Environment variable QUEUEIT_ERROR_CODE: %s", DEBUG_TAG, errorCode))
9488
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_HTTPONLY: %s", DEBUG_TAG, co_httpOnly))
9589
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_SECURE: %s", DEBUG_TAG, co_secure))
96-
r:debug(string.format("[%s] Environment variable QUEUEIT_COOKIE_OPTIONS_SAMESITE: %s", DEBUG_TAG, co_sameSite))
97-
90+
9891
assert(customerId ~= nil, "customerId invalid")
9992
assert(secretKey ~= nil, "secretKey invalid")
10093
assert(intConfFile ~= nil, "config invalid")
@@ -103,24 +96,24 @@ function handle(r)
10396
if (errorCode ~= nil) then
10497
errorCode = tonumber(errorCode)
10598
if (errorCode == nil) then
106-
r:warn(string.format("[%s] Value of QUEUEIT_ERROR_CODE is not a valid HTTP status code: %s", DEBUG_TAG, r.subprocess_env["QUEUEIT_ERROR_CODE"]))
99+
r:warn(string.format(
100+
"[%s] Value of QUEUEIT_ERROR_CODE is not a valid HTTP status code: %s",
101+
DEBUG_TAG, r.subprocess_env["QUEUEIT_ERROR_CODE"]))
107102
elseif (errorCode >= 100) and (errorCode < 600) then
108103
errorResult = errorCode
109104
end
110105
end
111106
r:debug(string.format("[%s] Value of variable errorCode: %s", DEBUG_TAG, errorCode))
112107

113108
-- configure cookie options
114-
local cookieOptions =
109+
local cookieOptions =
115110
{
116111
httpOnly = false,
117-
secure = false,
118-
sameSite = nil
112+
secure = false
119113
}
120-
114+
121115
if (co_httpOnly ~= nil and co_httpOnly == 'true') then cookieOptions.httpOnly = true end
122116
if (co_secure ~= nil and co_secure == 'true') then cookieOptions.secure = true end
123-
if (co_sameSite ~= nil and (co_sameSite == 'none' or co_sameSite == 'lax' or co_sameSite == 'strict' )) then cookieOptions.sameSite = co_sameSite end
124117

125118
-- initialize helper functions
126119
initRequiredHelpers(r, cookieOptions)

Handlers/KnownUserApacheHandler.lua

Lines changed: 46 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
iHelpers = require("KnownUserImplementationHelpers")
2-
knownUser = require("KnownUser")
3-
utils = require("Utils")
1+
local iHelpers = require("KnownUserImplementationHelpers")
2+
local knownUser = require("KnownUser")
3+
local utils = require("Utils")
44

55
local aHandler = {}
66

@@ -9,10 +9,10 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
99
assert(secretKey ~= nil, "secretKey invalid")
1010
assert(config ~= nil, "config invalid")
1111
assert(isIntegrationConfig ~= nil, "isIntegrationConfig invalid")
12-
assert(request_rec ~= nil, "request_rec invalid")
13-
12+
assert(request_rec ~= nil, "request_rec invalid")
13+
1414
-- Implement required helpers
15-
-- ********************************************************************************
15+
-- ********************************************************************************
1616
iHelpers.system.getConnectorName = function()
1717
return apache2.version
1818
end
@@ -21,72 +21,72 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
2121
local json = require("json")
2222
return json.parse(jsonStr)
2323
end
24-
24+
2525
iHelpers.hash.hmac_sha256_encode = function(message, key)
2626
local sha2 = require("sha2")
2727
return sha2.hmac(sha2.sha256, key, message)
2828
end
29-
29+
3030
iHelpers.request.getHeader = function(name)
3131
return request_rec.headers_in[name]
3232
end
33-
33+
3434
iHelpers.request.getUnescapedCookieValue = function(name)
35-
-- Alternative to request_rec:getcookie method,
35+
-- Alternative to request_rec:getcookie method,
3636
-- which fails if client sends a Cookie header with multiple entries with same name/key.
37-
local function getCookieValue(name)
38-
local function split(inputstr, sep)
39-
sep=sep or '%s' local t={}
40-
for field,s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do
41-
table.insert(t,field)
42-
if s=="" then
43-
return t
44-
end
45-
end
37+
local function getCookieValue(_name)
38+
local function split(inputstr, sep)
39+
sep=sep or '%s' local t={}
40+
for field,s in string.gmatch(inputstr, "([^"..sep.."]*)("..sep.."?)") do
41+
table.insert(t,field)
42+
if s=="" then
43+
return t
44+
end
45+
end
4646
end
47-
48-
if (name == nil) then
47+
48+
if (_name == nil) then
4949
return nil
5050
end
5151

5252
local cookieHeader = request_rec.headers_in["Cookie"]
53-
53+
5454
if(cookieHeader == nil) then
5555
return nil
5656
end
57-
57+
5858
local cookieHeaderParts = split(cookieHeader, ";")
59-
59+
6060
if (cookieHeaderParts == nil) then
6161
return nil
6262
end
63-
63+
6464
-- Translate name to pattern so it will work correctly in string.find
65-
-- ex. translate 'QueueITAccepted-SDFrts345E-V3_event1' to 'QueueITAccepted--SDFrts345E--V3_event1='
66-
name = name:gsub("-", "--") .. "="
67-
68-
for k, v in pairs(cookieHeaderParts) do
69-
startIndex, endIndex = string.find(v, name)
70-
65+
-- ex. translate 'QueueITAccepted-SDFrts345E-V3_event1' to 'QueueITAccepted--SDFrts345E--V3_event1='
66+
_name = _name:gsub("-", "--") .. "="
67+
68+
for _, v in pairs(cookieHeaderParts) do
69+
local _, endIndex = string.find(v, _name)
70+
7171
if(endIndex ~= nil) then
7272
return v:sub(endIndex + 1)
7373
end
7474
end
7575
end
76-
76+
7777
local cookieValue = getCookieValue(name)
78-
78+
7979
if (cookieValue ~= nil) then
8080
cookieValue = utils.urlDecode(cookieValue)
8181
end
8282

8383
return cookieValue
8484
end
85-
85+
8686
iHelpers.request.getUserHostAddress = function()
8787
return request_rec.useragent_ip
8888
end
89-
89+
9090
-- Implementation is not using built in r:setcookie method
9191
-- because we want to support Apache version < 2.4.12
9292
-- where there is bug in that specific method
@@ -98,51 +98,50 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
9898
if (domain == nil) then
9999
domain = ""
100100
end
101-
101+
102102
if (value == nil) then
103103
value = ""
104104
end
105-
105+
106106
value = utils.urlEncode(value)
107107

108108
local expire_text = ''
109109
if expire ~= nil and type(expire) == "number" and expire > 0 then
110110
expire_text = '; Expires=' .. os.date("!%a, %d %b %Y %H:%M:%S GMT", expire)
111111
end
112112

113-
request_rec.err_headers_out["Set-Cookie"] = name .. '=' .. value
113+
request_rec.err_headers_out["Set-Cookie"] = name .. '=' .. value
114114
.. expire_text
115-
.. (domain ~= "" and '; Domain=' .. domain or '')
115+
.. (domain ~= "" and '; Domain=' .. domain or '')
116116
.. (iHelpers.response.cookieOptions.httpOnly and '; HttpOnly' or '')
117117
.. (iHelpers.response.cookieOptions.secure and '; Secure' or '')
118-
.. (iHelpers.response.cookieOptions.sameSite and '; SameSite=' .. iHelpers.response.cookieOptions.sameSite or '')
119118
.. '; Path=/;'
120-
119+
121120
end
122121
-- ********************************************************************************
123122
-- END Implement required helpers
124123

125124
local queueitToken = request_rec:parseargs()["queueittoken"]
126125
local fullUrl = iHelpers.request.getAbsoluteUri()
127-
local currentUrlWithoutQueueitToken = fullUrl:gsub("([\\%?%&])(" .. knownUser.QUEUEIT_TOKEN_KEY .. "=[^&]*)", "")
126+
local currentUrlWithoutQueueitToken = fullUrl:gsub("([\\%?%&])(" .. knownUser.QUEUEIT_TOKEN_KEY .. "=[^&]*)", "")
128127

129-
local validationResult = nil
128+
local validationResult
130129
if (isIntegrationConfig) then
131130
validationResult = knownUser.validateRequestByIntegrationConfig(currentUrlWithoutQueueitToken, queueitToken, config, customerId, secretKey)
132131
else
133132
validationResult = knownUser.resolveQueueRequestByLocalConfig(currentUrlWithoutQueueitToken, queueitToken, config, customerId, secretKey)
134133
end
135-
134+
136135
if (validationResult:doRedirect()) then
137136
--Adding no cache headers to prevent browsers to cache requests
138137
request_rec.err_headers_out["Cache-Control"] = "no-cache, no-store, must-revalidate, max-age=0"
139138
request_rec.err_headers_out["Pragma"] = "no-cache"
140139
request_rec.err_headers_out["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
141140
--end
142-
141+
143142
if (validationResult.isAjaxResult) then
144143
request_rec.err_headers_out[validationResult.getAjaxQueueRedirectHeaderKey()] = validationResult:getAjaxRedirectUrl()
145-
else
144+
else
146145
request_rec.err_headers_out["Location"] = validationResult.redirectUrl
147146
return apache2.HTTP_MOVED_TEMPORARILY
148147
end
@@ -153,7 +152,7 @@ local function handle(customerId, secretKey, config, isIntegrationConfig, reques
153152
return apache2.HTTP_MOVED_TEMPORARILY
154153
end
155154
end
156-
155+
157156
return apache2.DECLINED
158157
end
159158

0 commit comments

Comments
 (0)