filter out illegal remote names when reading proxy log

This commit is contained in:
Joey Hess 2024-06-06 12:51:30 -04:00
parent d208b03e5d
commit a72d0f69d0
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 10 additions and 7 deletions

View file

@ -18,6 +18,7 @@ import qualified Data.Map as M
import qualified Annex import qualified Annex
import Annex.Common import Annex.Common
import qualified Annex.Branch import qualified Annex.Branch
import qualified Git.Remote
import Git.Types import Git.Types
import Logs import Logs
import Logs.UUIDBased import Logs.UUIDBased
@ -37,7 +38,7 @@ data Proxy = Proxy
-- TODO caching -- TODO caching
getProxies :: Annex (M.Map UUID (S.Set Proxy)) getProxies :: Annex (M.Map UUID (S.Set Proxy))
getProxies = M.map value . fromMapLog . parseProxyLog getProxies = M.map (validateProxies . value) . fromMapLog . parseProxyLog
<$> Annex.Branch.get proxyLog <$> Annex.Branch.get proxyLog
recordProxies :: S.Set Proxy -> Annex () recordProxies :: S.Set Proxy -> Annex ()
@ -76,3 +77,11 @@ parseProxyList = S.fromList <$> many parseword
<* (const () <$> A8.char colon) <* (const () <$> A8.char colon)
<*> (decodeBS <$> A8.takeWhile1 (/= ' ')) <*> (decodeBS <$> A8.takeWhile1 (/= ' '))
colon = ':' colon = ':'
-- Filter out any proxies that have a name that is not allowed as a git
-- remote name. This avoids any security problems with eg escape
-- characters in names, and ensures the name can be used anywhere a usual
-- git remote name can be used without causing issues.
validateProxies :: S.Set Proxy -> S.Set Proxy
validateProxies = S.filter $ \p ->
Git.Remote.makeLegalName (proxyRemoteName p) == proxyRemoteName p

View file

@ -37,12 +37,6 @@ For June's work on [[design/passthrough_proxy]], implementation plan:
1. getProxies should be cached to avoid repeatedly reading the log and 1. getProxies should be cached to avoid repeatedly reading the log and
parsing. parsing.
1. Remote names coming from the git-annex branch need to be
limited to what's legal in git remote names. If a remote name is not
legal, munge it until it is.
This will also prevent remote names being a security hazard
via eg escape characters.
2. Remote instantiation for proxies. When a remote "foo" is a proxy, 2. Remote instantiation for proxies. When a remote "foo" is a proxy,
and has a remote "bar", instantiate a remote "foo-bar" that has the UUID and has a remote "bar", instantiate a remote "foo-bar" that has the UUID
of bar but is of the same type and configuration of remote "foo". of bar but is of the same type and configuration of remote "foo".