Skip to content

fix(spanner_dbapi): replace insecure pickle with json for partition deserialization#17014

Open
sinhasubham wants to merge 1 commit into
mainfrom
dbApi-vlnr
Open

fix(spanner_dbapi): replace insecure pickle with json for partition deserialization#17014
sinhasubham wants to merge 1 commit into
mainfrom
dbApi-vlnr

Conversation

@sinhasubham
Copy link
Copy Markdown
Contributor

@sinhasubham sinhasubham commented May 11, 2026

This PR resolves a critical Insecure Deserialization vulnerability (potential Remote Code Execution) in the spanner_dbapi module b/510871112 . Previously, the module utilized pickle.loads() to decode partition IDs provided by users via the RUN PARTITION statement, creating a possibility for arbitrary code execution attack payloads.
We have fully eliminated pickle usage in this module and migrated to standard json serialization.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request replaces the use of pickle with json for serializing and deserializing partition IDs to mitigate security risks associated with insecure deserialization. It introduces _serialize_value and _deserialize_value helper functions to handle specific types like bytes, datetime, and protobuf messages. Review feedback points out that MessageToDict defaults to camelCase, which could break compatibility with code expecting snake_case, and suggests using preserving_proto_field_name=True. Additionally, the reviewer noted that protobuf messages are currently deserialized as dictionaries rather than original message objects, which may lead to issues with nested field types.

Comment thread packages/google-cloud-spanner/google/cloud/spanner_dbapi/partition_helper.py Outdated
Comment thread packages/google-cloud-spanner/google/cloud/spanner_dbapi/partition_helper.py Outdated
Comment thread packages/google-cloud-spanner/google/cloud/spanner_dbapi/partition_helper.py Outdated
@sinhasubham sinhasubham marked this pull request as ready for review May 12, 2026 06:00
@sinhasubham sinhasubham requested a review from a team as a code owner May 12, 2026 06:00
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.

1 participant