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

keep 'secret' query parameter first to please the Google Authenticator #95

Closed
wants to merge 1 commit into from

Conversation

yogo1212
Copy link

No description provided.

@yogo1212
Copy link
Author

@pquerna could you give this small PR a quick review?
should be an easy merge

@@ -18,7 +18,6 @@ func EncodeQuery(v url.Values) string {
for k := range v {
keys = append(keys, k)
}
sort.Strings(keys)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we use a custom sort here instead of no sorting? i kinda liked it was stable rendering of the input. eg, sort where secret is always first

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

something like this?

	slices.SortFunc(keys, func(a, b string) bool {
		if a == "secret" {
			return true
		}
		if b == "secret" {
			return false
		}
		return a < b
	})

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sure thing - my biggest motivation is to roll out a fix for everyone to enjoy!

i can give you an alternative so you have another option to pick from:

	// Google Authenticator expects the secret to be first, so handle it separately
	keys := make([]string, 0, len(v) - 1)
	for k := range v {
		if k != "secret" {
			keys = append(keys, k)
		}
	}
	sort.Strings(keys)
	for _, k := range append([]string{"secret"}, keys...) {

or maybe a little more optimised:

	// Google Authenticator expects the secret to be first, so handle it separately
	keys := make([]string, 0, len(v))
	keys = append(keys, "secret")
	for k := range v {
		if k != "secret" {
			keys = append(keys, k)
		}
	}
	sort.Strings(keys[1:])
	for _, k := range keys {

these solutions fail, though, if there' no secret at all

@yogo1212
Copy link
Author

@pquerna i've amended the commit to keep the sorting in general, as you requested.
i went with the 'one allocation, one comparison in sort' approach.

@yogo1212
Copy link
Author

yogo1212 commented Dec 4, 2024

closing this as the investigation over on issue #94 revealed that order of the parameters is not the root cause of the problem.

@yogo1212 yogo1212 closed this Dec 4, 2024
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 this pull request may close these issues.

2 participants