Piped login: tolerate duplicate nonce query param (array values), idempotent replay of the just-issued login
This commit is contained in:
1 parent
a79e820f2d
commit
da85f182bb
3 files changed
+46
-6
No files matched your search
@@ -40,7 +40,7 @@ requires_widevine_version=1.0
|
|||||||
playlet_lib_squashfs_remote_url=https://github.com/iBicha/playlet/releases/latest/download/playlet-lib.squashfs.pkg
|
playlet_lib_squashfs_remote_url=https://github.com/iBicha/playlet/releases/latest/download/playlet-lib.squashfs.pkg
|
||||||
playlet_lib_zip_remote_url=https://github.com/iBicha/playlet/releases/latest/download/playlet-lib.zip
|
playlet_lib_zip_remote_url=https://github.com/iBicha/playlet/releases/latest/download/playlet-lib.zip
|
||||||
playlet_lib_zip_embedded_url=pkg:/lib/playlet-lib.zip
|
playlet_lib_zip_embedded_url=pkg:/lib/playlet-lib.zip
|
||||||
playlet_lib_zip_debug_url=https://gitea.spaghet.io/spaghet/playlet-piped/raw/branch/main/piped/playlet-lib-1795490592.zip
|
playlet_lib_zip_debug_url=https://gitea.spaghet.io/spaghet/playlet-piped/raw/branch/main/piped/playlet-lib-1795491297.zip
|
||||||
|
|
||||||
git_commit_sha=unknown
|
git_commit_sha=unknown
|
||||||
|
|
||||||
|
|||||||
@@ -129,7 +129,7 @@ namespace Http
|
|||||||
end function
|
end function
|
||||||
|
|
||||||
function LibBuildTag() as string
|
function LibBuildTag() as string
|
||||||
return "PIPED-LIB-18"
|
return "PIPED-LIB-19"
|
||||||
end function
|
end function
|
||||||
|
|
||||||
function FetchJson(path as string, params = invalid as object) as dynamic
|
function FetchJson(path as string, params = invalid as object) as dynamic
|
||||||
|
|||||||
@@ -145,6 +145,34 @@ namespace Http
|
|||||||
m.loginNonceSlot = (m.loginNonceSlot + 1) mod 4
|
m.loginNonceSlot = (m.loginNonceSlot + 1) mod 4
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
' The gate script appends token+nonce to the cb URL while the cb
|
||||||
|
' template already carries a nonce, so the callback can arrive with
|
||||||
|
' the key twice; Playlet's query parser turns duplicate keys into an
|
||||||
|
' ARRAY and ValidString(array) is "" -> the nonce looked unknown.
|
||||||
|
function FirstStr(v as dynamic) as string
|
||||||
|
if GetInterface(v, "ifArray") <> invalid
|
||||||
|
if v.Count() > 0
|
||||||
|
return ValidString(v[0])
|
||||||
|
end if
|
||||||
|
return ""
|
||||||
|
end if
|
||||||
|
return ValidString(v)
|
||||||
|
end function
|
||||||
|
|
||||||
|
function ReadLastSession() as string
|
||||||
|
reg = CreateObject("roRegistrySection", "piped_login")
|
||||||
|
if reg.Exists("current")
|
||||||
|
return reg.Read("current")
|
||||||
|
end if
|
||||||
|
return ""
|
||||||
|
end function
|
||||||
|
|
||||||
|
function WriteLastSession(sessionUuid as string) as void
|
||||||
|
reg = CreateObject("roRegistrySection", "piped_login")
|
||||||
|
reg.Write("current", sessionUuid)
|
||||||
|
reg.Flush()
|
||||||
|
end function
|
||||||
|
|
||||||
function SetLoggedInProfile(username as string, sessionUuid as string) as void
|
function SetLoggedInProfile(username as string, sessionUuid as string) as void
|
||||||
instance = m.GetInstance()
|
instance = m.GetInstance()
|
||||||
port = Str(m.server.task.port).Replace(" ", "")
|
port = Str(m.server.task.port).Replace(" ", "")
|
||||||
@@ -201,7 +229,7 @@ namespace Http
|
|||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
reqNonce = ValidString(request.query.nonce)
|
reqNonce = m.FirstStr(request.query.nonce)
|
||||||
if reqNonce <> ""
|
if reqNonce <> ""
|
||||||
' The phone clicked the link the login page handed out; keep
|
' The phone clicked the link the login page handed out; keep
|
||||||
' that nonce valid for the callback this redirect starts,
|
' that nonce valid for the callback this redirect starts,
|
||||||
@@ -248,7 +276,7 @@ namespace Http
|
|||||||
fields = m.ParseFormBody(ValidString(request.BodyText()))
|
fields = m.ParseFormBody(ValidString(request.BodyText()))
|
||||||
username = ValidString(fields.username)
|
username = ValidString(fields.username)
|
||||||
password = ValidString(fields.password)
|
password = ValidString(fields.password)
|
||||||
nonce = ValidString(fields.nonce)
|
nonce = m.FirstStr(fields.nonce)
|
||||||
|
|
||||||
if nonce <> "" and m.KnownNonceIdx(nonce) < 0
|
if nonce <> "" and m.KnownNonceIdx(nonce) < 0
|
||||||
response.Default(400, m.ErrorPage(`Stale login page. <a href="/piped/login">Start again</a>`))
|
response.Default(400, m.ErrorPage(`Stale login page. <a href="/piped/login">Start again</a>`))
|
||||||
@@ -313,8 +341,8 @@ namespace Http
|
|||||||
request = context.request
|
request = context.request
|
||||||
response = context.response
|
response = context.response
|
||||||
|
|
||||||
token = ValidString(request.query.token)
|
token = m.FirstStr(request.query.token)
|
||||||
nonce = ValidString(request.query.nonce)
|
nonce = m.FirstStr(request.query.nonce)
|
||||||
|
|
||||||
if StringUtils.IsNullOrEmpty(token)
|
if StringUtils.IsNullOrEmpty(token)
|
||||||
response.Default(400, m.ErrorPage("Missing token."))
|
response.Default(400, m.ErrorPage("Missing token."))
|
||||||
@@ -324,6 +352,17 @@ namespace Http
|
|||||||
' rolling window above). Consume it so each link is single-use.
|
' rolling window above). Consume it so each link is single-use.
|
||||||
idx = m.KnownNonceIdx(nonce)
|
idx = m.KnownNonceIdx(nonce)
|
||||||
if idx < 0
|
if idx < 0
|
||||||
|
' A consumed nonce arriving with the SAME session we just
|
||||||
|
' installed is a retry/replay of a login that already
|
||||||
|
' succeeded (the gate script can bounce the phone twice) -
|
||||||
|
' show success, not an error the user cannot act on.
|
||||||
|
if nonce <> "" and token = m.ReadLastSession()
|
||||||
|
response.http_code = 200
|
||||||
|
response.headers["Cache-Control"] = "no-store, max-age=0"
|
||||||
|
response.ContentType("text/html")
|
||||||
|
response.SetBodyDataString(m.PageShell("Signed in", m.SuccessBody(m.LookupUsername(token))))
|
||||||
|
return true
|
||||||
|
end if
|
||||||
response.Default(403, m.ErrorPage(`Login link expired or already used. <a href="/piped/login">Start again</a>`))
|
response.Default(403, m.ErrorPage(`Login link expired or already used. <a href="/piped/login">Start again</a>`))
|
||||||
return true
|
return true
|
||||||
end if
|
end if
|
||||||
@@ -335,6 +374,7 @@ namespace Http
|
|||||||
username = m.LookupUsername(token)
|
username = m.LookupUsername(token)
|
||||||
|
|
||||||
m.SetLoggedInProfile(username, token)
|
m.SetLoggedInProfile(username, token)
|
||||||
|
m.WriteLastSession(token)
|
||||||
|
|
||||||
response.http_code = 200
|
response.http_code = 200
|
||||||
response.headers["Cache-Control"] = "no-store, max-age=0"
|
response.headers["Cache-Control"] = "no-store, max-age=0"
|
||||||
|
|||||||
Reference in new issue
Block a user