Skip to content
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

Validate static command argument type before deserialization (4.1) #1722

Merged
merged 1 commit into from
Oct 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/Framework/Framework/Hosting/DotvvmPresenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,8 +333,20 @@ public async Task ProcessRequestCore(IDotvvmRequestContext context)

private object? ExecuteStaticCommandPlan(StaticCommandInvocationPlan plan, Queue<JToken> arguments, IDotvvmRequestContext context)
{
var parameters = plan.Method.GetParameters();
object? DeserializeArgument(Type type, int index)
{
var parameterType =
plan.Method.IsStatic ? parameters[index].ParameterType :
index == 0 ? plan.Method.DeclaringType :
parameters[index - 1].ParameterType;
if (!parameterType!.IsAssignableFrom(type))
throw new Exception($"Argument {index} has an invalid type");
var arg = arguments.Dequeue();
return arg.ToObject(type);
}
var methodArgs = plan.Arguments.Select((a, index) =>
a.Type == StaticCommandParameterType.Argument ? arguments.Dequeue().ToObject((Type)a.Arg!) :
a.Type == StaticCommandParameterType.Argument ? DeserializeArgument((Type)a.Arg!, index) :
a.Type == StaticCommandParameterType.Constant || a.Type == StaticCommandParameterType.DefaultValue ? a.Arg :
a.Type == StaticCommandParameterType.Inject ?
#pragma warning disable CS0618
Expand Down
Loading