SKY-D387 · Security in code
Exposed password written to a database
HighCWE-256
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
Why it matters
A reader with access to the stored records may be able to recover the original password.
What Skylos flags
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
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
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
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
- Skylos checks a literal INSERT with named columns or an UPDATE with simple assignments. It matches positional placeholders to the columns named
password,passwdorpassword_hash. The value bound at one of those positions must come from exposing a SecretString. - It checks bound values sent to rusqlite and SQLx. SQLx needs a visible execution such as an awaited
executecall. 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].