ईवेंट्स
17 मार्च, 9 pm - 21 मार्च, 10 am
साथी डेवलपर्स और विशेषज्ञों के साथ वास्तविक दुनिया के उपयोग के मामलों के आधार पर स्केलेबल एआई समाधान बनाने के लिए मीटअप श्रृंखला में शामिल हों।
अभी पंजीकरण करेंयह ब्राउज़र अब समर्थित नहीं है.
नवीनतम सुविधाओं, सुरक्षा अपडेट और तकनीकी सहायता का लाभ लेने के लिए Microsoft Edge में अपग्रेड करें.
Property | Value |
---|---|
Rule ID | CA5362 |
Title | Potential reference cycle in deserialized object graph |
Category | Security |
Fix is breaking or non-breaking | Non-breaking |
Enabled by default in .NET 9 | No |
A class marked with the System.SerializableAttribute has a field or property may refer to the containing object directly or indirectly, allowing for a potential reference cycle.
If deserializing untrusted data, then any code processing the deserialized object graph needs to handle reference cycles without going into infinite loops. This includes both code that's part of a deserialization callback and code that processes the object graph after deserialization completed. Otherwise, an attacker could perform a Denial-of-Service attack with malicious data containing a reference cycle.
This rule doesn't necessarily mean there's a vulnerability, but just flags potential reference cycles in deserialized object graphs.
Don't serialize the class and remove the SerializableAttribute. Or, redesign your application so that the self-referred members can be removed out of the serializable class.
It's safe to suppress a warning from this rule if:
If you just want to suppress a single violation, add preprocessor directives to your source file to disable and then re-enable the rule.
#pragma warning disable CA5362
// The code that's violating the rule is on this line.
#pragma warning restore CA5362
To disable the rule for a file, folder, or project, set its severity to none
in the configuration file.
[*.{cs,vb}]
dotnet_diagnostic.CA5362.severity = none
For more information, see How to suppress code analysis warnings.
using System;
[Serializable()]
class ExampleClass
{
public ExampleClass ExampleProperty {get; set;}
public int NormalProperty {get; set;}
}
class AnotherClass
{
// The argument passed by could be `JsonConvert.DeserializeObject<ExampleClass>(untrustedData)`.
public void AnotherMethod(ExampleClass ec)
{
while(ec != null)
{
Console.WriteLine(ec.ToString());
ec = ec.ExampleProperty;
}
}
}
using System;
[Serializable()]
class ExampleClass
{
[NonSerialized]
public ExampleClass ExampleProperty {get; set;}
public int NormalProperty {get; set;}
}
class AnotherClass
{
// The argument passed by could be `JsonConvert.DeserializeObject<ExampleClass>(untrustedData)`.
public void AnotherMethod(ExampleClass ec)
{
while(ec != null)
{
Console.WriteLine(ec.ToString());
ec = ec.ExampleProperty;
}
}
}
.NET प्रतिक्रिया
.NET एक ओपन सोर्स प्रोजेक्ट है. प्रतिक्रिया प्रदान करने के लिए लिंक का चयन करें:
ईवेंट्स
17 मार्च, 9 pm - 21 मार्च, 10 am
साथी डेवलपर्स और विशेषज्ञों के साथ वास्तविक दुनिया के उपयोग के मामलों के आधार पर स्केलेबल एआई समाधान बनाने के लिए मीटअप श्रृंखला में शामिल हों।
अभी पंजीकरण करें