annotate hggit/compat.py @ 850:81c55f8629ba

hg2git: audit path components during export (CVE-2014-9390) A user recently got confused and managed to track and export a .git directory, which confuses git and causes it to emit very odd errors. For example, cloning one such repository (which has a symlink for .git) produces this output from git: Cloning into 'git'... done. error: Updating '.git' would lose untracked files in it and another (which has a .git directory checked in) produces this: Cloning into 'git'... done. error: Invalid path '.git/hooks/post-update' If it ended there, that'd be fine, but this led to a line of investigation that ended with CVE-2014-9390, so now git will block checking these revisions out, so we should try to prevent foot-shooting on our end. Since some servers (notably github) are blocking trees that contain these entries, default to refusing to export any path component that looks like it folds to .git. Since some histories probably contain this already, we offer an escape hatch via the config option git.blockdotgit that allows users to resume foot-shooting behavior.
author Augie Fackler <raf@durin42.com>
date Sun, 23 Nov 2014 19:06:21 -0500
parents
children 92d7702c19da
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
850
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
1 try:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
2 from mercurial import encoding
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
3 hfsignoreclean = encoding.hfsignoreclean
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
4 except AttributeError:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
5 # compat with hg 3.2.1 and earlier, which doesn't have
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
6 # hfsignoreclean (This was borrowed wholesale from hg 3.2.2.)
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
7 _ignore = [unichr(int(x, 16)).encode("utf-8") for x in
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
8 "200c 200d 200e 200f 202a 202b 202c 202d 202e "
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
9 "206a 206b 206c 206d 206e 206f feff".split()]
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
10 # verify the next function will work
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
11 assert set([i[0] for i in _ignore]) == set(["\xe2", "\xef"])
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
12
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
13 def hfsignoreclean(s):
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
14 """Remove codepoints ignored by HFS+ from s.
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
15
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
16 >>> hfsignoreclean(u'.h\u200cg'.encode('utf-8'))
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
17 '.hg'
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
18 >>> hfsignoreclean(u'.h\ufeffg'.encode('utf-8'))
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
19 '.hg'
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
20 """
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
21 if "\xe2" in s or "\xef" in s:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
22 for c in _ignore:
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
23 s = s.replace(c, '')
81c55f8629ba hg2git: audit path components during export (CVE-2014-9390)
Augie Fackler <raf@durin42.com>
parents:
diff changeset
24 return s