Skip to content

Commit afcb6ee

Browse files
committed
push --signed: tighten what the receiving end can ask to sign
Instead of blindly trusting the receiving side to give us a sensible nonce to sign, limit the length (max 256 bytes) and the alphabet (alnum and a few selected punctuations, enough to encode in base64) that can be used in nonce. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 45917f0 commit afcb6ee

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

send-pack.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,6 +279,28 @@ static int generate_push_cert(struct strbuf *req_buf,
279279
return update_seen;
280280
}
281281

282+
#define NONCE_LEN_LIMIT 256
283+
284+
static void reject_invalid_nonce(const char *nonce, int len)
285+
{
286+
int i = 0;
287+
288+
if (NONCE_LEN_LIMIT <= len)
289+
die("the receiving end asked to sign an invalid nonce <%.*s>",
290+
len, nonce);
291+
292+
for (i = 0; i < len; i++) {
293+
int ch = nonce[i] & 0xFF;
294+
if (isalnum(ch) ||
295+
ch == '-' || ch == '.' ||
296+
ch == '/' || ch == '+' ||
297+
ch == '=' || ch == '_')
298+
continue;
299+
die("the receiving end asked to sign an invalid nonce <%.*s>",
300+
len, nonce);
301+
}
302+
}
303+
282304
int send_pack(struct send_pack_args *args,
283305
int fd[], struct child_process *conn,
284306
struct ref *remote_refs,
@@ -321,6 +343,7 @@ int send_pack(struct send_pack_args *args,
321343
push_cert_nonce = server_feature_value("push-cert", &len);
322344
if (!push_cert_nonce)
323345
die(_("the receiving end does not support --signed push"));
346+
reject_invalid_nonce(push_cert_nonce, len);
324347
push_cert_nonce = xmemdupz(push_cert_nonce, len);
325348
}
326349

0 commit comments

Comments
 (0)