Skip to content

feat(snowflake-driver): Support execute sql via custom procedure #9579

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

RusovDmitriy
Copy link
Member

No description provided.

this.config.snowflakeExecutionProcedure &&
query.toUpperCase().startsWith('SELECT')
) {
const escapedQuery = query.replace(/'/g, "\\'");

Check failure

Code scanning / CodeQL

Incomplete string escaping or encoding High

This does not escape backslash characters in the input.

Copilot Autofix

AI 4 days ago

To fix the issue, we need to ensure that backslashes in the query string are escaped before escaping single quotes. This can be achieved by first replacing all backslashes (\) with double backslashes (\\), and then replacing all single quotes (') with escaped single quotes (\'). This ensures that both backslashes and single quotes are properly escaped.

The best way to implement this fix is to chain two replace operations on the query string:

  1. Replace all backslashes (\) with double backslashes (\\).
  2. Replace all single quotes (') with escaped single quotes (\').

This change should be applied to line 892 in the execute method.


Suggested changeset 1
packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts b/packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts
--- a/packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts
+++ b/packages/cubejs-snowflake-driver/src/SnowflakeDriver.ts
@@ -891,3 +891,3 @@
     ) {
-      const escapedQuery = query.replace(/'/g, "\\'");
+      const escapedQuery = query.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
       const serializedBinds = `ARRAY_CONSTRUCT(${(values ?? [])
EOF
@@ -891,3 +891,3 @@
) {
const escapedQuery = query.replace(/'/g, "\\'");
const escapedQuery = query.replace(/\\/g, "\\\\").replace(/'/g, "\\'");
const serializedBinds = `ARRAY_CONSTRUCT(${(values ?? [])
Copilot is powered by AI and may make mistakes. Always verify output.
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant