git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [RFC] imap-send: escape backslash in password

From
Jeff King <peff@peff.net>
Date
Aug 4, 2017, 20:18 UTC
Message-ID
<20170804201836.3t5fp7v5xfwz64h4@sigill.intra.peff.net>
In-Reply-To
<20170804200643.gq5pqeoeje3xii57@genre.crustytoothpaste.net>
On Fri, Aug 04, 2017 at 08:06:43PM +0000, brian m. carlson wrote:
Show 18 quoted lines
> 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
Previous: brian m. carlson
Message 15 of 15 in “[RFC] imap-send: escape backslash in password”
  1. Nicolas Morey-ChaisemartinAug 4, 2017
  2. Junio C HamanoAug 4, 2017
  3. Nicolas Morey-ChaisemartinAug 4, 2017
  4. Andreas SchwabAug 4, 2017
  5. Jeff KingAug 4, 2017
  6. Junio C HamanoAug 4, 2017
  7. Jeff KingAug 4, 2017
  8. Nicolas Morey-ChaisemartinAug 6, 2017
  9. Jeff KingAug 7, 2017
  10. Junio C HamanoAug 7, 2017
  11. Jeff KingAug 8, 2017
  12. Junio C HamanoAug 8, 2017
  13. Jeff KingAug 9, 2017
  14. brian m. carlsonAug 4, 2017
  15. Jeff KingAug 4, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.