Skip to main content

SKY-D387 · Security in code

Exposed password written to a database

A rusqlite or SQLx write binds the exposed contents of a SecretString to a password column.

Languages
Rust
Quality gate
counted toward the gate limits (full and diff scans)
Finding type
review
Wrong result? Report itA false positive, a missed case or a confusing message: it goes privately to the founder.

Why it matters

A reader with access to the stored records may be able to recover the original password.

What Skylos flags

src/lib.rs · RustReported on line 4
use secrecy::{ExposeSecret, SecretString};pub fn save(db: &rusqlite::Connection, pw: &SecretString) {    let raw = pw.expose_secret();    let _ = db.execute("INSERT INTO accounts(password) VALUES (?1)", [raw]);}

What Skylos leaves alone

src/lib.rs · Rust
pub fn save_hash(db: &rusqlite::Connection, hash: &argon2::password_hash::PasswordHash<'_>) {    let encoded = hash.to_string();    let _ = db.execute("INSERT INTO accounts(password_hash) VALUES (?1)", [encoded]);}

Why Skylos leaves it alone

The bound value is an encoded password hash.

More languages

Rust

Flagged

src/accounts.rs · RustReported on line 6
use secrecy::{ExposeSecret, SecretString};pub async fn save(pool: &sqlx::PgPool, id: i64, pw: &SecretString) {    let write = sqlx::query("UPDATE accounts SET password_hash = $2 WHERE id = $1")        .bind(id)        .bind(pw.expose_secret());    let _ = write.execute(pool).await;}

Not flagged

src/accounts.rs · Rust
pub async fn save(pool: &sqlx::PgPool, id: i64, hash: &argon2::password_hash::PasswordHash<'_>) {    let write = sqlx::query("UPDATE accounts SET password_hash = $2 WHERE id = $1")        .bind(id)        .bind(hash.to_string());    let _ = write.execute(pool).await;}

Why Skylos leaves it alone

The second parameter receives the encoded password hash.

How Skylos decides

  1. Skylos checks a literal INSERT with named columns or an UPDATE with simple assignments. It matches positional placeholders to the columns named password, passwd or password_hash. The value bound at one of those positions must come from exposing a SecretString.
  2. It checks bound values sent to rusqlite and SQLx. SQLx needs a visible execution such as an awaited execute call. Reading rows, binding an encoded hash, and building a query without running it stay quiet.

How to fix it

For account authentication, derive a salted password hash before saving the record.

When it can be wrong

  • Database-side triggers, encryption and schema policy are outside this local check.

Seeing a case that isn't listed here? Report the wrong result so the rule can be fixed. Don't paste company code: describe the shape of it.

How to silence it

  • Record the reason on the reported line with // skylos: ignore[SKY-D387].

From the Skylos rule handbook, Skylos 5.8.0 (commit 5b880b0). All rules.