git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: "brian m. carlson" <sandals@crustytoothpaste.net>,
	Nicolas Morey-Chaisemartin <nicolas@morey-chaisemartin.com>,
	git@vger.kernel.org
Subject: Re: [RFC] imap-send: escape backslash in password
Date: Fri, 4 Aug 2017 16:18:36 -0400	[thread overview]
Message-ID: <20170804201836.3t5fp7v5xfwz64h4@sigill.intra.peff.net> (raw)
In-Reply-To: <20170804200643.gq5pqeoeje3xii57@genre.crustytoothpaste.net>

On Fri, Aug 04, 2017 at 08:06:43PM +0000, brian m. carlson wrote:

> On Fri, Aug 04, 2017 at 06:16:53PM +0200, Nicolas Morey-Chaisemartin wrote:
> >  static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *folder)
> >  {
> >  	struct credential cred = CREDENTIAL_INIT;
> > @@ -1090,7 +1116,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *f
> >  			if (!srvc->user)
> >  				srvc->user = xstrdup(cred.username);
> >  			if (!srvc->pass)
> > -				srvc->pass = xstrdup(cred.password);
> > +				srvc->pass = imap_escape_password(cred.password);
> >  		}
> >  
> >  		if (srvc->auth_method) {
> 
> I'm not sure if this is correct.  It looks like this username and
> password are used by whatever authentication method we use, whether
> that's LOGIN or CRAM-MD5.  I don't think we'd want to encode the
> password here before sending it through the CRAM-MD5 authenticator.

Yeah. This is an on-the-wire encoding issue, and should happen as part
of forming the protocol string to send. So:

  imap_exec(ctx, NULL, "LOGIN \"%s\" \"%s\"", srvc->user, srvc->pass)

is probably where it needs to happen.

It looks like this issue is present in a lot of other places, too. Just
a few lines below I see:

  imap_exec(ctx, NULL, "CREATE \"%s\"", ctx->name)

As an aside, these are all potential injection vulnerabilities, too.
E.g., if I specify my folder as

  foo"\n. DELETE "bar

then we'd issue an accidental deletion. I doubt it's a big deal in
practice, as it's not common to feed attacker-controlled strings to
imap-send. But we should probably fix it anyway.

The right interface is probably to teach imap_exec() to take a
NULL-terminated list of items (rather than a format string) and then
quote each one appropriately.

-Peff

      reply	other threads:[~2017-08-04 20:18 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-04 16:16 [RFC] imap-send: escape backslash in password Nicolas Morey-Chaisemartin
2017-08-04 19:09 ` Junio C Hamano
2017-08-04 19:32   ` Nicolas Morey-Chaisemartin
2017-08-04 19:46   ` Andreas Schwab
2017-08-04 20:22     ` Jeff King
2017-08-04 21:18       ` Junio C Hamano
2017-08-04 21:22         ` Jeff King
2017-08-06 19:12           ` Nicolas Morey-Chaisemartin
2017-08-07 20:58             ` Jeff King
2017-08-07  1:34           ` Junio C Hamano
2017-08-08  7:25             ` Jeff King
2017-08-08 16:54               ` Junio C Hamano
2017-08-09 12:04                 ` Jeff King
2017-08-04 20:06 ` brian m. carlson
2017-08-04 20:18   ` Jeff King [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170804201836.3t5fp7v5xfwz64h4@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=nicolas@morey-chaisemartin.com \
    --cc=sandals@crustytoothpaste.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).