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

SQL: fix handling of escaped chars in JDBC connection string #58429

Merged
merged 4 commits into from Jun 26, 2020

Conversation

bpintea
Copy link
Contributor

@bpintea bpintea commented Jun 23, 2020

This PR fixes an issue emerging when the connection string URI
contains escaped characters.

The original URI is pre-parsed in order to re-assemble a new URI having
the optional elements filled in with defaults. The new URI has been
using however the unescaped query and fragment parts. So if these
contained any escaped & or = (such as in the password option value),
the unescaping would reveal them and make them later interfere with the
options parsing.

The PR changes that, so that the new URI be built from the unescaped
"raw" parts of the original URI.

Closes #57927

This commit fixes an issue emerging when the connection string URI
contains escaped characters.

The original URI is pre-parsed in order to re-assemble a new URI having
the optional elements filled in with defaults. The new URI has been
using however the unescaped query and fragment parts. So if these
contained any escaped `&` or `=` (such as in the password option value),
the unescaping would reveal them and make them later interfere with the
options parsing.

The commit changes that, so that the new URI be built from the unescaped
"raw" parts of the original URI.
@bpintea
Copy link
Contributor Author

bpintea commented Jun 23, 2020

@elasticmachine update branch

@bpintea
Copy link
Contributor Author

bpintea commented Jun 23, 2020

@elasticmachine run elasticsearch-ci/default-distro

@bpintea
Copy link
Contributor Author

bpintea commented Jun 24, 2020

@elasticmachine update branch

@bpintea bpintea marked this pull request as ready for review June 24, 2020 10:59
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (:Query Languages/SQL)

@elasticmachine elasticmachine added the Team:QL (Deprecated) Meta label for query languages team label Jun 24, 2020
Copy link
Member

@costin costin left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. left a minor comment.

@@ -208,7 +215,8 @@ public boolean indexIncludeFrozen() {
}

public static boolean canAccept(String url) {
return (StringUtils.hasText(url) && url.trim().startsWith(JdbcConfiguration.URL_PREFIX));
return (StringUtils.hasText(url) &&
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: I would trim the url and use a local var to avoid trimming it potentially twice.

Copy link
Contributor

@astefan astefan left a comment

Choose a reason for hiding this comment

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

LGTM

- prevent double trimming of the connection string;
- improve docs
@bpintea bpintea requested a review from matriv June 25, 2020 21:23
Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. Thx for the randomization of the prefix in the tests!

@bpintea bpintea merged commit 94eb5a0 into elastic:master Jun 26, 2020
@bpintea bpintea deleted the fix/57927_escaped_chars_in_uri_query branch June 26, 2020 08:19
bpintea added a commit to bpintea/elasticsearch that referenced this pull request Jul 2, 2020
…#58429)

* Fix: preserve URI query and fragment char escaping

This commit fixes an issue emerging when the connection string URI
contains escaped characters.

The original URI is pre-parsed in order to re-assemble a new URI having
the optional elements filled in with defaults. The new URI has been
using however the unescaped query and fragment parts. So if these
contained any escaped `&` or `=` (such as in the password option value),
the unescaping would reveal them and make them later interfere with the
options parsing.

The commit changes that, so that the new URI be built from the unescaped
"raw" parts of the original URI.

(cherry picked from commit 94eb5a0)
bpintea added a commit to bpintea/elasticsearch that referenced this pull request Jul 2, 2020
…#58429)

* Fix: preserve URI query and fragment char escaping

This commit fixes an issue emerging when the connection string URI
contains escaped characters.

The original URI is pre-parsed in order to re-assemble a new URI having
the optional elements filled in with defaults. The new URI has been
using however the unescaped query and fragment parts. So if these
contained any escaped `&` or `=` (such as in the password option value),
the unescaping would reveal them and make them later interfere with the
options parsing.

The commit changes that, so that the new URI be built from the unescaped
"raw" parts of the original URI.

(cherry picked from commit 94eb5a0)
bpintea added a commit that referenced this pull request Jul 3, 2020
…58429) (#58977)

SQL: fix handling of escaped chars in JDBC connection string (#58429)

This commit fixes an issue emerging when the connection string URI
contains escaped characters.

The original URI is pre-parsed in order to re-assemble a new URI having
the optional elements filled in with defaults. The new URI has been
using however the unescaped query and fragment parts. So if these
contained any escaped `&` or `=` (such as in the password option value),
the unescaping would reveal them and make them later interfere with the
options parsing.

The commit changes that, so that the new URI be built from the unescaped
"raw" parts of the original URI.

(cherry picked from commit 94eb5a0)
bpintea added a commit that referenced this pull request Jul 3, 2020
…58429) (#58976)

SQL: fix handling of escaped chars in JDBC connection string (#58429)

This commit fixes an issue emerging when the connection string URI
contains escaped characters.

The original URI is pre-parsed in order to re-assemble a new URI having
the optional elements filled in with defaults. The new URI has been
using however the unescaped query and fragment parts. So if these
contained any escaped `&` or `=` (such as in the password option value),
the unescaping would reveal them and make them later interfere with the
options parsing.

The commit changes that, so that the new URI be built from the unescaped
"raw" parts of the original URI.

(cherry picked from commit 94eb5a0)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQL: JDBC: password attribute in connection string won't take escaped '&' or '='
6 participants