Skip to content
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

The hydra can't handle the DB username with "@" character #1460

Closed
yxzhm opened this issue Jun 5, 2019 · 9 comments · Fixed by #1466
Closed

The hydra can't handle the DB username with "@" character #1460

yxzhm opened this issue Jun 5, 2019 · 9 comments · Fixed by #1466

Comments

@yxzhm
Copy link

yxzhm commented Jun 5, 2019

Describe the bug
If I set the user name of DB with "@" char, the hydra can't connect to the DB.
When we create the mysql db in Azure, the user name always contains "@" character.
The DSN example is as following:
DSN=mysql://sa@test.mysql.database.azure.com:MyPassword@(127.0.0.1:3306)/hydra

According to my investigation, the issue caused by below function in sqlcon lib.
This QueryEscape will replace "@" to "%40".

func connectionString(clean *url.URL) string {
	if clean.Scheme == "mysql" {
		q := clean.Query()
		q.Set("parseTime", "true")
		clean.RawQuery = q.Encode()
	}

	username := clean.User.Username()
	userinfo := username
	password, hasPassword := clean.User.Password()
	if hasPassword {
		userinfo = url.QueryEscape(userinfo) + ":" + url.QueryEscape(password)
	}
	clean.User = nil
	u := clean.String()
	clean.User = url.UserPassword(username, password)

	if strings.HasPrefix(u, clean.Scheme+"://") {
		u = strings.Replace(u, clean.Scheme+"://", clean.Scheme+"://"+userinfo+"@", 1)
	}
	if clean.Scheme == "mysql" {
		u = strings.Replace(u, "mysql://", "", -1)
	}
	return u
}
@aeneasr
Copy link
Member

aeneasr commented Jun 5, 2019

Does mysql://sa%40test.mysql.database.azure.com:MyPassword@(127.0.0.1:3306)/hydra work?

@yxzhm
Copy link
Author

yxzhm commented Jun 5, 2019

Does mysql://sa%40test.mysql.database.azure.com:MyPassword@(127.0.0.1:3306)/hydra work?

Nope

@aeneasr
Copy link
Member

aeneasr commented Jun 5, 2019

Can you confirm that connecting to mysql://sa@test.mysql.database.azure.com:MyPassword@(127.0.0.1:3306)/hydra works when:

- userinfo = url.QueryEscape(userinfo) + ":" + url.QueryEscape(password)
+ userinfo = userinfo + ":" + password

?

@aeneasr
Copy link
Member

aeneasr commented Jun 5, 2019

It seems like ParseDSN doesn't care about URL formatting (username and info should be url encoded...) but simply uses the "last" @ or the last /. I have to check if that's the case for the postgres driver too (I think they actually care about proper URL formatting).

@yxzhm
Copy link
Author

yxzhm commented Jun 5, 2019

The below update works fine.
Do you have a plan to fix this issue recently? This issue blocks the deployment in Azure cloud.

BTW: The https://github.com/ory/sqlcon is archived.

`- userinfo = url.QueryEscape(userinfo) + ":" + url.QueryEscape(password)

  • userinfo = userinfo + ":" + password`

@aeneasr
Copy link
Member

aeneasr commented Jun 5, 2019

BTW: The https://github.com/ory/sqlcon is archived.

It moved to: https://github.com/ory/x/tree/master/sqlcon

Do you have a plan to fix this issue recently? This issue blocks the deployment in Azure cloud.

Next couple of days are busy but I have time to review and merge PRs if you create one!

@yxzhm
Copy link
Author

yxzhm commented Jun 5, 2019

Sure, I will try to create a PR ASAP. Thank you in advance.

@yxzhm
Copy link
Author

yxzhm commented Jun 6, 2019

I have created the PR. Could you please help to review it?
Thank you

ory/x#57

@leonfancy
Copy link

When will this feature be released? We are going to use it in our product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants