Skip to content
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

Fix for ClickHouse sql injection by removing ability to have expression in table options #16261

Merged

Conversation

vlad-lyutenko
Copy link
Contributor

@vlad-lyutenko vlad-lyutenko commented Feb 24, 2023

Description

Fix for ClickHouse sql injection

by removing ability to have expression in table options

Additional context and related issues

Release notes

(x) Release notes are required, with the following suggested text:

# ClickHouse
* Remove support for specifying expressions in `sample_by` table properties to prevent SQL injection. ({issue}`16261`)

@cla-bot cla-bot bot added the cla-signed label Feb 24, 2023
@@ -363,7 +369,7 @@ public void setTableProperties(ConnectorSession session, JdbcTableHandle handle,
.collect(toImmutableMap(Entry::getKey, entry -> entry.getValue().orElseThrow()));

ImmutableList.Builder<String> tableOptions = ImmutableList.builder();
ClickHouseTableProperties.getSampleBy(properties).ifPresent(value -> tableOptions.add("SAMPLE BY " + value));
ClickHouseTableProperties.getSampleBy(properties).ifPresent(value -> tableOptions.add("SAMPLE BY " + doubleQuote(value)));
Copy link
Member

Choose a reason for hiding this comment

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

Is quoting only SAMPLE BY property sufficient? What about other properties?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The same for all others.

@vlad-lyutenko vlad-lyutenko force-pushed the vlad-lyutenko/clickhouse-sample-by-fix branch 2 times, most recently from 2adb465 to 8d1092f Compare February 27, 2023 14:19
@@ -28,7 +28,7 @@
implements SessionPropertiesProvider
{
public static final String MAP_STRING_AS_VARCHAR = "map_string_as_varchar";

public static final String ALLOWED_EXPRESSION_IN_TABLE_OPTIONS = "allowed_expression_in_table_options";
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we want to allow end-users to enable this session property. Otherwise, even if the cluster administrator disabled this flag in the config property, users can enable it and cause SQL injection.

I lean toward removing support for expressions though it might be a regression for some users. I roughly guess there're less users who specify the expression in the SAMPLE BY in the connector. Also, security should win in this case. What do you think about it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Refactored

in table options like SAMPLE BY e.t.c
@vlad-lyutenko vlad-lyutenko force-pushed the vlad-lyutenko/clickhouse-sample-by-fix branch from 8d1092f to d20aeff Compare February 28, 2023 14:01
@vlad-lyutenko vlad-lyutenko changed the title Fix for ClickHouse alter create table with sample by injection Fix for ClickHouse sql injection by removing ability to have expression in table options Feb 28, 2023
Copy link
Member

@ebyhr ebyhr left a comment

Choose a reason for hiding this comment

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

Looks good except for a comment.

@ebyhr ebyhr merged commit d2b33fe into trinodb:master Feb 28, 2023
@ebyhr ebyhr mentioned this pull request Feb 28, 2023
@github-actions github-actions bot added this to the 409 milestone Mar 1, 2023
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.

2 participants