Skip to content
Snippets Groups Projects
Commit a2db1fd5 authored by Dan Villiom Podlaski Christiansen's avatar Dan Villiom Podlaski Christiansen
Browse files

push: add ui.dropdotgit option, enabled by default

The current behaviour is quite unhelpful, given that it either allows
you to abort the conversion or generate a bogus repository. As an
example, GitHub rejects anything with a `.git` in it.

Instead, the new default is to issue a warning and simply discard the
dangerous files. Although this might cause problems down the line, I'd
much rather have those problems than just have hg-git give up.

As an example of such a bogus repository, look no further than this
one. c43c02cc803a committed some tests from Dulwich with nested Git
repositories, and a061dce264b7 renamed them. Prior to this change,
hg-git could not push its own repository to GitHub.
parent 27e5052d
No related branches found
No related tags found
No related merge requests found
......@@ -78,7 +78,8 @@
CONFIG_DEFAULTS = {
b'git': {
b'authors': None,
b'blockdotgit': True,
b'dropdotgit': True,
b'blockdotgit': False,
b'blockdothg': True,
b'branch_bookmark_suffix': None,
b'debugextrainmessage': False, # test only -- do not document this!
......
......@@ -125,9 +125,12 @@
If ``git.blockdotgit`` is set, insecure paths raise an
exception.
Otherwise, a warning may be printed, but the return value is
``True``, indicating that all paths should be retained
regardless of any problems they may cause.
Otherwise, if ``ui.dropdotgit`` is set, the return value is
``False`` to indicate that they are insecure.
If neither is set, a warning may be printed, but the return
value is ``True``, indicating that all paths should be
retained regardless of any problems they may cause.
"""
ui = self._hg.ui
......@@ -152,10 +155,22 @@
b"set '[git] blockdotgit = false' in your hgrc"
),
)
ui.warn(b"warning: path '%s' contains a potentially dangerous path "
b'component, which git cannot check out and most '
b'git servers reject\n'
% path)
elif compat.config(ui, b'bool', b'git', b'dropdotgit'):
ui.warn(
b"warning: skipping potentially dangerous path '%s'\n"
% path,
)
return False
else:
ui.warn(
b"warning: path '%s' contains a potentially "
b'dangerous path component, which git cannot check '
b'out and most git servers reject\n'
% path,
)
return True
else:
return True
def audit_paths(self, paths):
"""Handle insecure paths"""
......@@ -159,9 +174,7 @@
def audit_paths(self, paths):
"""Handle insecure paths"""
for path in paths:
self._audit_one_path(path)
return paths
return [path for path in paths if self._audit_one_path(path)]
def update_changeset(self, newctx):
"""Set the tree to track a new Mercurial changeset.
......
......@@ -20,10 +20,14 @@
$ hg ci -m "we should refuse to export this"
$ hg book master
$ hg gexport
abort: likely-dangerous path '.git/hooks/post-update' rejected by configuration
(to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc)
[255]
$ hg gexport --config git.blockdotgit=no
warning: skipping potentially dangerous path '.git/hooks/post-update'
warning: skipping potentially dangerous path 'bar/.gi\xe2\x80\x8ct/wut' (esc)
warning: skipping potentially dangerous path 'foo/git~100/wat'
$ GIT_DIR=.hg/git git ls-tree -r --name-only master
this/is/safe
$ hg gclear
clearing out the git cache data
$ hg gexport --config git.dropdotgit=no
warning: path '.git/hooks/post-update' contains a potentially dangerous path component, which git cannot check out and most git servers reject
warning: path 'bar/.gi\xe2\x80\x8ct/wut' contains a potentially dangerous path component, which git cannot check out and most git servers reject (esc)
warning: path 'foo/git~100/wat' contains a potentially dangerous path component, which git cannot check out and most git servers reject
......@@ -48,6 +52,16 @@
$ hg ci -m "also refuse to export this"
$ hg book master
$ hg gexport
warning: skipping potentially dangerous path 'nested/.git/hooks/post-update'
$ git clone .hg/git git
Cloning into 'git'...
done.
$ rm -rf git
We can trigger an error:
$ hg -q gclear
$ hg --config git.blockdotgit=true gexport
abort: likely-dangerous path 'nested/.git/hooks/post-update' rejected by configuration
(to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc)
[255]
......@@ -51,4 +65,5 @@
abort: likely-dangerous path 'nested/.git/hooks/post-update' rejected by configuration
(to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc)
[255]
We can override if needed:
......@@ -54,5 +69,6 @@
We can override if needed:
$ hg --config git.blockdotgit=false gexport
$ hg --config git.dropdotgit=false gexport
warning: path 'nested/.git/hooks/post-update' contains a potentially dangerous path component, which git cannot check out and most git servers reject
$ cd ..
$ # different git versions give different return codes
......@@ -102,9 +118,7 @@
$ hg ci -m "also refuse to export this"
$ hg book master
$ hg gexport
abort: likely-dangerous path 'GIT~1/hooks/post-checkout' rejected by configuration
(to continue, read about CVE-2014-9390 and then set '[git] blockdotgit = false' in your hgrc)
[255]
warning: skipping potentially dangerous path 'GIT~1/hooks/post-checkout'
$ cd ..
Now check a Git repository containing a Mercurial repository, which
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment