aboutsummaryrefslogtreecommitdiff
path: root/jsonrpc
diff options
context:
space:
mode:
authorhozan23 <hozan23@karyontech.net>2024-06-15 00:42:15 +0200
committerhozan23 <hozan23@karyontech.net>2024-06-15 00:42:15 +0200
commit5bad1b8c6470f504339a742cfa8d213428a5c7f0 (patch)
tree6dcbd9691e502a278ae3f9220289c0e2296f6fe4 /jsonrpc
parent5064133f1f59be9539ff6a2ebd830132b2379564 (diff)
jsonrpc/server: check for the jsonrpc version in the request
Diffstat (limited to 'jsonrpc')
-rw-r--r--jsonrpc/src/server/mod.rs15
1 files changed, 15 insertions, 0 deletions
diff --git a/jsonrpc/src/server/mod.rs b/jsonrpc/src/server/mod.rs
index dd176d0..7ff1a8c 100644
--- a/jsonrpc/src/server/mod.rs
+++ b/jsonrpc/src/server/mod.rs
@@ -19,6 +19,7 @@ use response_queue::ResponseQueue;
pub const INVALID_REQUEST_ERROR_MSG: &str = "Invalid request";
pub const FAILED_TO_PARSE_ERROR_MSG: &str = "Failed to parse";
pub const METHOD_NOT_FOUND_ERROR_MSG: &str = "Method not found";
+pub const UNSUPPORTED_JSONRPC_VERSION: &str = "Unsupported jsonrpc version";
struct NewRequest {
srvc_name: String,
@@ -175,6 +176,20 @@ impl Server {
return SanityCheckResult::ErrRes(response);
}
};
+
+ if rpc_msg.jsonrpc != message::JSONRPC_VERSION {
+ let response = message::Response {
+ error: Some(message::Error {
+ code: message::INVALID_REQUEST_ERROR_CODE,
+ message: UNSUPPORTED_JSONRPC_VERSION.to_string(),
+ data: None,
+ }),
+ id: Some(rpc_msg.id),
+ ..Default::default()
+ };
+ return SanityCheckResult::ErrRes(response);
+ }
+
debug!("<-- {rpc_msg}");
// Parse the service name and its method