You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3df6179
Browse filesBrowse the repository at this point in the historyBrowse files
fence(auth): host-binding side door + access-checker community fence
Two adversarially-proven multi-tenant fences for the auth lane on the frozen Lane 0 SHA:
1. NIP-98 verifier: drop loopback aliasing unconditionally.
normalize_url() collapsed localhost / ::1 -> 127.0.0.1 — a testing convenience that
becomes a row-zero side door under multi-tenant. The u-tag host is the community
binding (docs/multi-tenant-conformance.md, NIP-98 row); collapsing the three would
let an event signed for localhost pass against a 127.0.0.1-resolved community (or
vice versa). Inverted the localhost test to bite the new strict rule: signed-for-one
vs expected-other now REJECTS, identity still passes. Adversarial: re-introduced
the aliasing -> test goes red -> restored.
2. ChannelAccessChecker: thread &TenantContext through every method.
Frozen 0001 has channels PK (community_id, id), so the same UUID legitimately
co-exists across communities. A bare WHERE id = implementation would be a
cross-community existence oracle. Mirror of buzz-db rule 4a.1 on the auth side.
MockAccessChecker keyed on (community, pubkey, channel_id); new test
access_does_not_cross_communities bites the bare-id direction. Adversarial:
dropped the community filter from the mock -> test goes red -> restored.
No external impl of ChannelAccessChecker in-tree (DB uses a separate free function
under Mari's lane), so the trait signature change is contained.
cargo test -p buzz-auth: 45 passed / 0 failed.
Lane: auth (buzz-auth). Base: e349d76 (frozen Lane 0).
Co-authored-by: Tyler Longwell <[email protected]>
Signed-off-by: Tyler Longwell <[email protected]>
Copy file name to clipboardExpand all lines: crates/buzz-auth/src/nip98.rs
+30-8Lines changed: 30 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -134,17 +134,19 @@ pub fn verify_nip98_event(
134
134
///
135
135
/// - Lowercases scheme and host (already done by the `url` crate).
136
136
/// - Strips trailing slash from path.
137
-
/// - Treats `localhost` and `::1` as equivalent to `127.0.0.1`.
137
+
///
138
+
/// **No loopback aliasing.** `localhost`, `::1`, and `127.0.0.1` are three
139
+
/// distinct hosts here. Under multi-tenant the `u`-tag host is the row-zero
140
+
/// community binding (`docs/multi-tenant-conformance.md`, NIP-98 row): if
141
+
/// `verify_nip98_event` collapses them, an event signed for `localhost`
142
+
/// would pass against a `127.0.0.1`-resolved community (or vice versa) —
143
+
/// a host-binding side door. Tests reconstruct `expected_url` from their
144
+
/// own bound host, the same shape production does.
138
145
fnnormalize_url(raw:&str) -> String{
139
146
letmut parsed = matchUrl::parse(raw){
140
147
Ok(u) => u,
141
148
Err(_) => return raw.to_lowercase(),
142
149
};
143
-
ifletSome(host) = parsed.host_str(){
144
-
if host == "localhost" || host == "::1"{
145
-
let _ = parsed.set_host(Some("127.0.0.1"));
146
-
}
147
-
}
148
150
let path = parsed.path().trim_end_matches('/').to_string();
149
151
parsed.set_path(&path);
150
152
parsed.to_string()
@@ -284,12 +286,32 @@ mod tests {
284
286
}
285
287
286
288
#[test]
287
-
fnlocalhost_normalized(){
289
+
fnloopback_aliases_are_distinct_hosts(){
290
+
// Under multi-tenant, the `u`-tag host is the row-zero community
291
+
// binding. An event signed for `localhost` MUST NOT pass against an
292
+
// expected URL on `127.0.0.1` (or `::1`) — collapsing the three would
293
+
// be a host-check side door. Production reconstructs `expected_url`
294
+
// from the community-bound host; tests do the same.
288
295
let keys = Keys::generate();
289
296
let localhost_url = "http://localhost:3000/api/tokens";
290
297
let loopback_url = "http://127.0.0.1:3000/api/tokens";
291
298
let json = make_nip98_event(&keys, localhost_url,TEST_METHOD,None,None);
292
299
let result = verify_nip98_event(&json, loopback_url,TEST_METHOD,None);
293
-
assert!(result.is_ok());
300
+
assert!(
301
+
matches!(result,Err(AuthError::Nip98Invalid(_))),
302
+
"localhost u-tag must NOT match a 127.0.0.1 expected_url; got {result:?}"
303
+
);
304
+
305
+
// Symmetric: signed-for-127.0.0.1 against expected localhost — same answer.
306
+
let json2 = make_nip98_event(&keys, loopback_url,TEST_METHOD,None,None);
307
+
let result2 = verify_nip98_event(&json2, localhost_url,TEST_METHOD,None);
0 commit comments