Skip to content

QueryUnescape the tlsConfig name during DSN parsing. #397

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 6, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ Jian Zhen <zhenjl at gmail.com>
Joshua Prunier <joshua.prunier at gmail.com>
Julien Schmidt <go-sql-driver at julienschmidt.com>
Kamil Dziedzic <kamil at klecza.pl>
Kevin Malachowski <kevin at chowski.com>
Leonardo YongUk Kim <dalinaum at gmail.com>
Lucas Liu <extrafliu at gmail.com>
Luke Scott <luke at webconnex.com>
Expand Down
2 changes: 2 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ func parseDSNParams(cfg *config, params string) (err error) {
if boolValue {
cfg.tls = &tls.Config{}
}
} else if value, err := url.QueryUnescape(value); err != nil {
return fmt.Errorf("Invalid value for tls config name: %v", err)
} else {
if strings.ToLower(value) == "skip-verify" {
cfg.tls = &tls.Config{InsecureSkipVerify: true}
Expand Down
18 changes: 18 additions & 0 deletions utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"crypto/tls"
"encoding/binary"
"fmt"
"net/url"
"testing"
"time"
)
Expand Down Expand Up @@ -116,6 +117,23 @@ func TestDSNWithCustomTLS(t *testing.T) {
DeregisterTLSConfig("utils_test")
}

func TestDSNWithCustomTLS_queryEscape(t *testing.T) {
const configKey = "&%!:"
dsn := "user:password@tcp(localhost:5555)/dbname?tls=" + url.QueryEscape(configKey)
name := "foohost"
tlsCfg := tls.Config{ServerName: name}

RegisterTLSConfig(configKey, &tlsCfg)

cfg, err := parseDSN(dsn)

if err != nil {
t.Error(err.Error())
} else if cfg.tls.ServerName != name {
t.Errorf("Did not get the correct TLS ServerName (%s) parsing DSN (%s).", name, dsn)
}
}

func TestDSNUnsafeCollation(t *testing.T) {
_, err := parseDSN("/dbname?collation=gbk_chinese_ci&interpolateParams=true")
if err != errInvalidDSNUnsafeCollation {
Expand Down