Advertisement
Guest User

Broken Encoding Example

a guest
Apr 6th, 2020
882
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.37 KB | None | 0 0
  1. //UNITY SIDE
  2. IEnumerator Foo()
  3.     {
  4.         var N = JSON.Parse("{}");
  5.         N["input1"] = input1.text;
  6.         N["input2"] = input2.text;
  7.         string encrypted = Encrypt(N.ToString(), GenerateEncryptionKey);
  8.  
  9.         print("ENSEND: \n" + encrypted);
  10.         using (UnityWebRequest www = UnityWebRequest.Post(targetURL, encrypted))
  11.         {
  12.             yield return www.SendWebRequest();
  13.  
  14.             if (www.isHttpError || www.isNetworkError)
  15.             {
  16.                 Debug.LogError(www.error + "\n" + www.downloadHandler.text);
  17.                 onFail?.Invoke();
  18.             }
  19.             else
  20.             {
  21.                 onSuccess?.Invoke();
  22.                 print(www.responseCode + " : " + www.downloadHandler.text);
  23.             }
  24.  
  25.         }
  26.         yield break;
  27.     }
  28.  
  29. //FUNCTION SIDE
  30. [FunctionName("UserAuthentication")]
  31.         public static async Task<IActionResult> Run(
  32.             [HttpTrigger(AuthorizationLevel.Anonymous, "get", "post", Route = null)] HttpRequest req,
  33.             ILogger log)
  34.         {
  35.             log.LogInformation("C# HTTP trigger function processed a request.");
  36.  
  37.             string name = req.Query["name"];
  38.  
  39.             string requestBody = await new StreamReader(req.Body).ReadToEndAsync();
  40.             try
  41.             {
  42.                 requestBody = Decrypt(requestBody, "Dracon");
  43.             } catch (Exception e)
  44.             {
  45. //Throwing exception here due to escaped characters
  46.                 return new BadRequestObjectResult(e.Message + "\n" + requestBody + "\n" + Regex.Unescape(requestBody));
  47.             }
  48.            
  49.             JSONNode N = null;
  50.             try
  51.             {
  52.                 N = JSON.Parse(requestBody);
  53.                 if (N["input1"] != "")
  54.                 {
  55.                     name = N["username"];
  56.                     return (ActionResult)new OkObjectResult($"Hello, {name}");
  57.                 } else if (name != "")
  58.                 {
  59.                     return (ActionResult)new OkObjectResult($"Hello, {name}");
  60.                 } else
  61.                 {
  62.                     return new BadRequestObjectResult("Invalid object syntax");
  63.                 }
  64.             } catch (Exception e)
  65.             {
  66.                 return new BadRequestObjectResult("Invalid JSON provided. N = " + (N != null).ToString() + "\n" + requestBody + "\n" + e.Message);
  67.             }
  68.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement