Skip to content

Commit

Permalink
decode from safe zipped url
Browse files Browse the repository at this point in the history
  • Loading branch information
hoseinzadehashraf committed May 9, 2024
1 parent 2dd3373 commit 5fc142d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion Olive.Mvc/Extentions/Extensions.UrlHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ public static string AsSafeZippedUrl(this string url) => "..." + url.OrEmpty().T
.Replace("/", "_")
.Replace("=", "-");

/// <summary>
/// Gets the url decrypted from gzipped and safe base64.
/// </summary>
public static string FromSafeZippedUrl(this string url) => url.StartsWith("...")
? url.Substring(3).Replace("~", "+").Replace("_", "/").Replace("-", "=").FromGZippedBase64()
: url;

public static string Current(this IUrlHelper @this, object queryParameters)
{
if (queryParameters == null) return Current(@this);
Expand Down Expand Up @@ -87,7 +94,7 @@ public static string ReturnUrl(this IUrlHelper @this)

// Using Safe Encode?
if (url.StartsWith("..."))
url = url.Substring(3).Replace("~", "+").Replace("_", "/").Replace("-", "=").FromGZippedBase64();
url = url.FromSafeZippedUrl();

if (!@this.IsLocalUrl(url))
throw new Exception(url + " is not a valid ReturnUrl as it's external and so unsafe.");
Expand Down
2 changes: 1 addition & 1 deletion Olive.Mvc/Olive.Mvc.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp3.1</TargetFramework>
<Version>3.1.152</Version>
<Version>3.1.153</Version>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 5fc142d

Please sign in to comment.