http: match headers case-insensitively when redacting

When HTTP/2 is in use, we fail to correctly redact "Authorization" (and
other) headers in our GIT_TRACE_CURL output.

We get the headers in our CURLOPT_DEBUGFUNCTION callback, curl_trace().
It passes them along to curl_dump_header(), which in turn checks
redact_sensitive_header(). We see the headers as a text buffer like:

  Host: ...
  Authorization: Basic ...

After breaking it into lines, we match each header using skip_prefix().
This is case-sensitive, even though HTTP headers are case-insensitive.
This has worked reliably in the past because these headers are generated
by curl itself, which is predictable in what it sends.

But when HTTP/2 is in use, instead we get a lower-case "authorization:"
header, and we fail to match it. The fix is simple: we should match with
skip_iprefix().

Testing is more complicated, though. We do have a test for the redacting
feature, but we don't hit the problem case because our test Apache setup
does not understand HTTP/2. You can reproduce the issue by applying this
on top of the test change in this patch:

	diff --git a/t/lib-httpd/apache.conf b/t/lib-httpd/apache.conf
	index afa91e38b0..19267c7107 100644
	--- a/t/lib-httpd/apache.conf
	+++ b/t/lib-httpd/apache.conf
	@@ -29,6 +29,9 @@ ErrorLog error.log
	 	LoadModule setenvif_module modules/mod_setenvif.so
	 </IfModule>

	+LoadModule http2_module modules/mod_http2.so
	+Protocols h2c
	+
	 <IfVersion < 2.4>
	 LockFile accept.lock
	 </IfVersion>
	@@ -64,8 +67,8 @@ LockFile accept.lock
	 <IfModule !mod_access_compat.c>
	 	LoadModule access_compat_module modules/mod_access_compat.so
	 </IfModule>
	-<IfModule !mod_mpm_prefork.c>
	-	LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
	+<IfModule !mod_mpm_event.c>
	+	LoadModule mpm_event_module modules/mod_mpm_event.so
	 </IfModule>
	 <IfModule !mod_unixd.c>
	 	LoadModule unixd_module modules/mod_unixd.so
	diff --git a/t/t5551-http-fetch-smart.sh b/t/t5551-http-fetch-smart.sh
	index 1c2a444ae7..ff74f0ae8a 100755
	--- a/t/t5551-http-fetch-smart.sh
	+++ b/t/t5551-http-fetch-smart.sh
	@@ -24,6 +24,10 @@ test_expect_success 'create http-accessible bare repository' '
	 	git push public main:main
	 '

	+test_expect_success 'prefer http/2' '
	+	git config --global http.version HTTP/2
	+'
	+
	 setup_askpass_helper

	 test_expect_success 'clone http repository' '

but this has a few issues:

  - it's not necessarily portable. The http2 apache module might not be
    available on all systems. Further, the http2 module isn't compatible
    with the prefork mpm, so we have to switch to something else. But we
    don't necessarily know what's available. It would be nice if we
    could have conditional config, but IfModule only tells us if a
    module is already loaded, not whether it is available at all.

    This might be a non-issue. The http tests are already optional, and
    modern-enough systems may just have both of these. But...

  - if we do this, then we'd no longer be testing HTTP/1.1 at all. I'm
    not sure how much that matters since it's all handled by curl under
    the hood, but I'd worry that some detail leaks through. We'd
    probably want two scripts running similar tests, one with HTTP/2 and
    one with HTTP/1.1.

  - speaking of which, a later test fails with the patch above! The
    problem is that it is making sure we used a chunked
    transfer-encoding by looking for that header in the trace. But
    HTTP/2 doesn't support that, as it has its own streaming mechanisms
    (the overall operation works fine; we just don't see the header in
    the trace).

Furthermore, even with the changes above, this test still does not
detect the current failure, because we see _both_ HTTP/1.1 and HTTP/2
requests, which confuse it. Quoting only the interesting bits from the
resulting trace file, we first see:

  => Send header: GET /auth/smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
  => Send header: Connection: Upgrade, HTTP2-Settings
  => Send header: Upgrade: h2c
  => Send header: HTTP2-Settings: AAMAAABkAAQCAAAAAAIAAAAA

  <= Recv header: HTTP/1.1 401 Unauthorized
  <= Recv header: Date: Wed, 22 Sep 2021 20:03:32 GMT
  <= Recv header: Server: Apache/2.4.49 (Debian)
  <= Recv header: WWW-Authenticate: Basic realm="git-auth"

So the client asks for HTTP/2, but Apache does not do the upgrade for
the 401 response. Then the client repeats with credentials:

  => Send header: GET /auth/smart/repo.git/info/refs?service=git-upload-pack HTTP/1.1
  => Send header: Authorization: Basic <redacted>
  => Send header: Connection: Upgrade, HTTP2-Settings
  => Send header: Upgrade: h2c
  => Send header: HTTP2-Settings: AAMAAABkAAQCAAAAAAIAAAAA

  <= Recv header: HTTP/1.1 101 Switching Protocols
  <= Recv header: Upgrade: h2c
  <= Recv header: Connection: Upgrade
  <= Recv header: HTTP/2 200
  <= Recv header: content-type: application/x-git-upload-pack-advertisement

So the client does properly redact there, because we're speaking
HTTP/1.1, and the server indicates it can do the upgrade. And then the
client will make further requests using HTTP/2:

  => Send header: POST /auth/smart/repo.git/git-upload-pack HTTP/2
  => Send header: authorization: Basic dXNlckBob3N0OnBhc3NAaG9zdA==
  => Send header: content-type: application/x-git-upload-pack-request

And there we can see that the credential is _not_ redacted. This part of
the test is what gets confused:

	# Ensure that there is no "Basic" followed by a base64 string, but that
	# the auth details are redacted
	! grep "Authorization: Basic [0-9a-zA-Z+/]" trace &&
	grep "Authorization: Basic <redacted>" trace

The first grep does not match the un-redacted HTTP/2 header, because
it insists on an uppercase "A". And the second one does find the
HTTP/1.1 header. So as far as the test is concerned, everything is OK,
but it failed to notice the un-redacted lines.

We can make this test (and the other related ones) more robust by adding
"-i" to grep case-insensitively. This isn't really doing anything for
now, since we're not actually speaking HTTP/2, but it future-proofs the
tests for a day when we do (either we add explicit HTTP/2 test support,
or it's eventually enabled by default by our Apache+curl test setup).
And it doesn't hurt in the meantime for the tests to be more careful.

The change to use "grep -i", coupled with the changes to use HTTP/2
shown above, causes the test to fail with the current code, and pass
after this patch is applied.

And finally, there's one other way to demonstrate the issue (and how I
actually found it originally). Looking at GIT_TRACE_CURL output against
github.com, you'll see the unredacted output, even if you didn't set
http.version. That's because setting it is only necessary for curl to
send the extra headers in its HTTP/1.1 request that say "Hey, I speak
HTTP/2; upgrade if you do, too". But for a production site speaking
https, the server advertises via ALPN, a TLS extension, that it supports
HTTP/2, and the client can immediately start using it.

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