gitweb: escape URLs generated by href()

There's a cross-site scripting problem in gitweb, where it will print
URLs generated by its href() helper without further quoting. This allows
an attacker to point a victim to a specially crafted gitweb URL and
inject arbitrary HTML into the resulting page (which the victim sees as
coming from gitweb).

The base of the URL comes from evaluate_uri(), which pulls the value of
$REQUEST_URI via the CGI module. It tries to strip off $PATH_INFO, but
fails to do so in some cases (including ones that contain special
characters, like "+"). Most of the uses of the URL end up being passed
to "$cgi->a(-href = href())", which will get quoted properly by the CGI
module. But in a few places, we output them ourselves as part of
manually-generated HTML, and whatever was in the original URL will
appear unquoted in the output.

Given that all of the nearby variables placed into this manual HTML
_are_ quoted, it seems like the authors assumed that these URLs would
not need quoting. So it's possible that the bug is actually in
evaluate_uri(), which should be doing a more careful job of stripping
$PATH_INFO. There's some discussion in a comment in that function, as
well as the commit message in 81d3fe9f48 (gitweb: fix wrong base URL
when non-root DirectoryIndex, 2009-02-15). But I'm not sure I understand
it.

Regardless, it's a good idea to quote these values at the point of
insertion into the HTML output:

  1. Even if there is a bug in evaluate_uri(), this would give us
     belt-and-suspenders protection.

  2. evaluate_uri() is only handling the base. Some generated URLs will
     also mention arbitrary refs or filenames in the repositories, and
     these should be quoted anyway.

  3. It should never _hurt_ to quote (and that's what all of the
     $cgi->a() calls are doing already).

So there may be further work here, but this patch at least prevents the
XSS vulnerability, and shouldn't make anything worse.

The test here covers the calls in print_feed_meta(), but I manually
audited every call to href() to see how its output was used, and quoted
appropriately. Most of them are esc_attr(), as they're used in tag
attributes, but I used esc_html() when the URLs were printed bare. The
distinction is largely academic, as one is implemented as a wrapper for
the other.

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