Skip to content

Commit

Permalink
Fixed Azure table property being not sanitized.
Browse files Browse the repository at this point in the history
  • Loading branch information
dVakulen committed Feb 5, 2016
1 parent 5d63928 commit 2e2b5ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/OrleansAzureUtils/Storage/AzureStorageUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -275,10 +275,11 @@ public static string SanitizeTableProperty(string key)
{
// Remove any characters that can't be used in Azure PartitionKey or RowKey values
// http://www.jamestharpe.com/web-development/azure-table-service-character-combinations-disallowed-in-partitionkey-rowkey/
key.Replace('/', '_'); // Forward slash
key.Replace('\\', '_'); // Backslash
key.Replace('#', '_'); // Pound sign
key.Replace('?', '_'); // Question mark
key = key
.Replace('/', '_') // Forward slash
.Replace('\\', '_') // Backslash
.Replace('#', '_') // Pound sign
.Replace('?', '_'); // Question mark

This comment has been minimized.

Copy link
@ponsakthi

ponsakthi Feb 19, 2016

This code means that the following keys look the same
http:/hello , http#hello
which is a risk. Why not just Hexencode the keys? http://blogs.msdn.com/b/blambert/archive/2009/02/27/blambert-learnings-don-t-base64-encode-partitionkey-and-rowkey-values-in-azure-table-storage.aspx


if (key.Length >= 1024)
throw new ArgumentException(string.Format("Key length {0} is too long to be an Azure table key. Key={1}", key.Length, key));
Expand Down
7 changes: 7 additions & 0 deletions src/TesterInternal/StorageTests/AzureTableErrorCodeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,12 @@ public void AzureTableErrorCode_BadTableName()
string tableName = "abc-123";
AzureStorageUtils.ValidateTableName(tableName);
}

[TestMethod, TestCategory("Functional"), TestCategory("Azure"), TestCategory("Storage")]
public void AzureStorageUtils_TablePropertyShouldBeSanitized()
{
var tableProperty = "/A\\C#?";
Assert.AreEqual("_A_C__", AzureStorageUtils.SanitizeTableProperty(tableProperty));
}
}
}

0 comments on commit 2e2b5ca

Please sign in to comment.