-
Notifications
You must be signed in to change notification settings - Fork 1
Test branch #10
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
base: master
Are you sure you want to change the base?
Test branch #10
Conversation
…tracks, Monitor not implemented?
Implemented JSON-RPC server with Django
| response_data = server.handle_json_rpc_request(request_data) | ||
|
|
||
| # Return JSON response | ||
| return JsonResponse(response_data, status=200) |
Check warning
Code scanning / CodeQL
Information exposure through an exception Medium
Stack trace information
Stack trace information
Stack trace information
Show autofix suggestion
Hide autofix suggestion
Copilot Autofix
AI 2 days ago
The best way to fix the problem is to ensure that error messages sent to clients are generic and do not contain exception-derived details.
- In
src/bsv_wallet_toolbox/rpc/json_rpc_server.py:- In all relevant
except Exception as e:blocks and similar, update the returned error object so that the"message"field uses a hardcoded, generic string instead ofstr(e)orf"Internal error: {e!s}". - Log the actual details server-side, but always return either
"Internal error"for unexpected exceptions, or use the protocol-specified generic messages for known exception types.
- In all relevant
- In
examples/django_server/wallet_app/views.py:- No change is needed, as this endpoint already returns the result from the RPC server, and the actual leak occurs upstream (in the RPC error construction).
The detailed change:
- For all three error-generating blocks in
src/bsv_wallet_toolbox/rpc/json_rpc_server.py, change:JsonRpcInternalError(str(e)).to_dict()→JsonRpcInternalError().to_dict()JsonRpcInternalError(f"Internal error: {e!s}").to_dict()→JsonRpcInternalError().to_dict()- Similarly for parameter errors: optionally, sanitize the error message for
JsonRpcInvalidParamsError, but if further sanitization is desired, make even this message generic, e.g. "Invalid parameters" instead of includinge!s.
No additional imports or method definitions are needed.
-
Copy modified line R472 -
Copy modified line R475 -
Copy modified line R517 -
Copy modified line R526
| @@ -469,10 +469,10 @@ | ||
| } | ||
|
|
||
| except Exception as e: | ||
| logger.error(f"Unexpected error during request validation: {e}") | ||
| logger.error(f"Unexpected error during request validation: {e}", exc_info=True) | ||
| return { | ||
| "jsonrpc": "2.0", | ||
| "error": JsonRpcInternalError(str(e)).to_dict(), | ||
| "error": JsonRpcInternalError().to_dict(), | ||
| "id": request_id, | ||
| } | ||
|
|
||
| @@ -516,7 +514,7 @@ | ||
| logger.warning(f"Invalid params for method {method}: {e}") | ||
| return { | ||
| "jsonrpc": "2.0", | ||
| "error": JsonRpcInvalidParamsError(f"Invalid parameters: {e!s}").to_dict(), | ||
| "error": JsonRpcInvalidParamsError().to_dict(), | ||
| "id": request_id, | ||
| } | ||
|
|
||
| @@ -525,7 +523,7 @@ | ||
| logger.error(f"Internal error in method {method}: {e}", exc_info=True) | ||
| return { | ||
| "jsonrpc": "2.0", | ||
| "error": JsonRpcInternalError(f"Internal error: {e!s}").to_dict(), | ||
| "error": JsonRpcInternalError().to_dict(), | ||
| "id": request_id, | ||
| } | ||
|
|
No description provided.