# git format-patch --in-reply-to allows header injection. Intended?

4 messages from 2014-09-04 to 2014-09-04. Participants: Niklas Hambüchen, Junio C Hamano.
Thread: https://gitlist.dev/t/37491

## Niklas Hambüchen, 2014-09-04 21:21

Subject: git format-patch --in-reply-to allows header injection. Intended?
Message-ID: <5408D7ED.9010203@nh2.me>
URL: https://gitlist.dev/e/5408D7ED.9010203%40nh2.me

```
Hi,

I just wanted to ask if the --in-reply-to flag of git format-patch is
supposed to write the given string unmodified into the email or whether
it ought to perform some check against header injection.

For example, if you pass "--in-reply-to=<msgid>\nTo: <other@example.com"
(notice lack of trailing `>`), then the generated email will actually
contain a
  To: <other@example.com>
header.

(Depending on your shell you might also use "--in-reply-to=`cat`" to get
the above working more easily.)

Is this known and working as intended, or undesired?

Thanks!
Niklas

```

## Junio C Hamano, 2014-09-04 21:36

Subject: Re: git format-patch --in-reply-to allows header injection. Intended?
Message-ID: <xmqqppfbqd9x.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqppfbqd9x.fsf%40gitster.dls.corp.google.com
In-Reply-To: <5408D7ED.9010203@nh2.me>

```
Niklas Hambüchen <mail@nh2.me> writes:

> For example, if you pass "--in-reply-to=<msgid>\nTo: <other@example.com"
> (notice lack of trailing `>`), then the generated email will actually
> contain a
>   To: <other@example.com>
> header.

While I do not think of a reason to specify such a string to the
in-reply-to option (I'd rather edit the output in the editor if I
wanted to do anything fancy [*1*]), I do not think there is a reason
why you want to add a code to forbid such use, either.


[Footnote]

*1* For that matter, --in-reply-to option itself is superfluous.

```

## Niklas Hambüchen, 2014-09-04 21:42

Subject: Re: git format-patch --in-reply-to allows header injection. Intended?
Message-ID: <5408DCC5.8000607@nh2.me>
URL: https://gitlist.dev/e/5408DCC5.8000607%40nh2.me
In-Reply-To: <xmqqppfbqd9x.fsf@gitster.dls.corp.google.com>

```
On 04/09/14 23:36, Junio C Hamano wrote:
> While I do not think of a reason to specify such a string to the
> in-reply-to option (I'd rather edit the output in the editor if I
> wanted to do anything fancy [*1*]), I do not think there is a reason
> why you want to add a code to forbid such use, either.

My question was to find out whether I can pass untrusted user input to
--in-reply-to and expect that no header beyond "In-Reply-To" and
"References" is modified, but your answer makes clear that I cannot.

A possible alternative might have been that git verifies that the input
to --in-reply-to matches the format specified RFC2822 (section 3.6.4.).

Thanks!

```

## Junio C Hamano, 2014-09-04 23:59

Subject: Re: git format-patch --in-reply-to allows header injection. Intended?
Message-ID: <xmqqd2bbq6mi.fsf@gitster.dls.corp.google.com>
URL: https://gitlist.dev/e/xmqqd2bbq6mi.fsf%40gitster.dls.corp.google.com
In-Reply-To: <5408DCC5.8000607@nh2.me>

```
Niklas Hambüchen <mail@nh2.me> writes:

> On 04/09/14 23:36, Junio C Hamano wrote:
>> While I do not think of a reason to specify such a string to the
>> in-reply-to option (I'd rather edit the output in the editor if I
>> wanted to do anything fancy [*1*]), I do not think there is a reason
>> why you want to add a code to forbid such use, either.
>
> My question was to find out whether I can pass untrusted user input to
> ...

Ah, in general, anybody who passes unvetted user input to any Git
Porcelain deserves what s/he gets, so perhaps you would want to at
least make sure that the input is a single line, or something.

```
