diff --git a/parity/cli/mod.rs b/parity/cli/mod.rs index 60d391ee9..b225ee189 100644 --- a/parity/cli/mod.rs +++ b/parity/cli/mod.rs @@ -466,9 +466,9 @@ usage! { "--jsonrpc-threads=[THREADS]", "Turn on additional processing threads in all RPC servers. Setting this to non-zero value allows parallel cpu-heavy queries execution.", - ARG arg_jsonrpc_cors: (Option) = None, or |c: &Config| otry!(c.rpc).cors.clone(), + ARG arg_jsonrpc_cors: (String) = "none", or |c: &Config| otry!(c.rpc).cors.as_ref().map(|vec| vec.join(",")), "--jsonrpc-cors=[URL]", - "Specify CORS header for JSON-RPC API responses.", + "Specify CORS header for JSON-RPC API responses. Special options: \"all\", \"none\".", ARG arg_jsonrpc_server_threads: (Option) = None, or |c: &Config| otry!(c.rpc).server_threads, "--jsonrpc-server-threads=[NUM]", @@ -538,9 +538,9 @@ usage! { "--ipfs-api-hosts=[HOSTS]", "List of allowed Host header values. This option will validate the Host header sent by the browser, it is additional security against some attack vectors. Special options: \"all\", \"none\".", - ARG arg_ipfs_api_cors: (Option) = None, or |c: &Config| otry!(c.ipfs).cors.clone(), + ARG arg_ipfs_api_cors: (String) = "none", or |c: &Config| otry!(c.ipfs).cors.as_ref().map(|vec| vec.join(",")), "--ipfs-api-cors=[URL]", - "Specify CORS header for IPFS API responses.", + "Specify CORS header for IPFS API responses. Special options: \"all\", \"none\".", ["Secret store options"] FLAG flag_no_secretstore: (bool) = false, or |c: &Config| otry!(c.secretstore).disable.clone(), @@ -1052,7 +1052,7 @@ struct Rpc { disable: Option, port: Option, interface: Option, - cors: Option, + cors: Option>, apis: Option>, hosts: Option>, server_threads: Option, @@ -1108,7 +1108,7 @@ struct Ipfs { enable: Option, port: Option, interface: Option, - cors: Option, + cors: Option>, hosts: Option>, } @@ -1468,7 +1468,7 @@ mod tests { flag_no_jsonrpc: false, arg_jsonrpc_port: 8545u16, arg_jsonrpc_interface: "local".into(), - arg_jsonrpc_cors: Some("null".into()), + arg_jsonrpc_cors: "null".into(), arg_jsonrpc_apis: "web3,eth,net,parity,traces,rpc,secretstore".into(), arg_jsonrpc_hosts: "none".into(), arg_jsonrpc_server_threads: None, @@ -1507,7 +1507,7 @@ mod tests { flag_ipfs_api: false, arg_ipfs_api_port: 5001u16, arg_ipfs_api_interface: "local".into(), - arg_ipfs_api_cors: Some("null".into()), + arg_ipfs_api_cors: "null".into(), arg_ipfs_api_hosts: "none".into(), // -- Sealing/Mining Options diff --git a/parity/cli/tests/config.full.toml b/parity/cli/tests/config.full.toml index a49717085..6502da1a2 100644 --- a/parity/cli/tests/config.full.toml +++ b/parity/cli/tests/config.full.toml @@ -49,7 +49,7 @@ reserved_peers = "./path_to_file" disable = false port = 8545 interface = "local" -cors = "null" +cors = ["null"] apis = ["web3", "eth", "net", "parity", "traces", "rpc", "secretstore"] hosts = ["none"] @@ -76,7 +76,7 @@ path = "$HOME/.parity/dapps" user = "test_user" pass = "test_pass" -[secretstore] +[secretstore] disable = false disable_http = false disable_acl_check = false @@ -91,7 +91,7 @@ path = "$HOME/.parity/secretstore" enable = false port = 5001 interface = "local" -cors = "null" +cors = ["null"] hosts = ["none"] [mining] diff --git a/parity/configuration.rs b/parity/configuration.rs index 715e63db5..93a39bc6f 100644 --- a/parity/configuration.rs +++ b/parity/configuration.rs @@ -775,13 +775,19 @@ impl Configuration { apis.join(",") } - fn cors(cors: Option<&String>) -> Option> { - cors.map(|ref c| c.split(',').map(Into::into).collect()) + fn cors(cors: &str) -> Option> { + match cors { + "none" => return Some(Vec::new()), + "*" | "all" | "any" => return None, + _ => {}, + } + + Some(cors.split(',').map(Into::into).collect()) } fn rpc_cors(&self) -> Option> { - let cors = self.args.arg_jsonrpc_cors.as_ref().or(self.args.arg_rpccorsdomain.as_ref()); - Self::cors(cors) + let cors = self.args.arg_rpccorsdomain.clone().unwrap_or_else(|| self.args.arg_jsonrpc_cors.to_owned()); + Self::cors(&cors) } fn ipfs_cors(&self) -> Option> { @@ -1458,7 +1464,7 @@ mod tests { assert_eq!(net.rpc_enabled, true); assert_eq!(net.rpc_interface, "0.0.0.0".to_owned()); assert_eq!(net.rpc_port, 8000); - assert_eq!(conf.rpc_cors(), Some(vec!["*".to_owned()])); + assert_eq!(conf.rpc_cors(), None); assert_eq!(conf.rpc_apis(), "web3,eth".to_owned()); } @@ -1525,8 +1531,8 @@ mod tests { let conf2 = parse(&["parity", "--ipfs-api-cors", "http://parity.io,http://something.io"]); // then - assert_eq!(conf0.ipfs_cors(), None); - assert_eq!(conf1.ipfs_cors(), Some(vec!["*".into()])); + assert_eq!(conf0.ipfs_cors(), Some(vec![])); + assert_eq!(conf1.ipfs_cors(), None); assert_eq!(conf2.ipfs_cors(), Some(vec!["http://parity.io".into(),"http://something.io".into()])); } diff --git a/parity/ipfs.rs b/parity/ipfs.rs index 45c3f7062..ac9a4662b 100644 --- a/parity/ipfs.rs +++ b/parity/ipfs.rs @@ -34,8 +34,8 @@ impl Default for Configuration { enabled: false, port: 5001, interface: "127.0.0.1".into(), - cors: None, - hosts: Some(Vec::new()), + cors: Some(vec![]), + hosts: Some(vec![]), } } } diff --git a/parity/rpc.rs b/parity/rpc.rs index 3a202b590..d17b77ccd 100644 --- a/parity/rpc.rs +++ b/parity/rpc.rs @@ -59,8 +59,8 @@ impl Default for HttpConfiguration { interface: "127.0.0.1".into(), port: 8545, apis: ApiSet::UnsafeContext, - cors: None, - hosts: Some(Vec::new()), + cors: Some(vec![]), + hosts: Some(vec![]), server_threads: 1, processing_threads: 4, } @@ -98,7 +98,7 @@ impl From for HttpConfiguration { interface: conf.interface, port: conf.port, apis: rpc_apis::ApiSet::UnsafeContext, - cors: None, + cors: Some(vec![]), hosts: conf.hosts, server_threads: 1, processing_threads: 0,