Skip to content

Commit 1811615

Browse files
committed
make snowflake url construction safer
1 parent 2567e9c commit 1811615

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

src/platform/notebooks/deepnote/sqlIntegrationEnvironmentVariablesProvider.ts

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -96,36 +96,38 @@ function convertIntegrationConfigToJson(config: IntegrationConfig): string {
9696
const database = config.database ? `/${encodeURIComponent(config.database)}` : '';
9797
url = `snowflake://${encodedUsername}:${encodedPassword}@${encodedAccount}${database}`;
9898

99-
const queryParams: string[] = [];
99+
const queryParams = new URLSearchParams();
100100
if (config.warehouse) {
101-
queryParams.push(`warehouse=${encodeURIComponent(config.warehouse)}`);
101+
queryParams.set('warehouse', config.warehouse);
102102
}
103103
if (config.role) {
104-
queryParams.push(`role=${encodeURIComponent(config.role)}`);
104+
queryParams.set('role', config.role);
105105
}
106-
queryParams.push('application=Deepnote');
106+
queryParams.set('application', 'Deepnote');
107107

108-
if (queryParams.length > 0) {
109-
url += `?${queryParams.join('&')}`;
108+
const queryString = queryParams.toString();
109+
if (queryString) {
110+
url += `?${queryString}`;
110111
}
111112
} else if (config.authMethod === SnowflakeAuthMethods.SERVICE_ACCOUNT_KEY_PAIR) {
112113
// Service account key-pair authentication
113114
const encodedUsername = encodeURIComponent(config.username);
114115
const database = config.database ? `/${encodeURIComponent(config.database)}` : '';
115116
url = `snowflake://${encodedUsername}@${encodedAccount}${database}`;
116117

117-
const queryParams: string[] = [];
118+
const queryParams = new URLSearchParams();
118119
if (config.warehouse) {
119-
queryParams.push(`warehouse=${encodeURIComponent(config.warehouse)}`);
120+
queryParams.set('warehouse', config.warehouse);
120121
}
121122
if (config.role) {
122-
queryParams.push(`role=${encodeURIComponent(config.role)}`);
123+
queryParams.set('role', config.role);
123124
}
124-
queryParams.push('authenticator=snowflake_jwt');
125-
queryParams.push('application=Deepnote');
125+
queryParams.set('authenticator', 'snowflake_jwt');
126+
queryParams.set('application', 'Deepnote');
126127

127-
if (queryParams.length > 0) {
128-
url += `?${queryParams.join('&')}`;
128+
const queryString = queryParams.toString();
129+
if (queryString) {
130+
url += `?${queryString}`;
129131
}
130132

131133
// For key-pair auth, pass the private key and passphrase as params

0 commit comments

Comments
 (0)