Skip to content

Commit acaa902

Browse files
committed
Fixed #24: An exception nil value (local 'origin') is thrown when an OPTIONS request is sent that is not a CORS preflight request (which does not include an Options header).
1 parent f534376 commit acaa902

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

example/haproxy/cors.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ function cors_request(txn, allowed_methods, allowed_origins, allowed_headers)
108108
core.Debug("CORS: Got 'Origin' header: " .. headers["origin"][0])
109109
origin = headers["origin"][0]
110110
end
111+
112+
-- Bail if client did not send an Origin
113+
-- for example, it may be a regular OPTIONS request that is not a CORS preflight request
114+
if origin == nil or origin == '' then
115+
return
116+
end
111117

112118
transaction_data["origin"] = origin
113119
transaction_data["allowed_methods"] = allowed_methods

lib/cors.lua

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,12 @@ function cors_request(txn, allowed_methods, allowed_origins, allowed_headers)
108108
core.Debug("CORS: Got 'Origin' header: " .. headers["origin"][0])
109109
origin = headers["origin"][0]
110110
end
111+
112+
-- Bail if client did not send an Origin
113+
-- for example, it may be a regular OPTIONS request that is not a CORS preflight request
114+
if origin == nil or origin == '' then
115+
return
116+
end
111117

112118
transaction_data["origin"] = origin
113119
transaction_data["allowed_methods"] = allowed_methods

0 commit comments

Comments
 (0)