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:
1 parent
62eb4e5d82
commit
cd2dbb3b79
11 files changed
+124
-31
No files matched your search
@@ -117,21 +117,29 @@ impl Config {
|
||||
}
|
||||
|
||||
/// `http(s)://host[:port]`, no path, no whitespace; a trailing slash is dropped.
|
||||
/// Cleartext `http://` is accepted only where the key cannot leave the machine:
|
||||
/// loopback, or a single-label host (a Docker service name on the compose network).
|
||||
fn parse_url(raw: String) -> Result<String, ConfigError> {
|
||||
let url = raw.trim().trim_end_matches('/').to_owned();
|
||||
let rest = url
|
||||
.strip_prefix("http://")
|
||||
.or_else(|| url.strip_prefix("https://"))
|
||||
.ok_or(ConfigError::Invalid(URL))?;
|
||||
let (secure, rest) = match (url.strip_prefix("https://"), url.strip_prefix("http://")) {
|
||||
(Some(rest), _) => (true, rest),
|
||||
(None, Some(rest)) => (false, rest),
|
||||
(None, None) => return Err(ConfigError::Invalid(URL)),
|
||||
};
|
||||
let host_ok = !rest.is_empty()
|
||||
&& rest
|
||||
.chars()
|
||||
.all(|c| c.is_ascii_alphanumeric() || matches!(c, '.' | '-' | ':' | '_'));
|
||||
if host_ok {
|
||||
Ok(url)
|
||||
} else {
|
||||
Err(ConfigError::Invalid(URL))
|
||||
if !host_ok || (!secure && !cleartext_allowed(rest)) {
|
||||
return Err(ConfigError::Invalid(URL));
|
||||
}
|
||||
Ok(url)
|
||||
}
|
||||
|
||||
/// Loopback addresses and single-label names (no dot) may use plain HTTP.
|
||||
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('.')
|
||||
}
|
||||
|
||||
fn seconds(
|
||||
@@ -201,6 +209,31 @@ mod tests {
|
||||
move |name| map.get(name).cloned()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn cleartext_http_is_limited_to_loopback_and_service_names() {
|
||||
for ok in [
|
||||
"http://127.0.0.1:54321",
|
||||
"http://localhost:54321",
|
||||
"http://supabase_kong_faunosteo:8000",
|
||||
"http://kong",
|
||||
"https://abc.supabase.co",
|
||||
] {
|
||||
assert!(parse_url(ok.to_owned()).is_ok(), "{ok}");
|
||||
}
|
||||
for bad in [
|
||||
"http://abc.supabase.co",
|
||||
"http://10.0.0.5:8000",
|
||||
"ftp://x",
|
||||
"http://",
|
||||
] {
|
||||
assert_eq!(
|
||||
parse_url(bad.to_owned()).err(),
|
||||
Some(ConfigError::Invalid(URL)),
|
||||
"{bad}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn defaults_apply_when_only_the_required_variables_are_set() {
|
||||
let cfg = Config::from_vars(vars(&[
|
||||
|
||||
Reference in new issue
Block a user