node: allow JWT pass by file only #24579 (#1035)

This commit is contained in:
JukLee0ira 2025-05-16 12:01:36 +08:00 committed by GitHub
parent d81a5b6be1
commit c145287e87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 3 additions and 12 deletions

View file

@ -418,7 +418,7 @@ var (
}
JWTSecretFlag = &cli.StringFlag{
Name: "authrpc-jwtsecret",
Usage: "JWT secret (or path to a jwt secret) to use for authenticated RPC endpoints",
Usage: "Path to a JWT secret to use for authenticated RPC endpoints",
Category: flags.APICategory,
}

View file

@ -354,17 +354,8 @@ func (n *Node) closeDataDir() {
// or from the default location. If neither of those are present, it generates
// a new secret and stores to the default location.
func (n *Node) obtainJWTSecret(cliParam string) ([]byte, error) {
var fileName string
if len(cliParam) > 0 {
// If a plaintext secret was provided via cli flags, use that
jwtSecret := common.FromHex(cliParam)
if len(jwtSecret) == 32 && strings.HasPrefix(cliParam, "0x") {
log.Warn("Plaintext JWT secret provided, please consider passing via file")
return jwtSecret, nil
}
// path provided
fileName = cliParam
} else {
fileName := cliParam
if len(fileName) == 0 {
// no path provided, use default
fileName = n.ResolvePath(datadirJWTKey)
}