Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/store/adapters/postgres.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ pub async fn migrate(config: &StoreConfig) -> Result<()> {
.await?;

if !row.0 {
// `CREATE DATABASE` does not accept bind parameters for the database
// name. but this is not a critical SQL injection as the database name is not untrusted
// user input. nevertheless, let's validate DB identifiers to prevent the worst.
if !config
.pg
.database_name
.chars()
.all(|c| matches!(c, 'a'..='z' | 'A'..='Z' | '0'..='9' | '_'))
{
return Err(anyhow!(
"invalid database_name {:?}: only ASCII alphanumerics and underscores are allowed",
&config.pg.database_name
));
}

println!("Creating database {}", &config.pg.database_name);
sqlx::query(format!("CREATE DATABASE {}", &config.pg.database_name).as_str())
.execute(&default_pool)
Expand Down
Loading