@@ -68,6 +68,7 @@ pub struct Options {
68
68
pub ( crate ) git_dir_trust : Option < git_sec:: Trust > ,
69
69
pub ( crate ) filter_config_section : Option < fn ( & git_config:: file:: Metadata ) -> bool > ,
70
70
pub ( crate ) lossy_config : Option < bool > ,
71
+ pub ( crate ) bail_if_untrusted : bool ,
71
72
}
72
73
73
74
#[ derive( Default , Clone ) ]
@@ -118,7 +119,6 @@ impl Options {
118
119
git_prefix : deny,
119
120
}
120
121
} ,
121
- ..Permissions :: default ( )
122
122
} )
123
123
}
124
124
}
@@ -166,6 +166,17 @@ impl Options {
166
166
self
167
167
}
168
168
169
+ /// If true, default false, and if the repository's trust level is not `Full`
170
+ /// (see [`with()`][Self::with()] for more), then the open operation will fail.
171
+ ///
172
+ /// Use this to mimic `git`s way of handling untrusted repositories. Note that `gitoxide` solves
173
+ /// this by not using configuration from untrusted sources and by generally being secured against
174
+ /// doctored input files which at worst could cause out-of-memory at the time of writing.
175
+ pub fn bail_if_untrusted ( mut self , toggle : bool ) -> Self {
176
+ self . bail_if_untrusted = toggle;
177
+ self
178
+ }
179
+
169
180
/// Set the filter which determines if a configuration section can be used to read values from,
170
181
/// hence it returns true if it is eligible.
171
182
///
@@ -201,13 +212,15 @@ impl git_sec::trust::DefaultForLevel for Options {
201
212
git_dir_trust : git_sec:: Trust :: Full . into ( ) ,
202
213
filter_config_section : Some ( config:: section:: is_trusted) ,
203
214
lossy_config : None ,
215
+ bail_if_untrusted : false ,
204
216
} ,
205
217
git_sec:: Trust :: Reduced => Options {
206
218
object_store_slots : git_odb:: store:: init:: Slots :: Given ( 32 ) , // limit resource usage
207
219
replacement_objects : ReplacementObjects :: Disable , // don't be tricked into seeing manufactured objects
208
220
permissions : Permissions :: default_for_level ( level) ,
209
221
git_dir_trust : git_sec:: Trust :: Reduced . into ( ) ,
210
222
filter_config_section : Some ( config:: section:: is_trusted) ,
223
+ bail_if_untrusted : false ,
211
224
lossy_config : None ,
212
225
} ,
213
226
}
@@ -301,12 +314,8 @@ impl ThreadSafeRepository {
301
314
filter_config_section,
302
315
ref replacement_objects,
303
316
lossy_config,
304
- permissions :
305
- Permissions {
306
- git_dir : ref git_dir_perm,
307
- ref env,
308
- config,
309
- } ,
317
+ bail_if_untrusted,
318
+ permissions : Permissions { ref env, config } ,
310
319
} = options;
311
320
let git_dir_trust = git_dir_trust. expect ( "trust must be been determined by now" ) ;
312
321
@@ -344,7 +353,7 @@ impl ThreadSafeRepository {
344
353
config,
345
354
) ?;
346
355
347
- if * * git_dir_perm != git_sec:: ReadWrite :: all ( ) {
356
+ if bail_if_untrusted && git_dir_trust != git_sec:: Trust :: Full {
348
357
check_safe_directories ( & git_dir, git_install_dir. as_deref ( ) , home. as_deref ( ) , & config) ?;
349
358
}
350
359
0 commit comments