restricted json-rpc error

This commit is contained in:
hinto.janai 2024-12-17 18:39:05 -05:00
parent 3763dc9693
commit ce6838bd6f
No known key found for this signature in database
GPG key ID: D47CE05FA175A499
3 changed files with 17 additions and 22 deletions

View file

@ -71,12 +71,13 @@ macro_rules! generate_endpoints_inner {
($variant:ident, $handler:ident, $request:expr_2021) => {
paste::paste! {
{
// INVARIANT:
// The handler functions in `cuprated` depend on this line existing,
// the functions themselves do not check if they are being called
// from an (un)restricted context.
// Check if restricted.
//
// This line must be here or all methods will be allowed to be called freely.
// INVARIANT:
// The RPC handler functions in `cuprated` depend on this line existing,
// the functions themselves do not check if they are being called
// from an (un)restricted context. This line must be here or all
// methods will be allowed to be called freely.
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
// TODO: mimic `monerod` behavior.
return Err(StatusCode::FORBIDDEN);

View file

@ -39,21 +39,16 @@ pub(crate) async fn json_rpc<H: RpcHandler>(
// the requested method is only for non-restricted RPC.
//
// INVARIANT:
// The handler functions in `cuprated` depend on this line existing,
// The RPC handler functions in `cuprated` depend on this line existing,
// the functions themselves do not check if they are being called
// from an (un)restricted context.
//
// This line must be here or all methods will be allowed to be called freely.
// from an (un)restricted context. This line must be here or all
// methods will be allowed to be called freely.
if request.body.is_restricted() && handler.is_restricted() {
let error_object = ErrorObject {
code: ErrorCode::ServerError(-1 /* TODO */),
message: Cow::Borrowed("Restricted. TODO: mimic monerod message"),
data: None,
};
let response = Response::err(id, error_object);
return Ok(Json(response));
// The error when a restricted JSON-RPC method is called as per:
//
// - <https://github.com/monero-project/monero/blob/893916ad091a92e765ce3241b94e706ad012b62a/contrib/epee/include/net/http_server_handlers_map2.h#L244-L252>
// - <https://github.com/monero-project/monero/blob/cc73fe71162d564ffda8e549b79a350bca53c454/src/rpc/core_rpc_server.h#L188>
return Ok(Json(Response::method_not_found(id)));
}
// Send request.

View file

@ -77,11 +77,10 @@ macro_rules! generate_endpoints_inner {
// Check if restricted.
//
// INVARIANT:
// The handler functions in `cuprated` depend on this line existing,
// The RPC handler functions in `cuprated` depend on this line existing,
// the functions themselves do not check if they are being called
// from an (un)restricted context.
//
// This line must be here or all methods will be allowed to be called freely.
// from an (un)restricted context. This line must be here or all
// methods will be allowed to be called freely.
if [<$variant Request>]::IS_RESTRICTED && $handler.is_restricted() {
// TODO: mimic `monerod` behavior.
return Err(StatusCode::FORBIDDEN);