Unreachable OpenRPC rpc.discover method
Description
json-rpc completely prevents the usage of rpc. method namespace, aimed at system extensions, preventing any user or library from implementing said extensions.
https://github.com/pavlov99/json-rpc/blob/00b24a9e811d9ca89ec3b1570195c881687bbef4/jsonrpc/jsonrpc2.py#L74-L79
Nowhere in the JSON-RPC specification it is said that the usage of rpc. methods must be unconditionally forbidden, the restriction is reserved for system extensions, and MUST NOT be used for anything else, so its usage for system extensions is explicitly stated.
Blocking that namespace for system extensions is an explicit violation of the specification, and that fact impacts OpenRPC, which makes uses that namespace for its rpc.discover method (spec specification) (albeit OpenRPC rpc.discover being really a system extension or not is debatable, just like what a system extension itself really means).
Steps to Reproduce
- Declare a
rpc.discoveron a test applicationtestrpc.py(andpip install werkzeug jsonrpc).
from werkzeug.wrappers import Request, Response
from werkzeug.serving import run_simple
from jsonrpc import JSONRPCResponseManager, dispatcher
@dispatcher.add_method(name='rpc.discover')
def rpc_discover():
return {
"openrpc": "1.2.6",
"info": {
"title": "OpenRPC API",
"version": "0.0.1"
},
"methods": [{
"name": "rpc.discover",
"description": "Returns an OpenRPC schema as a description of this service",
"result": {
"name": "OpenRPC Schema",
"schema": {
"$ref": "https://raw.githubusercontent.com/open-rpc/meta-schema/master/schema.json"
}
}
}]
}
@Request.application
def application(request):
response = JSONRPCResponseManager.handle(request.get_data(cache=False, as_text=True), dispatcher)
return Response(response.json, mimetype='application/json')
if __name__ == '__main__':
run_simple('localhost', 8000, application)
- Run application:
python testrpc.py
- Call endpoint
curl localhost:8000 -d '{"jsonrpc":"2.0","method":"rpc.discover","id":0,"params":{}}'
Expected behavior:
{
"result": {
"openrpc": "1.2.6",
"info": {
"title": "OpenRPC API",
"version": "0.0.1"
},
"methods": [
{
"name": "rpc.discover",
"description": "Returns an OpenRPC schema as a description of this service",
"result": {
"name": "OpenRPC Schema",
"schema": {
"$ref": "https://raw.githubusercontent.com/open-rpc/meta-schema/master/schema.json"
}
}
}
]
},
"id": 0,
"jsonrpc": "2.0"
}
Actual behavior:
{
"error": {
"code": -32600,
"message": "Invalid Request"
},
"id": null,
"jsonrpc": "2.0"
}
Reproduces how often: happens every time.
Versions
All python versions, json-rpc-1.13.0.
Workaround (overriding method property):
import jsonrpc.jsonrpc2
jsonrpc.jsonrpc2.JSONRPC20Request.method = None