Skip to content

Simplify how SQL injection is detected when using query.comment-format#19413

Merged
hashhar merged 3 commits intotrinodb:masterfrom
dominikzalewski:format_based_remote_query_modifier_whitespace
Oct 23, 2023
Merged

Simplify how SQL injection is detected when using query.comment-format#19413
hashhar merged 3 commits intotrinodb:masterfrom
dominikzalewski:format_based_remote_query_modifier_whitespace

Conversation

@dominikzalewski
Copy link
Copy Markdown
Member

@dominikzalewski dominikzalewski commented Oct 16, 2023

Description

Instead of failing the query in case a character NOT in the allowlist is detected, now we search for occurence of the closing comment '*/' and only then fail the query.

Release notes

(X) This is not user-visible or is docs only, and no release notes are required.
( ) Release notes are required. Please propose a release note for me.
( ) Release notes are required, with the following suggested text:

@cla-bot cla-bot bot added the cla-signed label Oct 16, 2023
@dominikzalewski dominikzalewski changed the title Queries fail when any value in query.comment-format includes a whitespace/other special characters [WiP] Queries fail when any value in query.comment-format includes a whitespace/other special characters Oct 19, 2023
@dominikzalewski dominikzalewski force-pushed the format_based_remote_query_modifier_whitespace branch 5 times, most recently from 8f0f063 to 94c7967 Compare October 19, 2023 16:05
@dominikzalewski dominikzalewski changed the title [WiP] Queries fail when any value in query.comment-format includes a whitespace/other special characters Simplify how SQL injection is detected when using query.comment-format Oct 19, 2023
@dominikzalewski dominikzalewski force-pushed the format_based_remote_query_modifier_whitespace branch from 94c7967 to 2691b47 Compare October 19, 2023 16:56
Copy link
Copy Markdown
Member

@kokosing kokosing left a comment

Choose a reason for hiding this comment

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

I am fine with the approach

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is copied and modified SessionInterpolatedValues since the original object is also used in BigQuery

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it's ok to limit the scope by not fixing for BigQuery but same problem still exists in connectors who use SessionInterpolatedValues.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Will create a follow-up ticket then and put it in the backlog

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think you can simply remove io.trino.plugin.base.logging.SessionInterpolatedValues.SanitizedValuesProvider from SessionInterpolatedValues. I think the case in BigQuery is safe to be changed. There is no way to inject SQL as it is used only to set the label.

@dominikzalewski dominikzalewski marked this pull request as ready for review October 20, 2023 05:31
Copy link
Copy Markdown
Member

@hashhar hashhar left a comment

Choose a reason for hiding this comment

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

LGTM.

Note that non-JDBC connectors will still fail though.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

it's ok to limit the scope by not fixing for BigQuery but same problem still exists in connectors who use SessionInterpolatedValues.

@dominikzalewski dominikzalewski force-pushed the format_based_remote_query_modifier_whitespace branch 2 times, most recently from fc143ed to 3a49a2e Compare October 20, 2023 11:05
@kokosing
Copy link
Copy Markdown
Member

it's ok to limit the scope by not fixing for BigQuery

IIRC the case of BigQuery is way different. It does not use comment, but there is a dedicated field where put audit information. In such case there is no way for SQL Injection

@hashhar
Copy link
Copy Markdown
Member

hashhar commented Oct 21, 2023

Then instead of calling this new class ...Simple... we should call it "InterpolatedSessionValuesForSql"? Simple anyway doesn't convey any meaning.

Thanks for checking @kokosing , yes it uses a dedicated label field instead of adding to query text itself. So BigQuery isn't impacted.

@dominikzalewski dominikzalewski force-pushed the format_based_remote_query_modifier_whitespace branch from 3a49a2e to 37aee7d Compare October 23, 2023 07:36
Instead of failing the query in case a character NOT in the allowlist
is detected, now we search for occurence of the closing comment '*/'
and only then fail the query.
@dominikzalewski dominikzalewski force-pushed the format_based_remote_query_modifier_whitespace branch from 37aee7d to dc52ca6 Compare October 23, 2023 07:51
@hashhar hashhar merged commit 6db8a4d into trinodb:master Oct 23, 2023
@github-actions github-actions bot added this to the 431 milestone Oct 23, 2023
@dominikzalewski dominikzalewski deleted the format_based_remote_query_modifier_whitespace branch October 23, 2023 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants