J
Jesper
Is it possible to secure a reference parameter from modification using c#?
E.I. something like const would do in c++.
I've tried to do it by limiting the object to an interface with only get
functions, but that doesnt stop a malicious user from using reflection to
set it...Like:
---Example--------
public interface IFoo
{
int Param {get; }
}
public class Foo : IFoo
{
private int param;
public int Param
{
get { return param; }
set { param = value; }
}
}
public class UntrustedClass
{
public static void Bar(IFoo foo)
{
// Following line will generate a compile error. (Good)
// foo.Param = 15;
// However, this wont. (Bad). And it will execute correctly. (Really bad).
PropertyInfo[] ps = foo.GetType().GetProperties();
ps[0].SetValue(foo, 15, null);
}
}
---Example End--------
So..What are my options? Can I use attributes to stop reflection? Can I use
other security options? I plan on giving the untrusted code its own
AppDomain anyway, but can it stop reflection?
E.I. something like const would do in c++.
I've tried to do it by limiting the object to an interface with only get
functions, but that doesnt stop a malicious user from using reflection to
set it...Like:
---Example--------
public interface IFoo
{
int Param {get; }
}
public class Foo : IFoo
{
private int param;
public int Param
{
get { return param; }
set { param = value; }
}
}
public class UntrustedClass
{
public static void Bar(IFoo foo)
{
// Following line will generate a compile error. (Good)
// foo.Param = 15;
// However, this wont. (Bad). And it will execute correctly. (Really bad).
PropertyInfo[] ps = foo.GetType().GetProperties();
ps[0].SetValue(foo, 15, null);
}
}
---Example End--------
So..What are my options? Can I use attributes to stop reflection? Can I use
other security options? I plan on giving the untrusted code its own
AppDomain anyway, but can it stop reflection?