Skip to content

Commit 28671e1

Browse files
committed
Distros: Also validate URI for individual updates
1 parent c516df3 commit 28671e1

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/Distribution/Server/Features/Distro.hs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,8 +227,8 @@ distroFeature UserFeature{..}
227227
pVerStr <- look "version"
228228
pUriStr <- look "uri"
229229
case simpleParse pVerStr of
230-
Nothing -> mzero
231-
Just pVer -> return $ DistroPackageInfo pVer pUriStr
230+
Just pVer | isValidDistroURI pUriStr -> return $ DistroPackageInfo pVer pUriStr
231+
_ -> mzero
232232
case mInfo of
233233
(Left errs) -> ok $ toResponse $ unlines $ "Sorry, something went wrong there." : errs
234234
(Right pInfo) -> func pInfo
@@ -260,14 +260,18 @@ packageListToCSV :: [(PackageName, DistroPackageInfo)] -> CSVFile
260260
packageListToCSV entries
261261
= CSVFile $ map (\(pn,DistroPackageInfo version url) -> [display pn, display version, url]) entries
262262

263+
isValidDistroURI :: String -> Bool
264+
isValidDistroURI uri =
265+
T.pack "https:" `T.isPrefixOf` T.pack uri
266+
263267
csvToPackageList :: CSVFile -> Either String [(PackageName, DistroPackageInfo)]
264268
csvToPackageList (CSVFile records)
265269
= mapM fromRecord records
266270
where
267271
fromRecord [packageStr, versionStr, uri]
268272
| Just package <- simpleParse packageStr
269273
, Just version <- simpleParse versionStr
270-
, T.pack "https:" `T.isPrefixOf` T.pack uri
274+
, isValidDistroURI uri
271275
= return (package, DistroPackageInfo version uri)
272276
fromRecord record
273277
= Left $ "Invalid distro package entry: " ++ show record

0 commit comments

Comments
 (0)