Skip to content

fix(sqlite): reject SQLite URLs with user, password, or port - #998

Closed
HarshRajSinghania wants to merge 3 commits into
AndreaBozzo:masterfrom
HarshRajSinghania:fix/sqlite-url-credentials
Closed

HarshRajSinghania wants to merge 3 commits into
AndreaBozzo:masterfrom
HarshRajSinghania:fix/sqlite-url-credentials

Conversation

@HarshRajSinghania

@HarshRajSinghania HarshRajSinghania commented Oct 19, 2026 •

Copy link
Copy Markdown

Summary

SqliteConnector::new now rejects SQLite connection strings that contain a user, password, or port. These were previously accepted and silently misinterpreted (credentials dropped or treated as part of the filename).

Motivation

Addresses #997. SQLite has no network endpoint or credentials, so such URLs are always mistakes (e.g. a PostgreSQL URL with the scheme changed).

Implementation

After parsing ConnectionInfo, if username, password, or port is present the constructor returns DatabaseConfigError. The message names the rejected parts (never the password value) and lists the supported forms:

  • sqlite:///absolute/path.db
  • sqlite://relative/path.db
  • sqlite::memory:
  • bare file path

A host by itself remains allowed (as in sqlite://relative/path.db).

Testing

cargo test -p dataprof-db --features sqlite --lib sqlite::tests

All five new unit tests passed:

  • rejects_user
  • rejects_password
  • rejects_port
  • rejects_user_password_and_port (confirms password value is not echoed)
  • accepts_supported_forms

Also ran cargo fmt on the changed file.

No other files changed.

Summary by CodeRabbit

  • Bug Fixes
    • SQLite connections now provide a clear configuration error when a connection string includes an unsupported username, password, or port. Error messages do not reveal password values and explain which connection formats are supported.
    • Connection strings with a host alone remain accepted, as do supported URL and bare-path formats.

Harsh Raj Singhania added 3 commits October 19, 2026 13:11
SQLite has no network endpoint or credentials. Connection strings that
include them were previously accepted and silently misinterpreted.

SqliteConnector::new now returns DatabaseConfigError naming the rejected
parts and listing the supported forms. Unit tests cover each rejection
and the supported forms.

Fixes AndreaBozzo#997
SQLite has no network endpoint or credentials. Connection strings that
include them were previously accepted and silently misinterpreted.

SqliteConnector::new now returns DatabaseConfigError naming the rejected
parts and listing the supported forms. Unit tests cover each rejection
and the supported forms.

Fixes AndreaBozzo#997
SQLite has no network endpoint or credentials. Connection strings that
include them were previously accepted and silently misinterpreted.

SqliteConnector::new now returns DatabaseConfigError naming the rejected
parts and listing the supported forms. Unit tests cover each rejection
and the supported forms.

Fixes AndreaBozzo#997
@coderabbitai

coderabbitai Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: aef0c1d1-7f8b-41fd-bdfa-0b9238a6e2e0
📥 Commits

Reviewing files that changed from the base of the PR and between 1dcca12 and 0aac8de.

📒 Files selected for processing: 1
  • crates/dataprof-db/src/connectors/sqlite.rs

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

📝 Walkthrough

The SQLite connector rejects connection strings with a username, password, or port. Schema and row-count queries use captured-identifier formatting for table names.

Changes: SQLite connector

Layer / File(s) Summary
Connection string validation
crates/dataprof-db/src/connectors/sqlite.rs
SqliteConnector::new rejects usernames, passwords, and ports, and reports the unsupported components. Tests cover these rejections and accepted URL and bare-path forms. SqliteConnector derives Debug.
Table-name query formatting
crates/dataprof-db/src/connectors/sqlite.rs
Schema and row-count queries use captured-identifier formatting for table_name. Row-count identifier validation and query error handling remain unchanged.

Priority: ⬇️ Low

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix

Merge Risk: ⚪ Minimal · up to 0aac8

No merge-blocking issue is established for this change. The schema-query validation concern is pre-existing.

Pre-merge checks: Passed 4 · Failed 1

Failed Failed checks: 1 warning

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 72.73% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 11 functions across 1 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed Passed checks: 4 passed
Check name Status Explanation
Description check Passed The description clearly explains the behavior change, motivation, implementation, supported forms, and verification results. It does not use the template headings or explicitly state whether breaking …
Title check Passed The title is concise, specific, and accurately describes the primary change: rejecting SQLite URLs with a user, password, or port.
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Description check

Explanation

The description clearly explains the behavior change, motivation, implementation, supported forms, and verification results. It does not use the template headings or explicitly state whether breaking changes or feature flags apply, but the required information is mostly present.

  • Fix all pre-merge checks with AI
✨ Finishing Touches: 💡 1
🧪 Generate unit tests (beta)
  • Create a new PR
🛠️ Fix failing CI checks: 💡
  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added area: rust Pull requests that update rust code area: database Database connectors and SQL labels Oct 19, 2026

@AndreaBozzo AndreaBozzo left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Thanks for picking this up. The check is what #997 asks for: the message names the parts without echoing the password, lists the supported forms, and a host alone still passes.

Before it can merge:

  1. Code Quality fails on cargo fmt. Running cargo fmt --all fixes it (inline).
  2. Please revert the edits unrelated to the fix in get_table_schema, count_table_rows and test_connection: the inlined format! arguments and the removed blank lines. One behaviour change per PR keeps the diff to the fix.
  3. The Debug derive is only there for the tests (inline).

A note, not a request: since #990, sqlite://data@2026.db opens a file literally named data@2026.db, and this check now rejects it as a user. That is what #997 specifies and the bare path data@2026.db still works, so no change needed.

use {sqlx::sqlite::SqlitePool, sqlx::sqlite::SqlitePoolOptions};

/// SQLite embedded database connector
#[derive(Debug)]

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

This adds a public Debug impl only so the tests can call unwrap_err(). The Postgres and MySQL connectors don't derive it either. The tests can do without:

let Err(err) = SqliteConnector::new(config(url)) else {
    panic!("{url} should be rejected");
};

let pool = self.pool.as_ref().ok_or_else(not_connected_error)?;

let query = format!("PRAGMA table_info({})", table_name);
let query = format!("PRAGMA table_info({table_name})");

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Unrelated to the fix, please revert this, the COUNT(*) line below and the removed blank lines.

"/absolute/path.db",
"relative.db",
] {
SqliteConnector::new(config(url)).unwrap_or_else(|e| panic!("should accept {url}: {e}"));

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

rustfmt splits this over two lines, which is what fails Code Quality.

@AndreaBozzo

Copy link
Copy Markdown
Owner

Reopen this eventually

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: database Database connectors and SQL area: rust Pull requests that update rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants