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.2) #1723

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
15 changes: 14 additions & 1 deletion src/Framework/Framework/Hosting/StaticCommandExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,26 @@ IDotvvmRequestContext context
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, this.jsonDeserializer);
}
var methodArgs = new List<object?>();
var methodArgsPaths = argumentValidationPaths is null ? null : new List<string?>();
foreach (var a in plan.Arguments)
{
var index = methodArgs.Count;
var (value, path) = a.Type switch {
StaticCommandParameterType.Argument =>
((object?)arguments.Dequeue().ToObject((Type)a.Arg!, this.jsonDeserializer), argumentValidationPaths?.Dequeue()),
(DeserializeArgument((Type)a.Arg!, index), argumentValidationPaths?.Dequeue()),
StaticCommandParameterType.Constant or StaticCommandParameterType.DefaultValue =>
(a.Arg, null),
StaticCommandParameterType.Inject =>
Expand Down
Loading