diff options
author | gary rong <garyrong0905@gmail.com> | 2019-04-04 19:03:10 +0800 |
---|---|---|
committer | Péter Szilágyi <peterke@gmail.com> | 2019-04-04 19:03:10 +0800 |
commit | d5cae48bae81cd6072255150162b26a3653f176e (patch) | |
tree | e516341d29d6fbffbac0f389ef012fb273326c8b /node | |
parent | 9b3601cfce4d61cd303f5e243813fa89426259d4 (diff) | |
download | go-tangerine-d5cae48bae81cd6072255150162b26a3653f176e.tar go-tangerine-d5cae48bae81cd6072255150162b26a3653f176e.tar.gz go-tangerine-d5cae48bae81cd6072255150162b26a3653f176e.tar.bz2 go-tangerine-d5cae48bae81cd6072255150162b26a3653f176e.tar.lz go-tangerine-d5cae48bae81cd6072255150162b26a3653f176e.tar.xz go-tangerine-d5cae48bae81cd6072255150162b26a3653f176e.tar.zst go-tangerine-d5cae48bae81cd6072255150162b26a3653f176e.zip |
accounts, cmd, internal: disable unlock account on open HTTP (#17037)
* cmd, accounts, internal, node, rpc, signer: insecure unlock protect
* all: strict unlock API by rpc
* cmd/geth: check before printing warning log
* accounts, cmd/geth, internal: tiny polishes
Diffstat (limited to 'node')
-rw-r--r-- | node/config.go | 57 | ||||
-rw-r--r-- | node/node.go | 5 | ||||
-rw-r--r-- | node/service.go | 6 |
3 files changed, 44 insertions, 24 deletions
diff --git a/node/config.go b/node/config.go index 2f871e478..46876c157 100644 --- a/node/config.go +++ b/node/config.go @@ -88,6 +88,9 @@ type Config struct { // scrypt KDF at the expense of security. UseLightweightKDF bool `toml:",omitempty"` + // InsecureUnlockAllowed allows user to unlock accounts in unsafe http environment. + InsecureUnlockAllowed bool `toml:",omitempty"` + // NoUSB disables hardware wallet monitoring and connectivity. NoUSB bool `toml:",omitempty"` @@ -106,29 +109,6 @@ type Config struct { // for ephemeral nodes). HTTPPort int `toml:",omitempty"` - // GraphQLHost is the host interface on which to start the GraphQL server. If this - // field is empty, no GraphQL API endpoint will be started. - GraphQLHost string `toml:",omitempty"` - - // GraphQLPort is the TCP port number on which to start the GraphQL server. The - // default zero value is/ valid and will pick a port number randomly (useful - // for ephemeral nodes). - GraphQLPort int `toml:",omitempty"` - - // GraphQLCors is the Cross-Origin Resource Sharing header to send to requesting - // clients. Please be aware that CORS is a browser enforced security, it's fully - // useless for custom HTTP clients. - GraphQLCors []string `toml:",omitempty"` - - // GraphQLVirtualHosts is the list of virtual hostnames which are allowed on incoming requests. - // This is by default {'localhost'}. Using this prevents attacks like - // DNS rebinding, which bypasses SOP by simply masquerading as being within the same - // origin. These attacks do not utilize CORS, since they are not cross-domain. - // By explicitly checking the Host-header, the server will not allow requests - // made against the server with a malicious host domain. - // Requests using ip address directly are not affected - GraphQLVirtualHosts []string `toml:",omitempty"` - // HTTPCors is the Cross-Origin Resource Sharing header to send to requesting // clients. Please be aware that CORS is a browser enforced security, it's fully // useless for custom HTTP clients. @@ -178,6 +158,29 @@ type Config struct { // private APIs to untrusted users is a major security risk. WSExposeAll bool `toml:",omitempty"` + // GraphQLHost is the host interface on which to start the GraphQL server. If this + // field is empty, no GraphQL API endpoint will be started. + GraphQLHost string `toml:",omitempty"` + + // GraphQLPort is the TCP port number on which to start the GraphQL server. The + // default zero value is/ valid and will pick a port number randomly (useful + // for ephemeral nodes). + GraphQLPort int `toml:",omitempty"` + + // GraphQLCors is the Cross-Origin Resource Sharing header to send to requesting + // clients. Please be aware that CORS is a browser enforced security, it's fully + // useless for custom HTTP clients. + GraphQLCors []string `toml:",omitempty"` + + // GraphQLVirtualHosts is the list of virtual hostnames which are allowed on incoming requests. + // This is by default {'localhost'}. Using this prevents attacks like + // DNS rebinding, which bypasses SOP by simply masquerading as being within the same + // origin. These attacks do not utilize CORS, since they are not cross-domain. + // By explicitly checking the Host-header, the server will not allow requests + // made against the server with a malicious host domain. + // Requests using ip address directly are not affected + GraphQLVirtualHosts []string `toml:",omitempty"` + // Logger is a custom logger to use with the p2p.Server. Logger log.Logger `toml:",omitempty"` @@ -270,6 +273,12 @@ func DefaultWSEndpoint() string { return config.WSEndpoint() } +// ExtRPCEnabled returns the indicator whether node enables the external +// RPC(http, ws or graphql). +func (c *Config) ExtRPCEnabled() bool { + return c.HTTPHost != "" || c.WSHost != "" || c.GraphQLHost != "" +} + // NodeName returns the devp2p node identifier. func (c *Config) NodeName() string { name := c.name() @@ -497,7 +506,7 @@ func makeAccountManager(conf *Config) (*accounts.Manager, string, error) { } } - return accounts.NewManager(backends...), ephemeral, nil + return accounts.NewManager(&accounts.Config{InsecureUnlockAllowed: conf.InsecureUnlockAllowed}, backends...), ephemeral, nil } var warnLock sync.Mutex diff --git a/node/node.go b/node/node.go index bd031bd0f..f4c7d8c72 100644 --- a/node/node.go +++ b/node/node.go @@ -251,6 +251,11 @@ func (n *Node) Start() error { return nil } +// Config returns the configuration of node. +func (n *Node) Config() *Config { + return n.config +} + func (n *Node) openDataDir() error { if n.config.DataDir == "" { return nil // ephemeral diff --git a/node/service.go b/node/service.go index 4f6cb6676..24f809743 100644 --- a/node/service.go +++ b/node/service.go @@ -68,6 +68,12 @@ func (ctx *ServiceContext) Service(service interface{}) error { return ErrServiceUnknown } +// ExtRPCEnabled returns the indicator whether node enables the external +// RPC(http, ws or graphql). +func (ctx *ServiceContext) ExtRPCEnabled() bool { + return ctx.config.ExtRPCEnabled() +} + // ServiceConstructor is the function signature of the constructors needed to be // registered for service instantiation. type ServiceConstructor func(ctx *ServiceContext) (Service, error) |