Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Limit the number of attached databases to zero and enable defensive mode #234

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ fernet = { version = "0.2.1" }
lettre = { version = "0.10.4", features = ["tokio1-native-tls"] }
quoted_printable = { version = "0.5.0" }
reqwest = { version = "0.11.22", features = ["json"] }
rusqlite = { version = "0.27.0", features = ["bundled"] }
rusqlite = { version = "0.27.0", features = ["bundled", "limits"] }
regex = { version = "1.10.2"}
serde = { version = "1.0", features = ["derive"] }
serde_json = { version = "1.0.108" }
Expand Down
10 changes: 10 additions & 0 deletions src/hosted_db/sqlite.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
use crate::error::AybError;
use crate::hosted_db::QueryResult;
use rusqlite;
use rusqlite::config::DbConfig;
use rusqlite::limits::Limit;
use rusqlite::types::ValueRef;
use std::path::PathBuf;

pub fn run_sqlite_query(path: &PathBuf, query: &str) -> Result<QueryResult, AybError> {
let conn = rusqlite::Connection::open(path)?;

// Disable the usage of ATTACH
// https://www.sqlite.org/lang_attach.html
conn.set_limit(Limit::SQLITE_LIMIT_ATTACHED, 0);
// Prevent queries from deliberately corrupting the database
// https://www.sqlite.org/c3ref/c_dbconfig_defensive.html
conn.db_config(DbConfig::SQLITE_DBCONFIG_DEFENSIVE)?;

let mut prepared = conn.prepare(query)?;
let num_columns = prepared.column_count();
let mut fields: Vec<String> = Vec::new();
Expand Down