File tree 2 files changed +37
-1
lines changed
2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -1244,10 +1244,28 @@ impl Config {
1244
1244
) ;
1245
1245
}
1246
1246
1247
- let toml_v = toml:: from_document ( doc) . with_context ( || {
1247
+ let toml_v: toml :: Value = toml:: from_document ( doc) . with_context ( || {
1248
1248
format ! ( "failed to parse value from --config argument `{arg}`" )
1249
1249
} ) ?;
1250
1250
1251
+ if toml_v
1252
+ . get ( "registry" )
1253
+ . and_then ( |v| v. as_table ( ) )
1254
+ . and_then ( |t| t. get ( "token" ) )
1255
+ . is_some ( )
1256
+ {
1257
+ bail ! ( "registry.token cannot be set through --config for security reasons" ) ;
1258
+ } else if let Some ( ( k, _) ) = toml_v
1259
+ . get ( "registries" )
1260
+ . and_then ( |v| v. as_table ( ) )
1261
+ . and_then ( |t| t. iter ( ) . find ( |( _, v) | v. get ( "token" ) . is_some ( ) ) )
1262
+ {
1263
+ bail ! (
1264
+ "registries.{}.token cannot be set through --config for security reasons" ,
1265
+ k
1266
+ ) ;
1267
+ }
1268
+
1251
1269
CV :: from_toml ( Definition :: Cli , toml_v)
1252
1270
. with_context ( || format ! ( "failed to convert --config argument `{arg}`" ) ) ?
1253
1271
} ;
Original file line number Diff line number Diff line change @@ -368,6 +368,24 @@ b=2` was not a TOML dotted key expression (such as `build.jobs = 2`)",
368
368
) ;
369
369
}
370
370
371
+ #[ cargo_test]
372
+ fn no_disallowed_values ( ) {
373
+ let config = ConfigBuilder :: new ( )
374
+ . config_arg ( "registry.token=\" hello\" " )
375
+ . build_err ( ) ;
376
+ assert_error (
377
+ config. unwrap_err ( ) ,
378
+ "registry.token cannot be set through --config for security reasons" ,
379
+ ) ;
380
+ let config = ConfigBuilder :: new ( )
381
+ . config_arg ( "registries.crates-io.token=\" hello\" " )
382
+ . build_err ( ) ;
383
+ assert_error (
384
+ config. unwrap_err ( ) ,
385
+ "registries.crates-io.token cannot be set through --config for security reasons" ,
386
+ ) ;
387
+ }
388
+
371
389
#[ cargo_test]
372
390
fn no_inline_table_value ( ) {
373
391
// Disallow inline tables
You can’t perform that action at this time.
0 commit comments