-
Notifications
You must be signed in to change notification settings - Fork 102
Test parameter escaping #46
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @susodapop LGTM.
I added a few non-blocking comments for adding more tests.
tests/unit/test_param_escaper.py
Outdated
assert pe.escape_string("golly bob howdy") == "'golly bob howdy'" | ||
|
||
def test_escape_string_that_includes_quotes(self): | ||
# Databricks queries support just one special character: a single quote mark |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i don't understand this comment, per the spark docs backslash is used for escaping (so it too is a special character)
you might also try this query in Databricks SQL:
select 'cat\'s meow'
union all
select 'cat\\\'s meow'
union all
select '\U0001F44D \u3042'
see also #51
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good callout. Removing this comment in dd25478
Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
67a3841
to
bce1598
Compare
escaping a single quote with a second single quote. Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
…provided Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
Signed-off-by: Jesse Whitehouse <[email protected]>
This was originally written in such a way that it always passed. Signed-off-by: Jesse Whitehouse <[email protected]>
### Description Upgrades `databricks-sql-connector` to `2.2.2`. It includes: - Add tests for parameter sanitisation / escaping (databricks/databricks-sql-python#46) for the fix for #249 - Support Python 3.11 (databricks/databricks-sql-python#60)
### Description Upgrades `databricks-sql-connector` to `2.2.2`. It includes: - Add tests for parameter sanitisation / escaping (databricks/databricks-sql-python#46) for the fix for #249 - Support Python 3.11 (databricks/databricks-sql-python#60)
### Description Upgrades `databricks-sql-connector` to `2.2.2`. It includes: - Add tests for parameter sanitisation / escaping (databricks/databricks-sql-python#46) for the fix for #249 - Support Python 3.11 (databricks/databricks-sql-python#60)
### Description Upgrades `databricks-sql-connector` to `2.2.2`. It includes: - Add tests for parameter sanitisation / escaping (databricks/databricks-sql-python#46) for the fix for #249 - Support Python 3.11 (databricks/databricks-sql-python#60)
Background
databricks-sql-connector
adheres to PEP-249 which defines a parameter binding API. For supported databases, parameter binding avoids SQL-injection vulnerabilities because parameter values are always escaped at runtime. The hive thrift server doesn't support safe parameter binding (yet!). This means that all queries are passed as strings and are therefore vulnerable to SQL-injection. It's the client's responsibility to safely handle parameterised input before callingcursor.execute(<some query text>)
.databricks-sql-connector
automatically sanitises inputs that follow the PEP-249 calling convention. This pull request adds unit tests to demonstrate the sanitisation behaviour. It also sets a baseline we can use for testing server-side parameter binding once it's supported by the Databricks runtime.In a follow-up PR, I will add examples that use the PEP-249 parameter binding interface. Once Databricks runtime supports proper server-side binding, users of
databricks-sql-connector
will benefit from its enhanced safety "for free", without needing to rewrite their client code.