git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: Clemens Buchacher <drizzd@aon.at>, git@vger.kernel.org
Subject: Re: [PATCH 2/2] fix http auth with multiple curl handles
Date: Fri, 13 Apr 2012 02:16:22 -0400	[thread overview]
Message-ID: <20120413061622.GA27591@sigill.intra.peff.net> (raw)
In-Reply-To: <7v4nso4lb3.fsf@alter.siamese.dyndns.org>

On Thu, Apr 12, 2012 at 03:50:08PM -0700, Junio C Hamano wrote:

> > diff --git a/http.c b/http.c
> > index f3f83d7..374c3bb 100644
> > --- a/http.c
> > +++ b/http.c
> > @@ -211,12 +211,12 @@ static int http_options(const char *var, const char *value, void *cb)
> >  static void init_curl_http_auth(CURL *result)
> >  {
> >  	if (http_auth.username) {
> > -		struct strbuf up = STRBUF_INIT;
> > +		static struct strbuf up = STRBUF_INIT;
> >  		credential_fill(&http_auth);
> > +		strbuf_reset(&up);
> >  		strbuf_addf(&up, "%s:%s",
> >  			    http_auth.username, http_auth.password);
> > -		curl_easy_setopt(result, CURLOPT_USERPWD,
> > -				 strbuf_detach(&up, NULL));
> > +		curl_easy_setopt(result, CURLOPT_USERPWD, up.buf);
> >  	}
> >  }
> 
> Yeah, that's sad but I agree that is probably the best we could do.  Do
> you want me to squash it in?

We can use an #if-macro and only do the static thing for older versions
of curl (newer versions copy for us). But since we'd have to carry the
old code anyway, it doesn't clean up much.  However, since there is an
even newer interface for giving curl the credential, it might be worth
conditionally including that.

I'd rather not squash this bit. It's sufficiently subtle that I'd rather
do it on top as a separate patch. Plus I gotta keep up my shortlog
stats. ;)

So here are the two patches I think we should apply on top of what you
have in ct/http-multi-curl-auth.

  [1/2]: http: clean up leak in init_curl_http_auth
  [2/2]: http: use newer curl options for setting credentials

> > By the way, this touches on an area that I noticed while refactoring the
> > http auth code a while ago, but decided not to tackle at the time. We
> > fill in the auth information early, and then never bother to revisit it
> > as URLs change. So for example, if I got a redirect from host A to host
> > B, we would continue to use the credential for host A and host B. Which
> > is maybe convenient, and maybe a security issue.
> 
> Good point.  Do we follow redirects, though?

Curl follows them for us, since we set CURLOPT_FOLLOWLOCATION. However,
it does say this under CURLOPT_USERPWD (which I somehow missed the last
time I looked into this issue):

  When using HTTP and CURLOPT_FOLLOWLOCATION, libcurl might perform
  several requests to possibly different hosts. libcurl will only send
  this user and password information to hosts using the initial host
  name (unless CURLOPT_UNRESTRICTED_AUTH is set), so if libcurl
  follows locations to other hosts it will not send the user and
  password to those. This is enforced to prevent accidental information
  leakage.

So it looks like we are already doing the safe thing (unless we redirect
ourselves outside of curl, but I don't think we ever do so). We won't
properly retry auth if we get a 401 on a redirect (we never retry auth
if we already had both a username and password; we complain and exit).
But nobody has been complaining about that, so I guess it is a
non-issue.

-Peff

  reply	other threads:[~2012-04-13  6:16 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-04-01 18:48 Cannot clone the git repository shared over http with authorization Artur R. Czechowski
2012-04-01 19:45 ` Clemens Buchacher
2012-04-01 20:53   ` Clemens Buchacher
2012-04-02  8:31   ` Jeff King
2012-04-10  9:53     ` Clemens Buchacher
2012-04-10  9:53       ` [PATCH 1/2] http auth fails with multiple curl handles Clemens Buchacher
2012-04-10  9:53       ` [PATCH 2/2] fix http auth " Clemens Buchacher
2012-04-12  7:09         ` Jeff King
2012-04-12 22:50           ` Junio C Hamano
2012-04-13  6:16             ` Jeff King [this message]
2012-04-13  6:18               ` [PATCH 1/2] http: clean up leak in init_curl_http_auth Jeff King
2012-04-13  6:19               ` [PATCH 2/2] http: use newer curl options for setting credentials Jeff King

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

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

  git send-email \
    --in-reply-to=20120413061622.GA27591@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=drizzd@aon.at \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    /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.
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 NNTP newsgroup(s).