Skip to content

Commit 6af8572

Browse files
committed
http transport: cap number of authentication replays
Put a limit on the number of authentication replays in the HTTP transport. Standardize on 7 replays for authentication or redirects, which matches the behavior of the WinHTTP transport.
1 parent 2265481 commit 6af8572

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

src/transports/http.c

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ typedef struct {
6666
unsigned sent_request : 1,
6767
received_response : 1,
6868
chunked : 1,
69-
redirect_count : 3;
69+
replay_count : 3;
7070
} http_stream;
7171

7272
typedef struct {
@@ -424,6 +424,12 @@ static int on_headers_complete(http_parser *parser)
424424
git_buf buf = GIT_BUF_INIT;
425425
int allowed_proxy_auth_types = 0, allowed_www_auth_types = 0;
426426

427+
/* Enforce a reasonable cap on the number of replays */
428+
if (s->replay_count++ >= GIT_HTTP_REPLAY_MAX) {
429+
giterr_set(GITERR_NET, "too many redirects or authentication replays");
430+
return t->parse_error = PARSE_ERROR_GENERIC;
431+
}
432+
427433
/* Both parse_header_name and parse_header_value are populated
428434
* and ready for consumption. */
429435
if (VALUE == t->last_cb)
@@ -472,11 +478,6 @@ static int on_headers_complete(http_parser *parser)
472478
parser->status_code == 308) &&
473479
t->location) {
474480

475-
if (s->redirect_count >= 7) {
476-
giterr_set(GITERR_NET, "too many redirects");
477-
return t->parse_error = PARSE_ERROR_GENERIC;
478-
}
479-
480481
if (gitno_connection_data_from_url(&t->gitserver_data, t->location, s->service_url) < 0)
481482
return t->parse_error = PARSE_ERROR_GENERIC;
482483

@@ -489,8 +490,6 @@ static int on_headers_complete(http_parser *parser)
489490
t->location = NULL;
490491

491492
t->connected = 0;
492-
s->redirect_count++;
493-
494493
t->parse_error = PARSE_ERROR_REPLAY;
495494
return 0;
496495
}

src/transports/http.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
#include "buffer.h"
1212

13+
#define GIT_HTTP_REPLAY_MAX 7
14+
1315
GIT_INLINE(int) git_http__user_agent(git_buf *buf)
1416
{
1517
const char *ua = git_libgit2__user_agent();

src/transports/winhttp.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ static int winhttp_stream_read(
932932

933933
replay:
934934
/* Enforce a reasonable cap on the number of replays */
935-
if (++replay_count >= 7) {
935+
if (replay_count++ >= GIT_HTTP_REPLAY_MAX) {
936936
giterr_set(GITERR_NET, "too many redirects or authentication replays");
937937
return -1;
938938
}

0 commit comments

Comments
 (0)