Skip to content

Commit

Permalink
Use specific purpose when using machine key to avoid derived key cach…
Browse files Browse the repository at this point in the history
…ing on FE
  • Loading branch information
suwatch committed Jun 21, 2017
1 parent efb55da commit 97073f4
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/WebJobs.Script.Scaling/ScaleUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ namespace Microsoft.Azure.WebJobs.Script.Scaling
[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Justification = "By design")]
public static class ScaleUtils
{
public const string Purpose = "ScaleManager";

[SuppressMessage("Microsoft.Naming", "CA1704:IdentifiersShouldBeSpelledCorrectly", Justification = "By design")]
public static bool WorkerEquals(IWorkerInfo src, IWorkerInfo dst)
{
Expand Down Expand Up @@ -87,14 +89,14 @@ public static string ToDisplayString(this IEnumerable<string> values)
public static string GetToken(DateTime expiredUtc)
{
var bytes = BitConverter.GetBytes(expiredUtc.Ticks);
var encrypted = MachineKey.Protect(bytes);
var encrypted = MachineKey.Protect(bytes, Purpose);
return Convert.ToBase64String(encrypted);
}

public static void ValidateToken(string token)
{
var encrypted = Convert.FromBase64String(token);
var bytes = MachineKey.Unprotect(encrypted);
var bytes = MachineKey.Unprotect(encrypted, Purpose);
var ticks = BitConverter.ToInt64(bytes, 0);
var expiredUtc = new DateTime(ticks, DateTimeKind.Utc);

Expand Down

0 comments on commit 97073f4

Please sign in to comment.