fix(supabase): second security pass — ceiling counts queued purges, confirm refuses more than declared, upload predicate needs an active account; worker cleartext host check strict

Re-audit findings: the ceiling now also counts terminal rows whose keys still
wait in the purge queue (contract wording kept honest, residual named);
confirm_asset_upload refuses an object larger than the declared size;
can_upload_avatar_object joins profiles.active; pgTAP covers the null
sha256 guard on a live lease, the three service_role revocations, the
queued-purge accounting and the deactivated-account upload (plan 137).
Worker: cleartext http only for localhost, a dotted-quad loopback address or
a non-numeric single-label name (numeric and hex hosts refused, tests added).
This commit is contained in:
bchanot committed 2026-10-13 19:58:54 +02:00
1 parent cd2dbb3b79
commit c386a08b0b
5 files changed
+75 -14

No files matched your search

+17 -2
View File
@@ -136,10 +136,21 @@ fn parse_url(raw: String) -> Result<String, ConfigError> {
Ok(url)
}
/// Loopback addresses and single-label names (no dot) may use plain HTTP.
/// `localhost`, a dotted-quad loopback address, or a single-label name that is not a
/// number (a Docker service name on the compose network) may use plain HTTP. Numeric
/// forms (`167772165`, `0x0a000005`) resolve to arbitrary addresses and are refused.
fn cleartext_allowed(host_port: &str) -> bool {
let host = host_port.rsplit_once(':').map_or(host_port, |(h, _)| h);
host == "localhost" || host.starts_with("127.") || host == "[::1]" || !host.contains('.')
if host == "localhost" {
return true;
}
if let Ok(address) = host.parse::<std::net::Ipv4Addr>() {
return address.is_loopback();
}
!host.is_empty()
&& !host.contains('.')
&& host.chars().any(|c| c.is_ascii_alphabetic())
&& !host.starts_with("0x")
}
fn seconds(
@@ -223,6 +234,10 @@ mod tests {
for bad in [
"http://abc.supabase.co",
"http://10.0.0.5:8000",
"http://127.evil.example",
"http://167772165:8000",
"http://0x0a000005",
"http://127.0.0.1.example",
"ftp://x",
"http://",
] {