Skip to content

Commit 74fc770

Browse files
committed
Release 2.21
1 parent d006e52 commit 74fc770

File tree

5 files changed

+33
-52
lines changed

5 files changed

+33
-52
lines changed

Changes.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,22 @@
22

33
All notable changes to `lua-resty-session` will be documented in this file.
44

5+
## [2.21] - 2018-03-16
6+
### Screwed
7+
- Forgot to bump version number.
8+
9+
## [2.20] - 2018-03-16
10+
### Fixed
11+
- Fixes issue where check addr and check scheme could be faked.
12+
See also: https://github.com/bungle/lua-resty-session/issues/47
13+
Thanks @nielsole
14+
515
## [2.19] - 2017-09-19
616
### Fixed
717
- Fixes small bug where aes could generate invalid salt on invalid input
818
that further crashes Lua with error: bad argument #2 to 'salt' (number
919
expected, got no value)
1020

11-
1221
## [2.18] - 2017-07-10
1322
### Fixed
1423
- Automatically creates exactly 64 bits salt as required by the latest

lib/resty/session.lua

+11-39
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ local function setcookie(session, value, expires)
9393
else
9494
n[2] = "="
9595
end
96-
local n = concat(n)
96+
n = concat(n)
9797
k[1] = n
9898
if expires then
9999
k[2] = ""
@@ -110,9 +110,9 @@ local function setcookie(session, value, expires)
110110
if t == "table" then
111111
local f = false
112112
local z = #s
113-
for i=1, z do
114-
if find(s[i], n, 1, true) == 1 then
115-
s[i] = y
113+
for a=1, z do
114+
if find(s[a], n, 1, true) == 1 then
115+
s[a] = y
116116
f = true
117117
break
118118
end
@@ -203,7 +203,7 @@ local function init()
203203
end
204204

205205
local session = {
206-
_VERSION = "2.19"
206+
_VERSION = "2.21"
207207
}
208208

209209
session.__index = session
@@ -267,41 +267,13 @@ function session.open(opts)
267267
else
268268
self = session.new(opts)
269269
end
270-
local scheme = header["X-Forwarded-Proto"]
271-
if self.cookie.secure == nil then
272-
if scheme then
273-
self.cookie.secure = scheme == "https"
274-
else
275-
self.cookie.secure = var.https == "on"
276-
end
277-
end
278-
scheme = self.check.scheme and (scheme or var.scheme or "") or ""
279-
local addr = ""
280-
if self.check.addr then
281-
addr = header["CF-Connecting-IP"] or
282-
header["Fastly-Client-IP"] or
283-
header["Incap-Client-IP"] or
284-
header["X-Real-IP"]
285-
if not addr then
286-
addr = header["X-Forwarded-For"]
287-
if addr then
288-
-- We shouldn't really get the left-most address, because of spoofing,
289-
-- but this is better handled with a module, like nginx realip module,
290-
-- anyway (see also: http://goo.gl/Z6u2oR).
291-
local s = find(addr, ',', 1, true)
292-
if s then
293-
addr = addr:sub(1, s - 1)
294-
end
295-
else
296-
addr = var.remote_addr
297-
end
298-
end
299-
end
270+
271+
self.cookie.secure = var.scheme == "https" or var.https == "on"
300272
self.key = concat{
301-
self.check.ssi and (var.ssl_session_id or "") or "",
302-
self.check.ua and (var.http_user_agent or "") or "",
303-
addr,
304-
scheme
273+
self.check.ssi and var.ssl_session_id or "",
274+
self.check.ua and var.http_user_agent or "",
275+
self.check.addr and var.remote_addr or "",
276+
self.check.scheme and var.scheme or "",
305277
}
306278
self.opened = true
307279
local cookie = getcookie(self)

lib/resty/session/ciphers/none.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@ function cipher.new()
1111
return singleton
1212
end
1313

14-
function cipher:encrypt(d)
14+
function cipher.encrypt(_, d)
1515
return d
1616
end
1717

18-
function cipher:decrypt(d)
18+
function cipher.decrypt(_, d)
1919
return d
2020
end
2121

22-
return cipher
22+
return cipher

lib/resty/session/storage/cookie.lua

+3-3
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ function cookie:cookie(c)
3232
return r
3333
end
3434

35-
function cookie:open(cookie)
36-
local r = self:cookie(cookie)
35+
function cookie:open(c)
36+
local r = self:cookie(c)
3737
if r and r[1] and r[2] and r[3] and r[4] then
3838
return self.decode(r[1]), tonumber(r[2]), self.decode(r[3]), self.decode(r[4])
3939
end
@@ -44,4 +44,4 @@ function cookie:save(i, e, d, h)
4444
return concat({ self.encode(i), e, self.encode(d), self.encode(h) }, self.delimiter)
4545
end
4646

47-
return cookie
47+
return cookie

lib/resty/session/storage/redis.lua

+6-6
Original file line numberDiff line numberDiff line change
@@ -65,17 +65,17 @@ function redis.new(config)
6565
end
6666

6767
function redis:connect()
68-
local redis = self.redis
68+
local r = self.redis
6969
local ok, err
7070
if self.socket then
71-
ok, err = redis:connect(self.socket)
71+
ok, err = r:connect(self.socket)
7272
else
73-
ok, err = redis:connect(self.host, self.port)
73+
ok, err = r:connect(self.host, self.port)
7474
end
7575
if ok and self.auth then
76-
ok, err = redis:get_reused_times()
76+
ok, err = r:get_reused_times()
7777
if ok == 0 then
78-
ok, err = redis:auth(self.auth)
78+
ok, err = r:auth(self.auth)
7979
end
8080
end
8181
return ok, err
@@ -229,4 +229,4 @@ function redis:destroy(i)
229229
return ok, err
230230
end
231231

232-
return redis
232+
return redis

0 commit comments

Comments
 (0)