limit url downloads to whitelisted schemes
Security fix! Allowing any schemes, particularly file: and possibly others like scp: allowed file exfiltration by anyone who had write access to the git repository, since they could add an annexed file using such an url, or using an url that redirected to such an url, and wait for the victim to get it into their repository and send them a copy. * Added annex.security.allowed-url-schemes setting, which defaults to only allowing http and https URLs. Note especially that file:/ is no longer enabled by default. * Removed annex.web-download-command, since its interface does not allow supporting annex.security.allowed-url-schemes across redirects. If you used this setting, you may want to instead use annex.web-options to pass options to curl. With annex.web-download-command removed, nearly all url accesses in git-annex are made via Utility.Url via http-client or curl. http-client only supports http and https, so no problem there. (Disabling one and not the other is not implemented.) Used curl --proto to limit the allowed url schemes. Note that this will cause git annex fsck --from web to mark files using a disallowed url scheme as not being present in the web. That seems acceptable; fsck --from web also does that when a web server is not available. youtube-dl already disabled file: itself (probably for similar reasons). The scheme check was also added to youtube-dl urls for completeness, although that check won't catch any redirects it might follow. But youtube-dl goes off and does its own thing with other protocols anyway, so that's fine. Special remotes that support other domain-specific url schemes are not affected by this change. In the bittorrent remote, aria2c can still download magnet: links. The download of the .torrent file is otherwise now limited by annex.security.allowed-url-schemes. This does not address any external special remotes that might download an url themselves. Current thinking is all external special remotes will need to be audited for this problem, although many of them will use http libraries that only support http and not curl's menagarie. The related problem of accessing private localhost and LAN urls is not addressed by this commit. This commit was sponsored by Brett Eisenberg on Patreon.
This commit is contained in:
parent
c8559a0403
commit
28720c795f
16 changed files with 139 additions and 68 deletions
|
@ -11,7 +11,7 @@ module Annex.YoutubeDl (
|
|||
youtubeDlSupported,
|
||||
youtubeDlCheck,
|
||||
youtubeDlFileName,
|
||||
youtubeDlFileName',
|
||||
youtubeDlFileNameHtmlOnly,
|
||||
) where
|
||||
|
||||
import Annex.Common
|
||||
|
@ -41,8 +41,11 @@ import Control.Concurrent.Async
|
|||
-- (Note that we can't use --output to specifiy the file to download to,
|
||||
-- due to <https://github.com/rg3/youtube-dl/issues/14864>)
|
||||
youtubeDl :: URLString -> FilePath -> Annex (Either String (Maybe FilePath))
|
||||
youtubeDl url workdir
|
||||
| supportedScheme url = ifM (liftIO $ inPath "youtube-dl")
|
||||
youtubeDl url workdir = withUrlOptions $ youtubeDl' url workdir
|
||||
|
||||
youtubeDl' :: URLString -> FilePath -> UrlOptions -> Annex (Either String (Maybe FilePath))
|
||||
youtubeDl' url workdir uo
|
||||
| supportedScheme uo url = ifM (liftIO $ inPath "youtube-dl")
|
||||
( runcmd >>= \case
|
||||
Right True -> workdirfiles >>= \case
|
||||
(f:[]) -> return (Right (Just f))
|
||||
|
@ -134,8 +137,11 @@ youtubeDlSupported url = either (const False) id <$> youtubeDlCheck url
|
|||
|
||||
-- Check if youtube-dl can find media in an url.
|
||||
youtubeDlCheck :: URLString -> Annex (Either String Bool)
|
||||
youtubeDlCheck url
|
||||
| supportedScheme url = catchMsgIO $ htmlOnly url False $ do
|
||||
youtubeDlCheck = withUrlOptions . youtubeDlCheck'
|
||||
|
||||
youtubeDlCheck' :: URLString -> UrlOptions -> Annex (Either String Bool)
|
||||
youtubeDlCheck' url uo
|
||||
| supportedScheme uo url = catchMsgIO $ htmlOnly url False $ do
|
||||
opts <- youtubeDlOpts [ Param url, Param "--simulate" ]
|
||||
liftIO $ snd <$> processTranscript "youtube-dl" (toCommand opts) Nothing
|
||||
| otherwise = return (Right False)
|
||||
|
@ -144,18 +150,22 @@ youtubeDlCheck url
|
|||
--
|
||||
-- (This is not always identical to the filename it uses when downloading.)
|
||||
youtubeDlFileName :: URLString -> Annex (Either String FilePath)
|
||||
youtubeDlFileName url
|
||||
| supportedScheme url = flip catchIO (pure . Left . show) $
|
||||
htmlOnly url nomedia (youtubeDlFileName' url)
|
||||
| otherwise = return nomedia
|
||||
youtubeDlFileName url = withUrlOptions go
|
||||
where
|
||||
go uo
|
||||
| supportedScheme uo url = flip catchIO (pure . Left . show) $
|
||||
htmlOnly url nomedia (youtubeDlFileNameHtmlOnly' url uo)
|
||||
| otherwise = return nomedia
|
||||
nomedia = Left "no media in url"
|
||||
|
||||
-- Does not check if the url contains htmlOnly; use when that's already
|
||||
-- been verified.
|
||||
youtubeDlFileName' :: URLString -> Annex (Either String FilePath)
|
||||
youtubeDlFileName' url
|
||||
| supportedScheme url = flip catchIO (pure . Left . show) go
|
||||
youtubeDlFileNameHtmlOnly :: URLString -> Annex (Either String FilePath)
|
||||
youtubeDlFileNameHtmlOnly = withUrlOptions . youtubeDlFileNameHtmlOnly'
|
||||
|
||||
youtubeDlFileNameHtmlOnly' :: URLString -> UrlOptions -> Annex (Either String FilePath)
|
||||
youtubeDlFileNameHtmlOnly' url uo
|
||||
| supportedScheme uo url = flip catchIO (pure . Left . show) go
|
||||
| otherwise = return nomedia
|
||||
where
|
||||
go = do
|
||||
|
@ -189,12 +199,13 @@ youtubeDlOpts addopts = do
|
|||
opts <- map Param . annexYoutubeDlOptions <$> Annex.getGitConfig
|
||||
return (opts ++ addopts)
|
||||
|
||||
supportedScheme :: URLString -> Bool
|
||||
supportedScheme url = case uriScheme <$> parseURIRelaxed url of
|
||||
supportedScheme :: UrlOptions -> URLString -> Bool
|
||||
supportedScheme uo url = case parseURIRelaxed url of
|
||||
Nothing -> False
|
||||
-- avoid ugly message from youtube-dl about not supporting file:
|
||||
Just "file:" -> False
|
||||
-- ftp indexes may look like html pages, and there's no point
|
||||
-- involving youtube-dl in a ftp download
|
||||
Just "ftp:" -> False
|
||||
Just _ -> True
|
||||
Just u -> case uriScheme u of
|
||||
-- avoid ugly message from youtube-dl about not supporting file:
|
||||
"file:" -> False
|
||||
-- ftp indexes may look like html pages, and there's no point
|
||||
-- involving youtube-dl in a ftp download
|
||||
"ftp:" -> False
|
||||
_ -> allowedScheme uo u
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue