Skip to content

Commit

Permalink
fix: Accidental cache read via key construction (casbin#330)
Browse files Browse the repository at this point in the history
* fix: Accidental cache read via key construction

Signed-off-by: Tan <2912363476@qq.com>

* fix: separator changed from $ to $$

Signed-off-by: Tan <2912363476@qq.com>

---------

Signed-off-by: Tan <2912363476@qq.com>
  • Loading branch information
Tanyuu authored and sagilio committed Aug 19, 2023
1 parent 0eb65c6 commit e36209e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions Casbin.UnitTests/ModelTests/ModelTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -719,6 +719,16 @@ public void TestBackslashLineFeed()
TestEnforce(e, "bob", "data2", "write", true);
}

[Fact]
public void TestAccidentalCacheRead()
{
Enforcer e = new(_testModelFixture.GetBasicTestModel());

TestEnforce(e, "alice", "data1", "read", true);
TestEnforce(e, "aliced", "ata1", "read", false);
TestEnforce(e, "alice", "data", "1read", false);
}

public class TestResource
{
public TestResource(string name, string owner)
Expand Down
6 changes: 3 additions & 3 deletions Casbin/Model/Request.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public static bool TryGetStringKey<TRequest>(TRequest requestValues, out string
return false;
}

key = string.Concat(values2.Value1, values2.Value2);
key = string.Concat(values2.Value1, "$$", values2.Value2);
return true;
case 3:
if (requestValues is not RequestValues<string, string, string> values3)
Expand All @@ -138,7 +138,7 @@ public static bool TryGetStringKey<TRequest>(TRequest requestValues, out string
return false;
}

key = string.Concat(values3.Value1, values3.Value2, values3.Value3);
key = string.Concat(values3.Value1, "$$", values3.Value2, "$$", values3.Value3);
return true;
case 4:
if (requestValues is not RequestValues<string, string, string, string> values4)
Expand All @@ -147,7 +147,7 @@ public static bool TryGetStringKey<TRequest>(TRequest requestValues, out string
return false;
}

key = string.Concat(values4.Value1, values4.Value2, values4.Value3, values4.Value4);
key = string.Concat(values4.Value1, "$$", values4.Value2, "$$", values4.Value3, "$$", values4.Value4);
return true;
}

Expand Down

0 comments on commit e36209e

Please sign in to comment.