fix(supabase): security pass on the files foundation — ceiling counts live bytes only, confirm checks the account, null sha256 refused, browser RPCs one role; worker: cleartext only on loopback or a service name, no env proxy, key ownership cross-check, no library text in logs

Security audit (PASS, 2 MEDIUM + LOW): the global ceiling summed every
non-deleted row, so rejected uploads ratcheted it toward storage_full with no
disk used → in-flight rows by declared size, clean rows by byte_size, nothing
else (pgTAP: rejected rows do not count, in-flight rows do); confirm refuses a
deactivated account like begin; complete_avatar_job refuses a null sha256;
begin / confirm / remove granted to authenticated only. Worker: SUPABASE_URL
over http:// accepted only for loopback or a single-label Docker service
name; ureq proxy(None); the job's keys must embed its owner and asset ids;
backend_failure / claim_failed / sweep_failure lines carry the closed kind and
the HTTP status, never the library's error text. e2e: uuid shape checked
before the psql query. Contract revision 2 (oracle fixes).
This commit is contained in:
bchanot committed 2026-10-13 19:49:58 +02:00
1 parent 62eb4e5d82
commit cd2dbb3b79
11 files changed
+124 -31

No files matched your search

+11
View File
@@ -79,6 +79,13 @@ pub fn validate_any_key(key: &str) -> Result<(), KeyError> {
}
}
/// True when a (valid) key's owner and asset segments are exactly these ids.
pub fn belongs_to(key: &str, owner_id: &str, asset_id: &str) -> bool {
let mut segments = key.split('/');
segments.next();
segments.next() == Some(owner_id) && segments.next() == Some(asset_id)
}
/// The asset id embedded in a valid quarantine key.
pub fn asset_id_of_quarantine_key(key: &str) -> Option<&str> {
validate_quarantine_key(key).ok()?;
@@ -140,6 +147,10 @@ mod tests {
assert_eq!(validate_any_key(key).err(), Some(*expected), "{key}");
}
assert_eq!(asset_id_of_quarantine_key("quarantine/a/b/upload"), None);
let key = format!("profiles/{U1}/{U2}/avatar.webp");
assert!(belongs_to(&key, U1, U2));
assert!(!belongs_to(&key, U2, U1));
assert!(!belongs_to(&key, U1, U1));
assert!(!is_uuid("10000000-0000-0000-0000-00000000000"));
}
}