From 23a662b94cf74f54fb4e08a929a166cfcef760be Mon Sep 17 00:00:00 2001 From: Ruben Fiszel Date: Fri, 25 Aug 2023 14:38:30 +0200 Subject: [PATCH] encode special characters in postgres url --- backend/Cargo.lock | 1 + backend/windmill-queue/src/jobs.rs | 2 +- backend/windmill-worker/Cargo.toml | 1 + backend/windmill-worker/src/pg_executor.rs | 8 +++++--- 4 files changed, 8 insertions(+), 4 deletions(-) diff --git a/backend/Cargo.lock b/backend/Cargo.lock index 0cf6daa693..2df7580f6a 100644 --- a/backend/Cargo.lock +++ b/backend/Cargo.lock @@ -7399,6 +7399,7 @@ dependencies = [ "tokio", "tokio-postgres", "tracing", + "urlencoding", "uuid 1.4.1", "windmill-api-client", "windmill-audit", diff --git a/backend/windmill-queue/src/jobs.rs b/backend/windmill-queue/src/jobs.rs index 0fcc092712..3b4c256aa2 100644 --- a/backend/windmill-queue/src/jobs.rs +++ b/backend/windmill-queue/src/jobs.rs @@ -162,7 +162,7 @@ pub async fn cancel_job<'c: 'async_recursion>( let add_job = add_completed_job_error( &db, &job_running, - format!("canceled by {username}: (force cancel: {force_cancel}"), + format!("canceled by {username}: (force cancel: {force_cancel})"), serde_json::json!({"message": format!("Job canceled: {reason} by {username}"), "name": "Canceled", "reason": reason, "canceler": username}), None, rsmq.clone(), diff --git a/backend/windmill-worker/Cargo.toml b/backend/windmill-worker/Cargo.toml index f90313f58e..91e581feba 100644 --- a/backend/windmill-worker/Cargo.toml +++ b/backend/windmill-worker/Cargo.toml @@ -69,6 +69,7 @@ rust_decimal.workspace = true jsonwebtoken = { workspace = true, optional = true } sha2 = { workspace = true, optional = true } pem = { workspace = true, optional = true } +urlencoding.workspace = true [build-dependencies] deno_fetch.workspace = true diff --git a/backend/windmill-worker/src/pg_executor.rs b/backend/windmill-worker/src/pg_executor.rs index 206a382d5d..18ca1f14ae 100644 --- a/backend/windmill-worker/src/pg_executor.rs +++ b/backend/windmill-worker/src/pg_executor.rs @@ -19,6 +19,7 @@ use windmill_parser_sql::parse_pgsql_sig; use crate::common::transform_json_value; use crate::{AuthedClient, JobCompleted}; +use urlencoding::encode; #[derive(Deserialize)] struct PgDatabase { @@ -49,13 +50,14 @@ pub async fn do_postgresql( let sslmode = database.sslmode.unwrap_or("prefer".to_string()); let database = format!( "postgres://{user}:{password}@{host}:{port}/{dbname}?sslmode={sslmode}", - user = database.user.unwrap_or("postgres".to_string()), - password = database.password.unwrap_or("".to_string()), - host = database.host, + user = encode(&database.user.unwrap_or("postgres".to_string())), + password = encode(&database.password.unwrap_or("".to_string())), + host = encode(&database.host), port = database.port.unwrap_or(5432), dbname = database.dbname, sslmode = sslmode ); + tracing::error!("database: {}", database); let (client, handle) = if sslmode == "require" { let (client, connection) = tokio_postgres::connect( &database,