fix(tokens): introduce clock leniency and remove start for downloads
This commit is contained in:
parent
0ea4eec840
commit
8939a8b90a
@ -179,9 +179,13 @@ server-sessions:
|
|||||||
absolute-timeout: 604801
|
absolute-timeout: 604801
|
||||||
timeout-resolution: 601
|
timeout-resolution: 601
|
||||||
persistent-cookies: true
|
persistent-cookies: true
|
||||||
|
session-token-start: null
|
||||||
session-token-expiration: 28807
|
session-token-expiration: 28807
|
||||||
session-token-encoding: HS256
|
session-token-encoding: HS256
|
||||||
|
|
||||||
|
session-token-clock-leniency-start: 5
|
||||||
|
bearer-token-clock-leniency-start: 5
|
||||||
|
|
||||||
cookies:
|
cookies:
|
||||||
SESSION:
|
SESSION:
|
||||||
same-site: lax
|
same-site: lax
|
||||||
|
|||||||
@ -31,12 +31,14 @@ makeSessionBackend app@UniWorX{ appSettings' = AppSettings{..}, ..} = noCreateFo
|
|||||||
-> return Nothing
|
-> return Nothing
|
||||||
where
|
where
|
||||||
cfg = JwtSession.ServerSessionJwtConfig
|
cfg = JwtSession.ServerSessionJwtConfig
|
||||||
{ sJwtJwkSet = appJSONWebKeySet
|
{ sJwtJwkSet = appJSONWebKeySet
|
||||||
, sJwtStart = Nothing
|
, sJwtStart = appSessionTokenStart
|
||||||
, sJwtExpiration = appSessionTokenExpiration
|
, sJwtExpiration = appSessionTokenExpiration
|
||||||
, sJwtEncoding = appSessionTokenEncoding
|
, sJwtEncoding = appSessionTokenEncoding
|
||||||
, sJwtIssueBy = appInstanceID
|
, sJwtIssueBy = appInstanceID
|
||||||
, sJwtIssueFor = appClusterID
|
, sJwtIssueFor = appClusterID
|
||||||
|
, sJwtClockLeniencyStart = appSessionTokenClockLeniencyStart
|
||||||
|
, sJwtClockLeniencyEnd = appSessionTokenClockLeniencyEnd
|
||||||
}
|
}
|
||||||
mkBackend :: forall sto.
|
mkBackend :: forall sto.
|
||||||
( ServerSession.SessionData sto ~ Map Text ByteString
|
( ServerSession.SessionData sto ~ Map Text ByteString
|
||||||
|
|||||||
@ -67,7 +67,7 @@ withFileDownloadTokenMaybe' mSource route = maybeT (return $ SomeRoute route) $
|
|||||||
(HashMap.singleton BearerTokenRouteAccess . HashSet.singleton $ urlRoute route)
|
(HashMap.singleton BearerTokenRouteAccess . HashSet.singleton $ urlRoute route)
|
||||||
Nothing
|
Nothing
|
||||||
(Just . Just $ addUTCTime expireOffset now)
|
(Just . Just $ addUTCTime expireOffset now)
|
||||||
(Just now)
|
Nothing
|
||||||
encodedBearer <- lift $ encodeBearer bearer
|
encodedBearer <- lift $ encodeBearer bearer
|
||||||
|
|
||||||
lift . setDownload $ SomeRoute @UniWorX route
|
lift . setDownload $ SomeRoute @UniWorX route
|
||||||
|
|||||||
@ -108,8 +108,11 @@ data AppSettings = AppSettings
|
|||||||
, appServerSessionConfig :: ServerSessionSettings
|
, appServerSessionConfig :: ServerSessionSettings
|
||||||
, appServerSessionAcidFallback :: Bool
|
, appServerSessionAcidFallback :: Bool
|
||||||
, appSessionMemcachedConf :: Maybe MemcachedConf
|
, appSessionMemcachedConf :: Maybe MemcachedConf
|
||||||
|
, appSessionTokenStart
|
||||||
, appSessionTokenExpiration :: Maybe NominalDiffTime
|
, appSessionTokenExpiration :: Maybe NominalDiffTime
|
||||||
, appSessionTokenEncoding :: JwtEncoding
|
, appSessionTokenEncoding :: JwtEncoding
|
||||||
|
, appSessionTokenClockLeniencyStart, appSessionTokenClockLeniencyEnd
|
||||||
|
, appBearerTokenClockLeniencyStart, appBearerTokenClockLeniencyEnd :: Maybe NominalDiffTime
|
||||||
|
|
||||||
, appMailObjectDomain :: Text
|
, appMailObjectDomain :: Text
|
||||||
, appMailVerp :: VerpMode
|
, appMailVerp :: VerpMode
|
||||||
@ -567,9 +570,16 @@ instance FromJSON AppSettings where
|
|||||||
httpOnlyCookie = maybe id ServerSession.setHttpOnlyCookies . cookieHttpOnly $ appCookieSettings CookieSession
|
httpOnlyCookie = maybe id ServerSession.setHttpOnlyCookies . cookieHttpOnly $ appCookieSettings CookieSession
|
||||||
secureCookie :: forall a. ServerSession.State a -> ServerSession.State a
|
secureCookie :: forall a. ServerSession.State a -> ServerSession.State a
|
||||||
secureCookie = maybe id ServerSession.setSecureCookies . cookieSecure $ appCookieSettings CookieSession
|
secureCookie = maybe id ServerSession.setSecureCookies . cookieSecure $ appCookieSettings CookieSession
|
||||||
|
appSessionTokenStart <- o .:? "session-token-start"
|
||||||
appSessionTokenExpiration <- o .:? "session-token-expiration"
|
appSessionTokenExpiration <- o .:? "session-token-expiration"
|
||||||
appSessionTokenEncoding <- o .: "session-token-encoding"
|
appSessionTokenEncoding <- o .: "session-token-encoding"
|
||||||
|
|
||||||
|
|
||||||
|
appSessionTokenClockLeniencyStart <- o .:? "session-token-clock-leniency-start"
|
||||||
|
appSessionTokenClockLeniencyEnd <- o .:? "session-token-clock-leniency-end"
|
||||||
|
appBearerTokenClockLeniencyStart <- o .:? "bearer-token-clock-leniency-start"
|
||||||
|
appBearerTokenClockLeniencyEnd <- o .:? "bearer-token-clock-leniency-end"
|
||||||
|
|
||||||
appFavouritesQuickActionsBurstsize <- o .: "favourites-quick-actions-burstsize"
|
appFavouritesQuickActionsBurstsize <- o .: "favourites-quick-actions-burstsize"
|
||||||
appFavouritesQuickActionsAvgInverseRate <- o .: "favourites-quick-actions-avg-inverse-rate"
|
appFavouritesQuickActionsAvgInverseRate <- o .: "favourites-quick-actions-avg-inverse-rate"
|
||||||
appFavouritesQuickActionsTimeout <- o .: "favourites-quick-actions-timeout"
|
appFavouritesQuickActionsTimeout <- o .: "favourites-quick-actions-timeout"
|
||||||
|
|||||||
@ -115,6 +115,7 @@ decodeBearer :: forall m.
|
|||||||
, MonadCrypto m
|
, MonadCrypto m
|
||||||
, ParseRoute (HandlerSite m)
|
, ParseRoute (HandlerSite m)
|
||||||
, Hashable (Route (HandlerSite m))
|
, Hashable (Route (HandlerSite m))
|
||||||
|
, HasAppSettings (HandlerSite m)
|
||||||
)
|
)
|
||||||
=> Jwt -> m (BearerToken (HandlerSite m))
|
=> Jwt -> m (BearerToken (HandlerSite m))
|
||||||
-- ^ Decode a `Jwt` and call `bearerParseJSON`
|
-- ^ Decode a `Jwt` and call `bearerParseJSON`
|
||||||
@ -130,9 +131,10 @@ decodeBearer (Jwt bs) = do
|
|||||||
parser <- bearerParseJSON'
|
parser <- bearerParseJSON'
|
||||||
bearer@BearerToken{..} <- either (throwM . BearerTokenInvalidFormat . uncurry JSON.formatError) return $ JSON.eitherDecodeStrictWith JSON.jsonEOF' (JSON.iparse parser) content'
|
bearer@BearerToken{..} <- either (throwM . BearerTokenInvalidFormat . uncurry JSON.formatError) return $ JSON.eitherDecodeStrictWith JSON.jsonEOF' (JSON.iparse parser) content'
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
unless (NTop bearerExpiresAt > NTop (Just now)) $
|
(clockLeniencyStart, clockLeniencyEnd) <- getsYesod $ (,) <$> view _appBearerTokenClockLeniencyStart <*> view _appBearerTokenClockLeniencyEnd
|
||||||
|
unless (NTop bearerExpiresAt > NTop (Just $ maybe id addUTCTime (negate <$> clockLeniencyEnd) now)) $
|
||||||
throwM BearerTokenExpired
|
throwM BearerTokenExpired
|
||||||
unless (bearerStartsAt <= Just now) $
|
unless (bearerStartsAt <= Just (maybe id addUTCTime clockLeniencyStart now)) $
|
||||||
throwM BearerTokenNotStarted
|
throwM BearerTokenNotStarted
|
||||||
return bearer
|
return bearer
|
||||||
|
|
||||||
|
|||||||
@ -46,6 +46,7 @@ data ServerSessionJwtConfig = ServerSessionJwtConfig
|
|||||||
, sJwtEncoding :: JwtEncoding
|
, sJwtEncoding :: JwtEncoding
|
||||||
, sJwtIssueBy :: InstanceId
|
, sJwtIssueBy :: InstanceId
|
||||||
, sJwtIssueFor :: ClusterId
|
, sJwtIssueFor :: ClusterId
|
||||||
|
, sJwtClockLeniencyStart, sJwtClockLeniencyEnd :: Maybe NominalDiffTime
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -147,9 +148,9 @@ decodeSession ServerSessionJwtConfig{..} (Jwt bs) = do
|
|||||||
session@SessionToken{..} <- either (throwM . SessionTokenInvalidFormat) return $ JSON.eitherDecodeStrict content'
|
session@SessionToken{..} <- either (throwM . SessionTokenInvalidFormat) return $ JSON.eitherDecodeStrict content'
|
||||||
|
|
||||||
now <- liftIO getCurrentTime
|
now <- liftIO getCurrentTime
|
||||||
unless (NTop sessionExpiresAt > NTop (Just now)) $
|
unless (NTop sessionExpiresAt > NTop (Just $ maybe id addUTCTime (negate <$> sJwtClockLeniencyEnd) now)) $
|
||||||
throwM SessionTokenExpired
|
throwM SessionTokenExpired
|
||||||
unless (sessionStartsAt <= Just now) $
|
unless (sessionStartsAt <= Just (maybe id addUTCTime sJwtClockLeniencyStart now)) $
|
||||||
throwM SessionTokenNotStarted
|
throwM SessionTokenNotStarted
|
||||||
|
|
||||||
return session
|
return session
|
||||||
|
|||||||
Reference in New Issue
Block a user