Skip to content

Validate Snowflake account and region before building the SQL API URL - #72174

Merged
shahar1 merged 2 commits into
apache:mainfrom
potiuk:fix-snowflake-account-validation
Sep 21, 2026
Merged

shahar1 merged 2 commits into
apache:mainfrom
potiuk:fix-snowflake-account-validation

Conversation

@potiuk

@potiuk potiuk commented Aug 27, 2026

Copy link
Copy Markdown
Member

The account and region connection fields are interpolated into the SQL API URL, with the .snowflakecomputing.com suffix appended as text:

url = f"{self.account_identifier}.snowflakecomputing.com/api/v2/statements"

Neither field was checked, so a value carrying URL-significant punctuation changed the address the request was sent to rather than just naming the account.

Both are now restricted to the characters a Snowflake account or region identifier is actually made of — letters, digits, ., _ and - — and anything else raises ValueError before a request is built. An empty account, which previously produced a meaningless host, is rejected too.

Test change worth flagging: four test_snowflake_sql_api tests patched _get_conn_params without setting a return value, so they were building their URLs from a MagicMock. They now use the CONN_PARAMS constant the rest of that file already uses.

Local: 386 passed, 11 skipped across the Snowflake provider; ruff and mypy clean.

🤖 Generated with Claude Code

@boring-cyborg boring-cyborg Bot added area:providers provider:snowflake Issues related to Snowflake provider labels Aug 27, 2026
@potiuk
potiuk force-pushed the fix-snowflake-account-validation branch from 55336ab to 7b9a736 Compare August 28, 2026 14:38

@justinpakzad justinpakzad left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I had a look through and aside from my comment below, we should probably apply the account validation in the SnowflakeCortexAgentHook._get_base_url as well since it builds the URL from the bare account value. Could be a followup if you want to keep this scoped to the SQL API, although it should be a fairly small change.

@potiuk
potiuk force-pushed the fix-snowflake-account-validation branch from 7b9a736 to 11e220b Compare September 18, 2026 10:26
@shahar1
shahar1 self-requested a review September 20, 2026 09:37
The account and region connection fields are interpolated into the SQL API URL,
with the .snowflakecomputing.com suffix appended as text. Restrict both to the
characters a Snowflake account or region identifier is made of, so neither can
carry URL-significant punctuation into the request address.

Four sql_api tests mocked _get_conn_params without a return value and so built
their URLs from a MagicMock; they now use the CONN_PARAMS constant the rest of
the file already uses.
Review pointed out the SQL API is not the only place a bare account
value reaches a URL: the OAuth token endpoint and the Cortex Agent base
URL build their host from it the same way, so the same unchecked value
could redirect those requests as well.

The line drawn is between fields that *name* the account (account,
region), which are validated, and fields that *are* the address
(token_endpoint, host), which stay the address the user configured.

Generated-by: Claude Opus 5
@potiuk
potiuk force-pushed the fix-snowflake-account-validation branch from d7e1807 to 1de1a7f Compare September 21, 2026 00:31
@shahar1
shahar1 merged commit bee4896 into apache:main Sep 21, 2026
83 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:providers provider:snowflake Issues related to Snowflake provider

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants