-
Notifications
You must be signed in to change notification settings - Fork 324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Leave domain empty in cookies, but account for clients with old cookies. #1102
Changes from all commits
7aefaa3
b19fe6a
531cda3
860b2dc
3d47172
e17422e
e7667ad
a28e83e
f2aaa21
649cecc
6841dff
b94c80e
b05e536
d2b5d65
23d29b8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -410,8 +410,6 @@ data Settings = Settings | |
setUserMaxConnections :: !Int64, | ||
-- | Max. number of permanent clients per user | ||
setUserMaxPermClients :: !(Maybe Int), | ||
-- | The domain to restrict cookies to | ||
setCookieDomain :: !Text, | ||
-- | Whether to allow plain HTTP transmission | ||
-- of cookies (for testing purposes only) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You removed the wrong comment There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
setCookieInsecure :: !Bool, | ||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -60,7 +60,9 @@ import Control.Lens (to, view) | |||||
import Data.ByteString.Conversion (toByteString) | ||||||
import Data.Handle (Handle) | ||||||
import Data.Id | ||||||
import Data.List1 (singleton) | ||||||
import qualified Data.List.NonEmpty as NE | ||||||
import Data.List1 (List1) | ||||||
import qualified Data.List1 as List1 | ||||||
import Data.Misc (PlainTextPassword (..)) | ||||||
import qualified Data.ZAuth.Token as ZAuth | ||||||
import Imports | ||||||
|
@@ -152,18 +154,18 @@ withRetryLimit action uid = do | |||||
BudgetExhausted ttl -> throwE . LoginBlocked . RetryAfter . floor $ ttl | ||||||
BudgetedValue () _ -> pure () | ||||||
|
||||||
logout :: ZAuth.TokenPair u a => ZAuth.Token u -> ZAuth.Token a -> ExceptT ZAuth.Failure AppIO () | ||||||
logout ut at = do | ||||||
(u, ck) <- validateTokens ut (Just at) | ||||||
logout :: ZAuth.TokenPair u a => List1 (ZAuth.Token u) -> ZAuth.Token a -> ExceptT ZAuth.Failure AppIO () | ||||||
logout uts at = do | ||||||
(u, ck) <- validateTokens uts (Just at) | ||||||
lift $ revokeCookies u [cookieId ck] [] | ||||||
|
||||||
renewAccess :: | ||||||
ZAuth.TokenPair u a => | ||||||
ZAuth.Token u -> | ||||||
List1 (ZAuth.Token u) -> | ||||||
Maybe (ZAuth.Token a) -> | ||||||
ExceptT ZAuth.Failure AppIO (Access u) | ||||||
renewAccess ut at = do | ||||||
(uid, ck) <- validateTokens ut at | ||||||
renewAccess uts at = do | ||||||
(uid, ck) <- validateTokens uts at | ||||||
Log.debug $ field "user" (toByteString uid) . field "action" (Log.val "User.renewAccess") | ||||||
catchSuspendInactiveUser uid ZAuth.Expired | ||||||
ck' <- lift $ nextCookie ck | ||||||
|
@@ -192,7 +194,7 @@ catchSuspendInactiveUser uid errval = do | |||||
msg (val "Suspending user due to inactivity") | ||||||
~~ field "user" (toByteString uid) | ||||||
~~ field "action" ("user.suspend" :: String) | ||||||
lift $ suspendAccount (singleton uid) | ||||||
lift $ suspendAccount (List1.singleton uid) | ||||||
throwE errval | ||||||
|
||||||
newAccess :: forall u a. ZAuth.TokenPair u a => UserId -> CookieType -> Maybe CookieLabel -> ExceptT LoginError AppIO (Access u) | ||||||
|
@@ -252,12 +254,32 @@ isPendingActivation ident = case ident of | |||||
Just SSOIdentity {} -> False -- sso-created users are activated immediately. | ||||||
Nothing -> True | ||||||
|
||||||
-- | Validate a list of (User/LH) tokens potentially with an associated access token. | ||||||
-- If there are multiple valid cookies, we try all of them. When an access token is | ||||||
-- given, we perform the usual checks. | ||||||
-- If multiple cookies are given and several are valid, we return the first valid one. | ||||||
validateTokens :: | ||||||
ZAuth.TokenPair u a => | ||||||
List1 (ZAuth.Token u) -> | ||||||
Maybe (ZAuth.Token a) -> | ||||||
ExceptT ZAuth.Failure AppIO (UserId, Cookie (ZAuth.Token u)) | ||||||
validateTokens uts at = do | ||||||
tiago-loureiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
tokens <- forM uts $ \ut -> lift $ runExceptT (validateToken ut at) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We discussed it f2f; the reason is that we don't want to fail right away so the logic is correct. Will try to tackle the previous point as a cleanup. |
||||||
getFirstSuccessOrFirstFail tokens | ||||||
where | ||||||
-- FUTUREWORK: There is surely a better way to do this | ||||||
getFirstSuccessOrFirstFail :: List1 (Either ZAuth.Failure (UserId, Cookie (ZAuth.Token u))) -> ExceptT ZAuth.Failure AppIO (UserId, Cookie (ZAuth.Token u)) | ||||||
tiago-loureiro marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
getFirstSuccessOrFirstFail tks = case (lefts $ NE.toList $ List1.toNonEmpty tks, rights $ NE.toList $ List1.toNonEmpty tks) of | ||||||
(_, (suc : _)) -> return suc | ||||||
((e : _), _) -> throwE e | ||||||
_ -> throwE ZAuth.Invalid -- Impossible | ||||||
|
||||||
validateToken :: | ||||||
ZAuth.TokenPair u a => | ||||||
ZAuth.Token u -> | ||||||
Maybe (ZAuth.Token a) -> | ||||||
ExceptT ZAuth.Failure AppIO (UserId, Cookie (ZAuth.Token u)) | ||||||
validateTokens ut at = do | ||||||
validateToken ut at = do | ||||||
unless (maybe True ((ZAuth.userTokenOf ut ==) . ZAuth.accessTokenOf) at) $ | ||||||
throwE ZAuth.Invalid | ||||||
ExceptT (ZAuth.validateToken ut) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move this to integration.yaml
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need.