1
0
mirror of https://github.com/redis/go-redis.git synced 2026-10-22 19:49:00 +03:00

fix(options): reject invalid skip_verify values in ParseURL (#4064)

skip_verify was parsed after the query error check, so an invalid
value such as skip_verify=yes was silently treated as false instead of
returning an error like every other boolean option. Move the check so
the error is reported, in both ParseURL and ParseFailoverURL.
This commit is contained in:
phuoc14.dev
2026-10-05 18:01:29 +07:00
committed by GitHub
parent f813adcb85
commit 89ecbc5a8e
4 changed files with 14 additions and 3 deletions

View File

@@ -1119,12 +1119,12 @@ func setupConnParams(u *url.URL, o *Options) (*Options, error) {
if q.has("conn_max_lifetime_jitter") {
o.ConnMaxLifetimeJitter = min(q.duration("conn_max_lifetime_jitter"), o.ConnMaxLifetime)
}
if q.err != nil {
return nil, q.err
}
if o.TLSConfig != nil && q.has("skip_verify") {
o.TLSConfig.InsecureSkipVerify = q.bool("skip_verify")
}
if q.err != nil {
return nil, q.err
}
// any parameters left?
if r := q.remaining(); len(r) > 0 {

View File

@@ -128,6 +128,10 @@ func TestParseURL(t *testing.T) {
// invalid bool value
url: "redis://localhost/?pool_fifo=yes",
err: errors.New(`redis: invalid pool_fifo boolean: expected true/false/1/0 or an empty string, got "yes"`),
}, {
// invalid skip_verify value
url: "rediss://localhost/?skip_verify=yes",
err: errors.New(`redis: invalid skip_verify boolean: expected true/false/1/0 or an empty string, got "yes"`),
}, {
// it returns first error
url: "redis://localhost/?db=foo&pool_size=five",

View File

@@ -527,6 +527,9 @@ func setupFailoverConnParams(u *url.URL, o *FailoverOptions) (*FailoverOptions,
if o.TLSConfig != nil && q.has("skip_verify") {
o.TLSConfig.InsecureSkipVerify = q.bool("skip_verify")
}
if q.err != nil {
return nil, q.err
}
// any parameters left?
if r := q.remaining(); len(r) > 0 {

View File

@@ -571,6 +571,10 @@ func TestParseSentinelURL(t *testing.T) {
},
err: errors.New("redis: unexpected option: abc"),
},
{
url: "rediss://localhost:6379/5?master_name=test&skip_verify=yes",
err: errors.New(`redis: invalid skip_verify boolean: expected true/false/1/0 or an empty string, got "yes"`),
},
{
url: "http://google.com",
err: errors.New("redis: invalid URL scheme: http"),