Skip to content

Commit

Permalink
node: implement --authrpc.vhosts flag
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Mar 14, 2022
1 parent 6f88cec commit 0449ff5
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions cmd/geth/main.go
Expand Up @@ -167,6 +167,7 @@ var (
utils.HTTPCORSDomainFlag,
utils.AuthHostFlag,
utils.AuthPortFlag,
utils.AuthVirtualHostsFlag,
utils.JWTSecretFlag,
utils.HTTPVirtualHostsFlag,
utils.GraphQLEnabledFlag,
Expand Down
1 change: 1 addition & 0 deletions cmd/geth/usage.go
Expand Up @@ -152,6 +152,7 @@ var AppHelpFlagGroups = []flags.FlagGroup{
utils.JWTSecretFlag,
utils.AuthHostFlag,
utils.AuthPortFlag,
utils.AuthVirtualHostsFlag,
utils.GraphQLEnabledFlag,
utils.GraphQLCORSDomainFlag,
utils.GraphQLVirtualHostsFlag,
Expand Down
10 changes: 10 additions & 0 deletions cmd/utils/flags.go
Expand Up @@ -533,6 +533,11 @@ var (
Usage: "Listening port for authenticated APIs",
Value: node.DefaultConfig.AuthPort,
}
AuthVirtualHostsFlag = cli.StringFlag{
Name: "authrpc.vhosts",
Usage: "Comma separated list of virtual hostnames from which to accept requests (server enforced). Accepts '*' wildcard.",
Value: strings.Join(node.DefaultConfig.AuthVirtualHosts, ","),
}
JWTSecretFlag = cli.StringFlag{
Name: "authrpc.jwtsecret",
Usage: "JWT secret (or path to a jwt secret) to use for authenticated RPC endpoints",
Expand Down Expand Up @@ -973,10 +978,15 @@ func setHTTP(ctx *cli.Context, cfg *node.Config) {
if ctx.GlobalIsSet(AuthHostFlag.Name) {
cfg.AuthHost = ctx.GlobalString(AuthHostFlag.Name)
}

if ctx.GlobalIsSet(AuthPortFlag.Name) {
cfg.AuthPort = ctx.GlobalInt(AuthPortFlag.Name)
}

if ctx.GlobalIsSet(AuthVirtualHostsFlag.Name) {
cfg.AuthVirtualHosts = SplitAndTrim(ctx.GlobalString(AuthVirtualHostsFlag.Name))
}

if ctx.GlobalIsSet(HTTPCORSDomainFlag.Name) {
cfg.HTTPCors = SplitAndTrim(ctx.GlobalString(HTTPCORSDomainFlag.Name))
}
Expand Down
4 changes: 4 additions & 0 deletions node/config.go
Expand Up @@ -145,6 +145,10 @@ type Config struct {
// AuthPort is the port number on which authenticated APIs are provided.
AuthPort int `toml:",omitempty"`

// AuthVirtualHosts is the list of virtual hostnames which are allowed on incoming requests
// for the authenticated api. This is by default {'localhost'}.
AuthVirtualHosts []string `toml:",omitempty"`

// WSHost is the host interface on which to start the websocket RPC server. If
// this field is empty, no websocket API endpoint will be started.
WSHost string
Expand Down
1 change: 1 addition & 0 deletions node/defaults.go
Expand Up @@ -52,6 +52,7 @@ var DefaultConfig = Config{
HTTPPort: DefaultHTTPPort,
AuthHost: DefaultAuthHost,
AuthPort: DefaultAuthPort,
AuthVirtualHosts: DefaultAuthVhosts,
HTTPModules: []string{"net", "web3"},
HTTPVirtualHosts: []string{"localhost"},
HTTPTimeouts: rpc.DefaultHTTPTimeouts,
Expand Down
2 changes: 1 addition & 1 deletion node/node.go
Expand Up @@ -444,7 +444,7 @@ func (n *Node) startRPC() error {
}
if err := server.enableRPC(apis, httpConfig{
CorsAllowedOrigins: DefaultAuthCors,
Vhosts: DefaultAuthVhosts,
Vhosts: n.config.AuthVirtualHosts,
Modules: DefaultAuthModules,
prefix: DefaultAuthPrefix,
jwtSecret: secret,
Expand Down

0 comments on commit 0449ff5

Please sign in to comment.