From 5bfe84a4c757ec452e0efa5c43d6fedca35604fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=B6nke=20Ludwig?= Date: Mon, 15 Apr 2024 22:03:17 +0200 Subject: [PATCH] Avoid serializing AuthInfo and input streams in RPC interfaces. When an input stream return type is used, this now produces a runtime error instead, until this is actually supported. AuthInfo arguments are never serialized and sent over the wire, as the code already intended. --- web/vibe/web/rpc.d | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/web/vibe/web/rpc.d b/web/vibe/web/rpc.d index 3bd675413..9a7028c60 100644 --- a/web/vibe/web/rpc.d +++ b/web/vibe/web/rpc.d @@ -88,6 +88,7 @@ module vibe.web.rpc; import vibe.core.log; import vibe.core.core : Task, runTask, yield; import vibe.core.path : InetPath; +import vibe.core.stream : isInputStream; import vibe.data.bson; import vibe.inet.url : URL; import vibe.http.router; @@ -243,14 +244,14 @@ final class WebRPCPeerImpl(I, RootI, string method_prefix) : I mixin(generateWebRPCPeerMethods!I()); - private auto performCall(alias method, PARAMS...)(auto ref PARAMS params) + private ReturnType!method performCall(alias method, PARAMS...)(auto ref PARAMS params) { alias outparams = refOutParameterIndices!method; alias paramnames = ParameterIdentifierTuple!method; Bson args = Bson.emptyObject; foreach (i, pname; ParameterIdentifierTuple!method) - static if (!is(typeof(args[i]) == AuthInfo!I) && !(ParameterStorageClassTuple!method[i] & ParameterStorageClass.out_)) + static if (!is(ParameterTypeTuple!method[i] == AuthInfo!I) && !(ParameterStorageClassTuple!method[i] & ParameterStorageClass.out_)) args[pname] = serializeToBson(params[i]); auto seq = m_handler.sendCall(method_prefix ~ __traits(identifier, method), args); auto ret = m_handler.waitForResponse(seq); @@ -259,8 +260,11 @@ final class WebRPCPeerImpl(I, RootI, string method_prefix) : I params[pi] = ret[paramnames[pi]].deserializeBson!(PARAMS[pi]); static if (!is(ReturnType!method == void)) return ret["return"].deserializeBson!(ReturnType!method); - } else static if (!is(ReturnType!method == void)) + } else static if (isInputStream!(ReturnType!method)) { + throw new Exception("Stream type results are not yet supported"); + } else static if (!is(ReturnType!method == void)) { return ret.deserializeBson!(ReturnType!method); + } } } @@ -736,9 +740,9 @@ private final class WebSocketHandler(I) { bret = Bson.emptyObject; foreach (pi; outparams) bret[paramnames[pi]] = serializeToBson(args[pi]); - static if (is(typeof(ret))) + static if (is(typeof(ret)) && !isInputStream!(typeof(ret))) bret["return"] = serializeToBson(ret); - } else static if (is(typeof(ret))) { + } else static if (is(typeof(ret)) && !isInputStream!(typeof(ret))) { bret = serializeToBson(ret); } return bret;