##// END OF EJS Templates
dispatch: protect against malicious 'hg serve --stdio' invocations (sec)...
dispatch: protect against malicious 'hg serve --stdio' invocations (sec) Some shared-ssh installations assume that 'hg serve --stdio' is a safe command to run for minimally trusted users. Unfortunately, the messy implementation of argument parsing here meant that trying to access a repo named '--debugger' would give the user a pdb prompt, thereby sidestepping any hoped-for sandboxing. Serving repositories over HTTP(S) is unaffected. We're not currently hardening any subcommands other than 'serve'. If your service exposes other commands to users with arbitrary repository names, it is imperative that you defend against repository names of '--debugger' and anything starting with '--config'. The read-only mode of hg-ssh stopped working because it provided its hook configuration to "hg serve --stdio" via --config parameter. This is banned for security reasons now. This patch switches it to directly call ui.setconfig(). If your custom hosting infrastructure relies on passing --config to "hg serve --stdio", you'll need to find a different way to get that configuration into Mercurial, either by using ui.setconfig() as hg-ssh does in this patch, or by placing an hgrc file someplace where Mercurial will read it. mitrandir@fb.com provided some extra fixes for the dispatch code and for hg-ssh in places that I overlooked.

File last commit:

r26587:56b2bcea default
r32050:77eaf953 4.1.3 stable
Show More
test-custom-filters.t
66 lines | 1.5 KiB | text/troff | Tads3Lexer
/ tests / test-custom-filters.t
Nicolas Dumazet
tests: unify test-custom-filters
r12124 $ hg init
$ cat > .hg/hgrc <<EOF
> [extensions]
> prefixfilter = prefix.py
> [encode]
> *.txt = stripprefix: Copyright 2046, The Masters
> [decode]
> *.txt = insertprefix: Copyright 2046, The Masters
> EOF
$ cat > prefix.py <<EOF
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 > from mercurial import error
Nicolas Dumazet
tests: unify test-custom-filters
r12124 > def stripprefix(s, cmd, filename, **kwargs):
> header = '%s\n' % cmd
> if s[:len(header)] != header:
Pierre-Yves David
error: get Abort from 'error' instead of 'util'...
r26587 > raise error.Abort('missing header "%s" in %s' % (cmd, filename))
Nicolas Dumazet
tests: unify test-custom-filters
r12124 > return s[len(header):]
> def insertprefix(s, cmd):
> return '%s\n%s' % (cmd, s)
> def reposetup(ui, repo):
> repo.adddatafilter('stripprefix:', stripprefix)
> repo.adddatafilter('insertprefix:', insertprefix)
> EOF
$ cat > .hgignore <<EOF
> .hgignore
> prefix.py
> prefix.pyc
> EOF
$ cat > stuff.txt <<EOF
> Copyright 2046, The Masters
> Some stuff to ponder very carefully.
> EOF
$ hg add stuff.txt
$ hg ci -m stuff
Repository data:
$ hg cat stuff.txt
Some stuff to ponder very carefully.
Fresh checkout:
$ rm stuff.txt
$ hg up -C
1 files updated, 0 files merged, 0 files removed, 0 files unresolved
$ cat stuff.txt
Copyright 2046, The Masters
Some stuff to ponder very carefully.
Nicolas Dumazet
test-custom-filter: heredoc is not required for single line operations
r12125 $ echo "Very very carefully." >> stuff.txt
Nicolas Dumazet
tests: unify test-custom-filters
r12124 $ hg stat
M stuff.txt
Nicolas Dumazet
test-custom-filter: heredoc is not required for single line operations
r12125 $ echo "Unauthorized material subject to destruction." > morestuff.txt
Nicolas Dumazet
tests: unify test-custom-filters
r12124
Problem encoding:
$ hg add morestuff.txt
$ hg ci -m morestuff
abort: missing header "Copyright 2046, The Masters" in morestuff.txt
Matt Mackall
tests: add exit codes to unified tests
r12316 [255]
Nicolas Dumazet
tests: unify test-custom-filters
r12124 $ hg stat
M stuff.txt
A morestuff.txt