Skip to content

Unreachable OpenRPC rpc.discover method #119

@ergoithz

Description

@ergoithz

Description

json-rpc completely prevents the usage of rpc. method namespace, aimed at system extensions, preventing any user or library from implementing said extensions.

if value.startswith("rpc."):
raise ValueError(
"Method names that begin with the word rpc followed by a " +
"period character (U+002E or ASCII 46) are reserved for " +
"rpc-internal methods and extensions and MUST NOT be used " +
"for anything else.")

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

  1. Declare a rpc.discover on a test application testrpc.py (and pip 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)
  1. Run application:
python testrpc.py
  1. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions