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

Fix parsing both tokens with 0x prefix and without it #1869

Merged
merged 1 commit into from
Apr 4, 2024
Merged
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
9 changes: 6 additions & 3 deletions tools/walletextension/httpapi/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@ func getUserID(conn UserConn) ([]byte, error) {
// try getting userID (`token`) from query parameters and return it if successful
userID, err := getQueryParameter(conn.ReadRequestParams(), common.EncryptedTokenQueryParameter)
if err == nil {
if len(userID) != common.MessageUserIDLenWithPrefix {
return nil, fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d", len(userID), common.MessageUserIDLenWithPrefix))
if len(userID) == common.MessageUserIDLenWithPrefix {
return hexutils.HexToBytes(userID[2:]), nil
} else if len(userID) == common.MessageUserIDLen {
return hexutils.HexToBytes(userID), nil
}
return hexutils.HexToBytes(userID[2:]), err

return nil, fmt.Errorf(fmt.Sprintf("wrong length of userID from URL. Got: %d, Expected: %d od %d", len(userID), common.MessageUserIDLenWithPrefix, common.MessageUserIDLen))
}

return nil, fmt.Errorf("missing token field")
Expand Down
Loading