Skip to content

Commit 9a18876

Browse files
authored
Merge pull request #1445 from frasertweedale/sec/quick-jump-hashes
accept additional quick-jump hashes
2 parents 03bd16e + 97475e2 commit 9a18876

File tree

1 file changed

+78
-14
lines changed

1 file changed

+78
-14
lines changed

src/Distribution/Server/Features/Documentation.hs

Lines changed: 78 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -310,22 +310,25 @@ documentationFeature name
310310
case dpath of
311311
("..","doc-index.json") : _ -> True
312312
_ -> False
313-
isQuickJump =
313+
hashesToCheck =
314314
case dpath of
315-
("..","quick-jump.min.js") : _ -> True
316-
("..","quick-jump.css") : _ -> True
317-
_ -> False
315+
("..", "quick-jump.min.js") : _ -> Just quickJumpJsKnownGoodSha256
316+
("..", "quick-jump.css") : _ -> Just quickJumpCssKnownGoodSha256
317+
_ -> Nothing
318318
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
319+
| isDocIndex ->
320+
pure response
321+
| Just hashes <- hashesToCheck ->
322+
-- Because Quick Jump also runs on the package page,
323+
-- and not just on the user content domain,
324+
-- we cannot accept arbitrary user-uploaded content.
325+
if digest `elem` hashes
326+
then pure response
327+
else errForbidden "Quick Jump hash is not correct" [MText "Accepted Quick Jump hashes are listed in the hackage-server source code."]
328+
| mtime < UTCTime (fromGregorian 2025 2 1) 0 ->
329+
pure response
330+
| otherwise ->
331+
requireUserContent env response
329332

330333
rewriteDocs :: BSL.ByteString -> BSL.ByteString
331334
rewriteDocs dochtml = case BSL.breakFindAfter (BS.pack "<head>") dochtml of
@@ -520,3 +523,64 @@ mapParaM f = mapM (\x -> (,) x <$> f x)
520523

521524
getFileAge :: FilePath -> IO NominalDiffTime
522525
getFileAge file = diffUTCTime <$> getCurrentTime <*> getModificationTime file
526+
527+
quickJumpJsKnownGoodSha256 :: [String]
528+
quickJumpJsKnownGoodSha256 =
529+
[
530+
-- commit: e99aefb50ca63e2dbcc95841efbb53cea90151d8 (Sep 23 2017)
531+
-- object: c9f2b445b9
532+
"e1da96b0d7ab3d72cfe3786def923c5af91ba331858852f1f43a1acfc5ee6966"
533+
534+
-- commit: 8e88615a23a9f1980a55bd1b3ef9dcc938d95237 (Oct 10 2017)
535+
-- object: cb24f8bdea
536+
, "a273a3ef19c21032afc5f65d1e09933146f183da906ca9d0b4c285095539e0e7"
537+
538+
-- commit: b4982d87f41d9a4d3f6237bacfd819145723e35b (Oct 30 2017)
539+
-- object: f22f8f2881
540+
, "8aed621ac2b746751585cbe271631394cacc0e01cca4ef589e11b077b0acd291"
541+
542+
-- commit: 93c1e6eb9e829a66ff213ec076d529ab008880b3 (Dec 16 2017)
543+
-- object: bfdf04a372
544+
, "4b10c18a7ad35f032e8cdc0d263716a93878bf06d998b1b66dccff06ceeee89d"
545+
546+
-- commit: 59812a09eb69cbf12407206381f4c214987b1efd (Apr 3 2018)
547+
-- object: c03e083607
548+
, "ce86bba43edb0534c0faa2d6d0f504877576c5271321e3fbd9638fd4667384a2"
549+
550+
-- commit: a69311708493efe8524aed0e9d19365f79f2fab3 (Oct 24 2018)
551+
-- object: 06c35c7454
552+
, "548d676b3e5a52cbfef06d7424ec065c1f34c230407f9f5dc002c27a9666bec4"
553+
554+
-- commit: 7776566531e72c415f66dd3b13da9041c52076aa (Nov 13 2019)
555+
-- object: 0b0eeb27d1
556+
, "7ca43fc2058574846e032bc5493a0ad4568e4fa14fb58558fbf48d3bd6693e59"
557+
]
558+
559+
560+
quickJumpCssKnownGoodSha256 :: [String]
561+
quickJumpCssKnownGoodSha256 =
562+
[
563+
-- commit: d41abb0f606bf5fdbdc0a7bd3758e0c30601b121 (Sep 23 2017)
564+
-- object: b69903c3
565+
"f95b8b12a8a13dd31add93527e1239fdff6997c7f2396e975e2e415db04b75fb"
566+
567+
-- commit: 0997eb61803a37803ddb6cf7116eb9db1046b2ce (Oct 10 2017)
568+
-- object: ede05042
569+
, "59693ef3f0d793031b3af58b214af7884c0f63ce6db659ffd7432cf0aa852b51"
570+
571+
-- commit: fc069bf200f930c21f96ddbbec1d7c5c69f8ba72 (Jan 15 2018)
572+
-- object: 468d8036
573+
, "1d51573b72bc8a7b9b0dda3beffb7882db78d22a37840203f761e3969d915027"
574+
575+
-- commit: fa5ec121e2a700137bab8bd48cc30b1e80f58fd4 (Feb 27 2019)
576+
-- object: 8772809c
577+
, "29fe483bd37ad3feba12f646e9661731127526f246c246b0011b384e11649dff"
578+
579+
-- commit: 05ccce6e07731f9788a434d6e06f4cadeff3d6ba (Dec 8 2020)
580+
-- object: d656f51c
581+
, "6997c223e09b340f5f1bb970c930b458f768a0bbbe787cb87f181820a3d122b3"
582+
583+
-- commit: 9511e587701349093cbe3ac7c00f13583820774f (Feb 7 2021)
584+
-- object: cf10eee4
585+
, "6bd159f6d7b1cfef1bd190f1f5eadcd15d35c6c567330d7465c3c35d5195bc6f"
586+
]

0 commit comments

Comments
 (0)