Skip to content

Strip invalid characters in signatures on commit

Markus Koller requested to merge strip-invalid-characters-in-signature into master

What does this MR do?

When creating a commit, remove angle brackets (<>) and newlines (\n) from the name and email fields for the author and committer. This aligns the behaviour with Git CLI (see background below).

This addresses gitlab#19684 (closed), where committing fails if the user's display name contains angle brackets. The decision was to keep supporting these characters in GitLab Rails, because the display name is a free-form text field and we currently don't restrict the format in any way.

Background

Git CLI strips certain characters (.,:;<>"\', and ASCII 0-32) from the start and end of the name and email fields for the author and committer. In addition, it also removes angle brackets (<>) and newlines (\n) in the middle. Having these characters in .gitconfig does not cause an error, so this only takes effect when creating a commit.

This is implemented in the strbuf_addstr_without_crud function: https://github.com/git/git/blob/b02fd2accad4d48078671adf38fe5b5976d77304/ident.c#L221-L262

libgit2 implements the character stripping at the start and end, but doesn't remove the ones in the middle. Instead it checks for remaining angle brackets and aborts.

This is implemented in the extract_trimmed and git_signature_new functions: https://github.com/libgit2/libgit2/blob/cb17630b75dbdc502c21da8e73641fa932bc8c6b/src/signature.c#L51-L97

Related issues

This has been reported upstream at https://github.com/libgit2/libgit2/issues/5342. If the suggested change is implemented, we could remove this code again in Gitaly after upgrading libgit2 and Rugged.

Edited by GitLab Release Tools Bot

Merge request reports

Loading