Commit c417af4
reject control chars in written values in configuration
Reject CR, LF, and NUL in GitConfigParser values before writing them
to git config files (which also is a deviation from Git which escapes them).
GitConfigParser._write() serializes embedded newlines as indented
continuation lines by replacing "\n" with "\n\t". Git itself skips
leading whitespace before parsing config tokens, so an injected value
such as:
foo
[core]
hooksPath=/tmp/hooks
is written in a form where the indented "[core]" line is still parsed by
Git as a real section header. This lets attacker-controlled input passed
to config_writer().set_value() poison repository config, including
core.hooksPath, and redirect hook execution for later Git operations.
Fail closed instead of stripping or normalizing these characters. Silent
normalization can hide unsanitized caller input, and GitPython does not
currently round-trip Git-style escaped values such as "\n" as embedded
newlines.
Apply the validation to set_value(), add_value(), and the public set()
path so callers cannot bypass the safer helper API. Add regression tests
for the advisory payload and for CR, LF, NUL, and bytes values.
This preserves existing read behavior for config files that already
contain multiline values while preventing GitPython from writing new
unsafe values.
Co-authored-by: Sebastian Thiel <sebastian.thiel@icloud.com>1 parent 5a15361 commit c417af4
2 files changed
Lines changed: 55 additions & 2 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
882 | 882 | | |
883 | 883 | | |
884 | 884 | | |
| 885 | + | |
| 886 | + | |
| 887 | + | |
| 888 | + | |
| 889 | + | |
| 890 | + | |
| 891 | + | |
| 892 | + | |
| 893 | + | |
| 894 | + | |
| 895 | + | |
| 896 | + | |
| 897 | + | |
| 898 | + | |
| 899 | + | |
| 900 | + | |
| 901 | + | |
| 902 | + | |
885 | 903 | | |
886 | 904 | | |
887 | 905 | | |
| |||
902 | 920 | | |
903 | 921 | | |
904 | 922 | | |
| 923 | + | |
905 | 924 | | |
906 | 925 | | |
907 | | - | |
| 926 | + | |
908 | 927 | | |
909 | 928 | | |
910 | 929 | | |
| |||
929 | 948 | | |
930 | 949 | | |
931 | 950 | | |
| 951 | + | |
932 | 952 | | |
933 | 953 | | |
934 | | - | |
| 954 | + | |
935 | 955 | | |
936 | 956 | | |
937 | 957 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
150 | 150 | | |
151 | 151 | | |
152 | 152 | | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
153 | 186 | | |
154 | 187 | | |
155 | 188 | | |
| |||
0 commit comments