-
-
Notifications
You must be signed in to change notification settings - Fork 231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CVE-2024-51417: System.Linq.Dynamic.Core allows remote access to properties on reflection types and static properties/fields #867
Comments
Reported by nuget |
Hi, @StefH anyone working on this? Any timeline. |
We are investigating the issue. Initial research shows that whitelisting the allowed types would be a solution to fix both issues, however this will impact the usability from this library. No timeline is known yet. |
Just so I'm clear, there is no work around at this time? |
If the code is not building because you treat warnings as errors, you can add |
We've added the following to our impacted project's csproj file:
It also passes trough our devops pipelines this way, so we are not completely blocked at the moment, off course this can't be a permanent solution |
@mariusz96 Issue 1. Properties on reflection typesThe same result can also be achieved by calling normal C# code: var names = typeof(Customer)
.GetType()
.Assembly
.DefinedTypes
.SelectMany(t => t.CustomAttributes)
.Select(a => a.AttributeType)
.Select(t => t.AssemblyQualifiedName);
foreach (var name in names)
{
Console.WriteLine(name);
}
public class Customer
{
public int Id { get; set; }
public string Name { get; set; }
} The only way this will be an issue if you expose the functionality from System.Linq.Dynamic.Core via an unprotected external public API or interface. Issue 2. Static properties/fieldsAlso in this case, accessing a static class (normal or via reflection) is also possible in normal C#. Possible solutionA possible way of solving this issue is that the user needs to whitelist all types which are allowed to use by System.Linq.Dynamic.Core. |
Issue 1 I think only is possible because the |
@StefH
I do believe that exposing dynamic filters/queries to the client is very much the intended use case of the library. However, using
If you mean to extend the existing mechanism of white-listing methods to additionally white-list all properties and fields then it makes sense and should fix the vulnerability. Also, when IQueryable works with database it does not seem too much work for the end user to add some attributes/configuration on their table types so they can use them with the library. Might be harder for dependent nuget packages or end users with different use cases though. |
@Tasteful Issue 1. Properties on reflection typesWhen removing the object type from PredefinedTypes, this issue seems to be solved. So the provided POC code will now throw an exception when this change in PredefinedTypesHelper is applied. Related unit-test code: [Theory]
[InlineData("c => string.Join(\"_\", c.GetType().Assembly.DefinedTypes.SelectMany(t => t.CustomAttributes).Select(a => a.AttributeType).Select(t => t.AssemblyQualifiedName))")]
[InlineData("c => string.Join(\"_\", c.GetType().Assembly.DefinedTypes.Select(t => t.BaseType).Select(t => t.AssemblyQualifiedName))")]
[InlineData("c => string.Join(\"_\", c.GetType().Assembly.FullName))")]
public void UsingSystemReflectionAssembly_ThrowsException(string selector)
{
// Arrange
var queryable = new[]
{
new Message("Alice", "Bob")
}.AsQueryable();
// Act
Action action = () => queryable.Select(selector);
// Assert
action.Should().Throw<ParseException>().WithMessage("Methods on type 'Object' are not accessible");
} Issue 2: Static properties/fieldsThis can be solved by only allowing classes which are annotated with Related unit-test code: [Theory]
[InlineData("System.Linq.Dynamic.Core.Tests.Helpers.Models.AppSettings.SettingsProp[\"jwt\"]")]
[InlineData("System.Linq.Dynamic.Core.Tests.Helpers.Models.AppSettings.SettingsField[\"jwt\"]")]
[InlineData("c => System.Linq.Dynamic.Core.Tests.Helpers.Models.AppSettings.SettingsProp[\"jwt\"]")]
[InlineData("c => System.Linq.Dynamic.Core.Tests.Helpers.Models.AppSettings.SettingsField[\"jwt\"]")]
public void UsingStaticClass_ThrowsException(string selector)
{
// Arrange
var queryable = new[]
{
new Message("Alice", "Bob")
}.AsQueryable();
// Act
Action action = () => queryable.Select(selector);
// Assert
action.Should().Throw<ParseException>().WithMessage("Type 'System.Linq.Dynamic.Core.Tests.Helpers.Models.AppSettings' not found");
} @mariusz96 |
With the removal of |
@StefH Yes, it appears so. This should solve it.
Note that static properties/fields can also exists on non-static classes so there are actually four cases:
|
For issue 2, I guess it will be the same for static methods that they can exists on the static or instance classes. @StefH can you add test cases for them as well? |
@mariusz96 @Tasteful
|
Ouch! |
This code helped me get my pipeline builds through. (In pipeline warnings was treated as errors, so all builds was failing after this issue)
|
For those using Rider - take into account that
|
@mariusz96 |
@aarondglover |
@mariusz96 1.6.0-preview-02 To enable this functionality, set |
v1.6.0-preview-03 (25 January 2025)
|
Thank you for the great work and prompt response. |
Version 1.6.0 is released. |
Thanks for the quick reaction on this vulnerability!
Am I getting this right: Enabling the functionality would make an application vulnerable again? We are using this library to pass dynamic predicates into a |
The main part of the vulnerability was the fact that you could call |
Adjust PassNullParameter test, add new case, comment out failing case. See also CVE-2024-51417 zzzprojects/System.Linq.Dynamic.Core#867
Adjust PassNullParameter test, add new case, comment out failing case. See also CVE-2024-51417 zzzprojects/System.Linq.Dynamic.Core#867
Summary
System.Linq.Dynamic.Core allows remote access to properties on reflection types and static properties/fields.
Details
Access to properties on reflection types allows listing installed nuget packages' names and versions through attributes and base types they require. Then it is possible to google and exploit their vulnerabilities.
Access to static properties/fields allows just as implied.
PoC
Impact
Properties on reflection types PoC executes successfully in System.Linq.Dynamic.Core.1.0.0 and up (patched in System.Linq.Dynamic.Core.1.6.0).
Static properties/fields PoC executes successfully in System.Linq.Dynamic.Core.1.3.10 and up (patched in System.Linq.Dynamic.Core.1.6.0).
The text was updated successfully, but these errors were encountered: