Skip to content

Escape values interpolated into Drive queries - #1

Closed
pragmabits wants to merge 1 commit into
mainfrom
fix/drive-query-escaping
Closed

pragmabits wants to merge 1 commit into
mainfrom
fix/drive-query-escaping

Conversation

@pragmabits

Copy link
Copy Markdown
Owner

Problem

list_spreadsheets, list_folders and search_spreadsheets build their Drive query by dropping caller-supplied values straight into a quoted term. An apostrophe closes that term early and whatever follows is read as query syntax.

Searching for x' or mimeType != 'nope produces:

mimeType='application/vnd.google-apps.spreadsheet' and (name contains 'x' or mimeType != 'nope' or fullText contains 'x' or mimeType != 'nope')

The mimeType filter no longer constrains anything, so the call can return arbitrary Drive files instead of spreadsheets.

Change

Adds _escape_query_value() and applies it at the three interpolation points. Backslashes are escaped before quotes, so an already-escaped quote in the input stays escaped.

Notes

  • No new configuration. This is a bug fix, so it applies to everyone rather than sitting behind a flag.
  • 7 unit tests, including one that asserts the injected fragment can no longer detach the mimeType filter.
  • Test suite green on Python 3.10, 3.12 and 3.13.

list_spreadsheets, list_folders and search_spreadsheets built their Drive query
by dropping caller-supplied values straight into a quoted term. An apostrophe in
the value closes that term early and whatever follows is read as query syntax:
searching for "x' or mimeType != 'nope" produced a query whose mimeType filter
no longer constrained anything, so the call could return arbitrary Drive files
instead of spreadsheets. Escape backslashes and quotes before interpolating,
handling the backslash first so an escaped quote in the input stays escaped.
@pragmabits pragmabits closed this Sep 2, 2026
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