Skip to content

Commit 354a7de

Browse files
authored
Update Documentation.hs
quickjump hashcheck
1 parent c43d7e4 commit 354a7de

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

src/Distribution/Server/Features/Documentation.hs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{-# LANGUAGE RankNTypes, FlexibleContexts,
22
NamedFieldPuns, RecordWildCards, PatternGuards #-}
3-
{-# LANGUAGE LambdaCase #-}
3+
{-# LANGUAGE LambdaCase, MultiWayIf #-}
44
module Distribution.Server.Features.Documentation (
55
DocumentationFeature(..),
66
DocumentationResource(..),
@@ -310,12 +310,22 @@ documentationFeature name
310310
case dpath of
311311
("..","doc-index.json") : _ -> True
312312
_ -> False
313-
if mtime < UTCTime (fromGregorian 2025 2 1) 0
314-
|| isDocIndex
315-
|| digest == "548d676b3e5a52cbfef06d7424ec065c1f34c230407f9f5dc002c27a9666bec4" -- quick-jump.min.js
316-
|| digest == "6bd159f6d7b1cfef1bd190f1f5eadcd15d35c6c567330d7465c3c35d5195bc6f" -- quick-jump.css
317-
then pure response
318-
else requireUserContent env response
313+
isQuickJump =
314+
case dpath of
315+
("..","quick-jump.min.js") : _ -> True
316+
("..","quick-jump.css") : _ -> True
317+
_ -> False
318+
if
319+
| isDocIndex || mtime < UTCTime (fromGregorian 2025 2 1) 0 -> pure response
320+
| isQuickJump ->
321+
if digest == "548d676b3e5a52cbfef06d7424ec065c1f34c230407f9f5dc002c27a9666bec4" -- quick-jump.min.js
322+
|| digest == "6bd159f6d7b1cfef1bd190f1f5eadcd15d35c6c567330d7465c3c35d5195bc6f" -- quick-jump.css
323+
then pure response
324+
else
325+
-- Because Quick Jump also runs on the package page, and not just on the user content domain,
326+
-- we cannot accept arbitrary user-uploaded content.
327+
errForbidden "Quick Jump hash is not correct" [MText "Accepted Quick Jump hashes are listed in the hackage-server source code."]
328+
| otherwise -> requireUserContent env response
319329

320330
rewriteDocs :: BSL.ByteString -> BSL.ByteString
321331
rewriteDocs dochtml = case BSL.breakFindAfter (BS.pack "<head>") dochtml of

0 commit comments

Comments
 (0)