File tree Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Expand file tree Collapse file tree 2 files changed +37
-1
lines changed Original file line number Diff line number Diff line change @@ -1244,10 +1244,28 @@ impl Config {
12441244 ) ;
12451245 }
12461246
1247- let toml_v = toml:: from_document ( doc) . with_context ( || {
1247+ let toml_v: toml :: Value = toml:: from_document ( doc) . with_context ( || {
12481248 format ! ( "failed to parse value from --config argument `{arg}`" )
12491249 } ) ?;
12501250
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+
12511269 CV :: from_toml ( Definition :: Cli , toml_v)
12521270 . with_context ( || format ! ( "failed to convert --config argument `{arg}`" ) ) ?
12531271 } ;
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`)",
368368 ) ;
369369}
370370
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+
371389#[ cargo_test]
372390fn no_inline_table_value ( ) {
373391 // Disallow inline tables
You can’t perform that action at this time.
0 commit comments