Skip to content

Commit a52ed76

Browse files
peffdscho
authored andcommitted
fast-import: disallow "feature import-marks" by default
As with export-marks in the previous commit, import-marks can access the filesystem. This is significantly less dangerous than export-marks because it only involves reading from arbitrary paths, rather than writing them. However, it could still be surprising and have security implications (e.g., exfiltrating data from a service that accepts fast-import streams). Let's lump it (and its "if-exists" counterpart) in with export-marks, and enable the in-stream version only if --allow-unsafe-features is set. Signed-off-by: Jeff King <[email protected]>
1 parent 68061e3 commit a52ed76

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

Documentation/git-fast-import.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,8 @@ OPTIONS
5757
allowing fast-import to access the filesystem outside of the
5858
repository). These options are disabled by default, but can be
5959
allowed by providing this option on the command line. This
60-
currently impacts only the `feature export-marks` command.
60+
currently impacts only the `export-marks`, `import-marks`, and
61+
`import-marks-if-exists` feature commands.
6162
+
6263
Only enable this option if you trust the program generating the
6364
fast-import stream! This option is enabled automatically for

fast-import.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3344,8 +3344,10 @@ static int parse_one_feature(const char *feature, int from_stream)
33443344
if (skip_prefix(feature, "date-format=", &arg)) {
33453345
option_date_format(arg);
33463346
} else if (skip_prefix(feature, "import-marks=", &arg)) {
3347+
check_unsafe_feature("import-marks", from_stream);
33473348
option_import_marks(arg, from_stream, 0);
33483349
} else if (skip_prefix(feature, "import-marks-if-exists=", &arg)) {
3350+
check_unsafe_feature("import-marks-if-exists", from_stream);
33493351
option_import_marks(arg, from_stream, 1);
33503352
} else if (skip_prefix(feature, "export-marks=", &arg)) {
33513353
check_unsafe_feature(feature, from_stream);

t/t9300-fast-import.sh

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2106,6 +2106,14 @@ test_expect_success 'R: abort on receiving feature after data command' '
21062106
test_must_fail git fast-import <input
21072107
'
21082108

2109+
test_expect_success 'R: import-marks features forbidden by default' '
2110+
>git.marks &&
2111+
echo "feature import-marks=git.marks" >input &&
2112+
test_must_fail git fast-import <input &&
2113+
echo "feature import-marks-if-exists=git.marks" >input &&
2114+
test_must_fail git fast-import <input
2115+
'
2116+
21092117
test_expect_success 'R: only one import-marks feature allowed per stream' '
21102118
>git.marks &&
21112119
>git2.marks &&
@@ -2114,7 +2122,7 @@ test_expect_success 'R: only one import-marks feature allowed per stream' '
21142122
feature import-marks=git2.marks
21152123
EOF
21162124
2117-
test_must_fail git fast-import <input
2125+
test_must_fail git fast-import --allow-unsafe-features <input
21182126
'
21192127

21202128
test_expect_success 'R: export-marks feature forbidden by default' '
@@ -2210,7 +2218,8 @@ test_expect_success 'R: feature import-marks-if-exists' '
22102218
rm -f io.marks &&
22112219
>expect &&
22122220
2213-
git fast-import --export-marks=io.marks <<-\EOF &&
2221+
git fast-import --export-marks=io.marks \
2222+
--allow-unsafe-features <<-\EOF &&
22142223
feature import-marks-if-exists=not_io.marks
22152224
EOF
22162225
test_cmp expect io.marks &&
@@ -2221,7 +2230,8 @@ test_expect_success 'R: feature import-marks-if-exists' '
22212230
echo ":1 $blob" >expect &&
22222231
echo ":2 $blob" >>expect &&
22232232
2224-
git fast-import --export-marks=io.marks <<-\EOF &&
2233+
git fast-import --export-marks=io.marks \
2234+
--allow-unsafe-features <<-\EOF &&
22252235
feature import-marks-if-exists=io.marks
22262236
blob
22272237
mark :2
@@ -2234,7 +2244,8 @@ test_expect_success 'R: feature import-marks-if-exists' '
22342244
echo ":3 $blob" >>expect &&
22352245
22362246
git fast-import --import-marks=io.marks \
2237-
--export-marks=io.marks <<-\EOF &&
2247+
--export-marks=io.marks \
2248+
--allow-unsafe-features <<-\EOF &&
22382249
feature import-marks-if-exists=not_io.marks
22392250
blob
22402251
mark :3
@@ -2247,7 +2258,8 @@ test_expect_success 'R: feature import-marks-if-exists' '
22472258
>expect &&
22482259
22492260
git fast-import --import-marks-if-exists=not_io.marks \
2250-
--export-marks=io.marks <<-\EOF &&
2261+
--export-marks=io.marks \
2262+
--allow-unsafe-features <<-\EOF &&
22512263
feature import-marks-if-exists=io.marks
22522264
EOF
22532265
test_cmp expect io.marks

0 commit comments

Comments
 (0)