Skip to content

Commit

Permalink
Fixes a mojibake bug in web authenticators in some multibyte locales
Browse files Browse the repository at this point in the history
Fixes bitwarden#3345

Make the implementation of the character convertion consistent with
their consumers in the web app.
  • Loading branch information
yugui committed Jul 7, 2024
1 parent 8a43bb4 commit 4e2cec8
Showing 1 changed file with 2 additions and 8 deletions.
10 changes: 2 additions & 8 deletions src/Core/Utilities/AppHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -515,14 +515,8 @@ public static async Task<bool> IsVaultTimeoutImmediateAsync()

public static string EncodeDataParameter(object obj)
{
string EncodeMultibyte(Match match)
{
return Convert.ToChar(Convert.ToUInt32($"0x{match.Groups[1].Value}", 16)).ToString();
}

var escaped = Uri.EscapeDataString(JsonConvert.SerializeObject(obj));
var multiByteEscaped = Regex.Replace(escaped, "%([0-9A-F]{2})", EncodeMultibyte);
return WebUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(multiByteEscaped)));
var json = JsonConvert.SerializeObject(obj);
return WebUtility.UrlEncode(Convert.ToBase64String(Encoding.UTF8.GetBytes(json)));
}

public static async Task LogOutAsync(string userId, bool userInitiated = false)
Expand Down

0 comments on commit 4e2cec8

Please sign in to comment.