git style filename quoting for giveup
When the filenames are part of the git repository or other files that might have attacker-controlled names, quote them in error messages. This is fairly complete, although I didn't do the one in Utility.DirWatcher.INotify.hs because that doesn't have access to Git.Filename or Annex. But it's also quite possible I missed some. And also while scanning for these, I found giveup used with other things that could be attacker controlled to contain control characters (eg Keys). So, I'm thinking it would also be good for giveup to just filter out control characters. This commit is then not the only line of defence, but just good formatting when git-annex displays a filename in an error message. Sponsored-by: Kevin Mueller on Patreon
This commit is contained in:
parent
da83652c76
commit
063c00e4f7
8 changed files with 79 additions and 30 deletions
|
@ -5,6 +5,8 @@
|
|||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
||||
{-# LANGUAGE OverloadedStrings #-}
|
||||
|
||||
module Annex.Ingest (
|
||||
LockedDown(..),
|
||||
LockDownConfig(..),
|
||||
|
@ -46,6 +48,7 @@ import Utility.CopyFile
|
|||
import Utility.Touch
|
||||
import Utility.Metered
|
||||
import Git.FilePath
|
||||
import Git.Filename
|
||||
import Annex.InodeSentinal
|
||||
import Annex.AdjustedBranch
|
||||
import Annex.FileMatcher
|
||||
|
@ -133,16 +136,16 @@ lockDown' cfg file = tryNonAsync $ ifM crippledFileSystem
|
|||
|
||||
setperms = when (lockingFile cfg) $ do
|
||||
freezeContent file'
|
||||
when (checkWritePerms cfg) $
|
||||
maybe noop giveup =<< checkLockedDownWritePerms file' file'
|
||||
when (checkWritePerms cfg) $ do
|
||||
qp <- coreQuotePath <$> Annex.getGitConfig
|
||||
maybe noop (giveup . decodeBS . quote qp)
|
||||
=<< checkLockedDownWritePerms file' file'
|
||||
|
||||
checkLockedDownWritePerms :: RawFilePath -> RawFilePath -> Annex (Maybe String)
|
||||
checkLockedDownWritePerms :: RawFilePath -> RawFilePath -> Annex (Maybe StringContainingQuotedPath)
|
||||
checkLockedDownWritePerms file displayfile = checkContentWritePerm file >>= return . \case
|
||||
Just False -> Just $ unwords
|
||||
[ "Unable to remove all write permissions from"
|
||||
, fromRawFilePath displayfile
|
||||
, "-- perhaps it has an xattr or ACL set."
|
||||
]
|
||||
Just False -> Just $ "Unable to remove all write permissions from "
|
||||
<> QuotedPath displayfile
|
||||
<> " -- perhaps it has an xattr or ACL set."
|
||||
_ -> Nothing
|
||||
|
||||
{- Ingests a locked down file into the annex. Updates the work tree and
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue