Skip to content

Conversation

@F1r3Hydr4nt
Copy link
Collaborator

No description provided.

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
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.
Stack trace information
flows to this location and may be exposed to an external user.

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 of str(e) or f"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 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 including e!s.

No additional imports or method definitions are needed.

Suggested changeset 1
src/bsv_wallet_toolbox/rpc/json_rpc_server.py
Outside changed files

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/src/bsv_wallet_toolbox/rpc/json_rpc_server.py b/src/bsv_wallet_toolbox/rpc/json_rpc_server.py
--- a/src/bsv_wallet_toolbox/rpc/json_rpc_server.py
+++ b/src/bsv_wallet_toolbox/rpc/json_rpc_server.py
@@ -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,
             }
 
EOF
@@ -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,
}

Copilot is powered by AI and may make mistakes. Always verify output.
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

Successfully merging this pull request may close these issues.

3 participants