Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unreachable OpenRPC rpc.discover method #119

Open
ergoithz opened this issue Apr 19, 2021 · 1 comment
Open

Unreachable OpenRPC rpc.discover method #119

ergoithz opened this issue Apr 19, 2021 · 1 comment

Comments

@ergoithz
Copy link

ergoithz commented Apr 19, 2021

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.

@ergoithz
Copy link
Author

ergoithz commented Apr 19, 2021

Workaround (overriding method property):

import jsonrpc.jsonrpc2
jsonrpc.jsonrpc2.JSONRPC20Request.method = None

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant