mirror of
https://github.com/YunoHost/SSOwat.git
synced 2024-09-03 20:06:27 +02:00
security: Also check client-provided auth headers to prevent impersonation
This commit is contained in:
parent
7fc0350788
commit
1f56a08621
1 changed files with 3 additions and 4 deletions
|
@ -256,14 +256,14 @@ function refresh_logged_in()
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
-- If client set the `Proxy-Authorization` header before reaching the SSO,
|
-- If client set the Authorization/Proxy-Authorization header before reaching the SSO,
|
||||||
-- we want to match user and password against the user database.
|
-- we want to match user and password against the user database.
|
||||||
--
|
--
|
||||||
-- It allows to bypass the cookie-based procedure with a per-request
|
-- It allows to bypass the cookie-based procedure with a per-request
|
||||||
-- authentication. This is useful to authenticate on the SSO during
|
-- authentication. This is useful to authenticate on the SSO during
|
||||||
-- curl requests for example.
|
-- curl requests for example.
|
||||||
|
|
||||||
local auth_header = ngx.req.get_headers()["Proxy-Authorization"]
|
local auth_header = ngx.req.get_headers()["Authorization"] or ngx.req.get_headers()["Proxy-Authorization"]
|
||||||
|
|
||||||
if auth_header then
|
if auth_header then
|
||||||
_, _, b64_cred = string.find(auth_header, "^Basic%s+(.+)$")
|
_, _, b64_cred = string.find(auth_header, "^Basic%s+(.+)$")
|
||||||
|
@ -277,8 +277,7 @@ function refresh_logged_in()
|
||||||
authUser = user
|
authUser = user
|
||||||
is_logged_in = true
|
is_logged_in = true
|
||||||
else
|
else
|
||||||
-- https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/407
|
return ngx.exit(ngx.HTTP_UNAUTHORIZED)
|
||||||
ngx.status = 407
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue