Skip to content

Commit b4ea1c7

Browse files
authored
Fix incomplete-record-updates warnings (#1059)
1 parent 10f2a90 commit b4ea1c7

File tree

3 files changed

+32
-26
lines changed

3 files changed

+32
-26
lines changed

src/Distribution/Server/Features/Users.hs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,9 @@ userFeature templates usersState adminsState
495495
overrideResponse <- msum <$> runHook authFailHook err
496496
let resp' = fromMaybe defaultResponse overrideResponse
497497
-- reset authn to "0" on auth failures
498-
resp'' = resp' { errorHeaders = ("Set-Cookie","authn=\"0\";Path=/;Version=\"1\""):errorHeaders resp' }
498+
resp'' = case resp' of
499+
r@ErrorResponse{} -> r { errorHeaders = ("Set-Cookie","authn=\"0\";Path=/;Version=\"1\""):errorHeaders r }
500+
GenericErrorResponse -> GenericErrorResponse
499501
throwError resp''
500502

501503
-- Check if there is an authenticated userid, and return info, if so.

src/Distribution/Server/Framework/Auth.hs

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
-- We authenticate clients using HTTP Basic or Digest authentication and we
44
-- authorise users based on membership of particular user groups.
55
--
6-
{-# LANGUAGE PatternGuards #-}
6+
{-# LANGUAGE LambdaCase, PatternGuards #-}
77
module Distribution.Server.Framework.Auth (
88
-- * Checking authorisation
99
guardAuthorised,
@@ -428,26 +428,29 @@ data AuthError = NoAuthError
428428

429429
authErrorResponse :: MonadIO m => RealmName -> AuthError -> m ErrorResponse
430430
authErrorResponse realm autherr = do
431-
digestHeader <- liftIO (headerDigestAuthChallenge realm)
432-
return $! (toErrorResponse autherr) { errorHeaders = [digestHeader] }
433-
where
434-
toErrorResponse :: AuthError -> ErrorResponse
435-
toErrorResponse NoAuthError =
436-
ErrorResponse 401 [] "No authorization provided" []
437-
438-
toErrorResponse UnrecognizedAuthError =
439-
ErrorResponse 400 [] "Authorization scheme not recognized" []
440-
441-
toErrorResponse InsecureAuthError =
442-
ErrorResponse 400 [] "Authorization scheme not allowed over plain http"
443-
[ MText $ "HTTP Basic and X-ApiKey authorization methods leak "
444-
++ "information when used over plain HTTP. Either use HTTPS "
445-
++ "or if you must use plain HTTP for authorised requests then "
446-
++ "use HTTP Digest authentication." ]
447-
448-
toErrorResponse BadApiKeyError =
449-
ErrorResponse 401 [] "Bad auth token" []
450-
451-
-- we don't want to leak info for the other cases, so same message for them all:
452-
toErrorResponse _ =
453-
ErrorResponse 401 [] "Username or password incorrect" []
431+
digestHeader <- liftIO (headerDigestAuthChallenge realm)
432+
433+
let
434+
toErrorResponse :: AuthError -> ErrorResponse
435+
toErrorResponse = \case
436+
NoAuthError ->
437+
ErrorResponse 401 [digestHeader] "No authorization provided" []
438+
439+
UnrecognizedAuthError ->
440+
ErrorResponse 400 [digestHeader] "Authorization scheme not recognized" []
441+
442+
InsecureAuthError ->
443+
ErrorResponse 400 [digestHeader] "Authorization scheme not allowed over plain http"
444+
[ MText $ "HTTP Basic and X-ApiKey authorization methods leak "
445+
++ "information when used over plain HTTP. Either use HTTPS "
446+
++ "or if you must use plain HTTP for authorised requests then "
447+
++ "use HTTP Digest authentication." ]
448+
449+
BadApiKeyError ->
450+
ErrorResponse 401 [digestHeader] "Bad auth token" []
451+
452+
-- we don't want to leak info for the other cases, so same message for them all:
453+
_ ->
454+
ErrorResponse 401 [digestHeader] "Username or password incorrect" []
455+
456+
return $! toErrorResponse autherr

src/Distribution/Server/Framework/HappstackUtils.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,8 @@ enableRange = do
215215
-- awkward; we'd have to parse the original Content-Length header to find
216216
-- out the original length.
217217
rangeFilter :: (Int64, Int64) -> Response -> Response
218-
rangeFilter (fr, to) r =
218+
rangeFilter _ r@SendFile{} = r
219+
rangeFilter (fr, to) r@Response{} =
219220
setHeader "Content-Length" (show rangeLen)
220221
. setHeaderBS (BS.C8.pack "Content-Range") (contentRange fr to fullLen)
221222
. removeResponseHeader "Content-MD5"

0 commit comments

Comments
 (0)