~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Someone not signed in sees only a group's handle, and is asked to sign in

Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:console/signed-out
crates/group-host/src/blobs.rs+11−16
@@ -6,15 +6,13 @@
//!
//! An image of an account's is also served for a page to draw, at
//! `/img/{did}/{cid}`, to whoever may see a record that holds it: anyone,
//! for a record in its public repo or in the profile of a group listed on
//! the network; for one in a space, whoever that space lets read, as the
//! console's session says. Served as an image and nothing more, and kept
//! for good, as a CID names its bytes.
//! for a record in its public repo; for one in a space, whoever signed in
//! to the console that space lets read, a group's listed profile being for
//! anyone signed in. Served as an image and nothing more, and kept for
//! good, as a CID names its bytes.
use crate::Host;
use crate::authority::Access;
use crate::group::meta_space;
use crate::rbac::NS;
use crate::store::{Blob, Store};
use crate::time::now_millis;
use crate::xrpc::XrpcError;
@@ -181,7 +179,9 @@ impl Store {
impl Host {
/// Whether `who` (none, for someone not signed in) may see `did`'s blob
/// `cid`: a record holding it is one they may read.
/// `cid`: a record holding it is one they may read. Someone not signed
/// in sees only what the public repo holds, as of a group they learn
/// no more than its DID and handle.
pub fn may_see(&self, did: &str, cid: &Cid, who: Option<&str>) -> Result<bool> {
if self.store.deactivation(did)?.is_some() {
return Ok(false);
@@ -189,17 +189,12 @@ impl Host {
if self.store.held_publicly(did, cid)? {
return Ok(true);
}
// A listed group's profile is anyone's to see, as listGroups shows it.
let listed = self
.store
.record(did, &format!("{NS}.declaration"), "self")?
.is_some();
let Some(who) = who else {
return Ok(false);
};
for space in self.store.holding_spaces(did, cid)? {
if listed && space == meta_space(did) {
return Ok(true);
}
let hosted = self.store.space(&space)?;
let may = hosted.map(|h| self.may(&space, &h, who, Access::Read));
let may = hosted.map(|h| self.may(&space, &h, Some(who), Access::Read));
if may.transpose()?.unwrap_or(false) {
return Ok(true);
}
crates/group-host/src/group_api.rs+38−28
@@ -186,9 +186,16 @@ fn objects(field: &str, items: impl IntoIterator<Item = impl Into<String>>) -> V
.collect()
}
/// A group as someone not signed in sees it: what anyone can learn of it
/// already, its DID and handle.
fn signed_out(did: &str, handle: String) -> Value {
json!({"did": did, "handle": handle})
}
/// One group in full, as the caller may see it: what its meta space
/// holds for whoever may read it, the caller's own standing, and for a
/// member, its members, roles and spaces.
/// member, its members, roles and spaces. To no one signed in, only its
/// DID and handle, whatever its access record says.
pub async fn get_group(
State(host): State<Arc<Host>>,
Query(p): Query<Params>,
@@ -197,6 +204,9 @@ pub async fn get_group(
let group = param(&p, "group")?;
let handle = group_of(&host, group)?;
let me = caller(&host, &headers, &format!("{NS}.getGroup")).await?;
let Some(me) = me else {
return Ok(Json(json!({ "group": signed_out(group, handle) })));
};
// Switched off: nothing in it is read, by members either. Still
// answered, so a steward can find the switch.
if host.deactivation(group)?.is_some() {
@@ -209,17 +219,13 @@ pub async fn get_group(
.map_err(XrpcError::internal)
};
let (meta, members) = (meta_space(group), members_space(group));
let roles = match &me {
Some(me) => host.roles(group, me).map_err(XrpcError::internal)?,
None => Vec::new(),
};
let me_or = me.as_deref().unwrap_or_default();
let roles = host.roles(group, &me).map_err(XrpcError::internal)?;
let reads = |space: &str| -> Result<bool, XrpcError> {
let access = record(space, "access", "self")?;
Ok(access.is_some_and(|a| Access::of(&a, space).can_read(&roles, me_or)))
Ok(access.is_some_and(|a| Access::of(&a, space).can_read(&roles, &me)))
};
let reads_meta = reads(&meta)?;
let reads_members = me.is_some() && reads(&members)?;
let reads_members = reads(&members)?;
let permissions = record(&members, "permissions", "self")?.unwrap_or_default();
let granted = grants(&permissions);
let actions = actions_for(&granted, &roles);
@@ -231,23 +237,21 @@ pub async fn get_group(
}
view["rules"] = json!(rules(&host, group)?);
}
if let Some(me) = &me {
let member = !roles.is_empty();
let mut viewer = json!({
"member": member,
"roles": objects("role", roles.clone()),
"actions": actions,
});
if member {
viewer["accepted"] = json!(accepted(&host, &members, me).map_err(XrpcError::internal)?);
}
// Their own request, while it waits.
let asked = host.store.asked(group, me).map_err(XrpcError::internal)?;
if let Some(request) = asked.filter(|_| !member) {
viewer["request"] = crate::group_join::request_view(&request);
}
view["viewer"] = viewer;
let member = !roles.is_empty();
let mut viewer = json!({
"member": member,
"roles": objects("role", roles.clone()),
"actions": actions,
});
if member {
viewer["accepted"] = json!(accepted(&host, &members, &me).map_err(XrpcError::internal)?);
}
// Their own request, while it waits.
let asked = host.store.asked(group, &me).map_err(XrpcError::internal)?;
if let Some(request) = asked.filter(|_| !member) {
viewer["request"] = crate::group_join::request_view(&request);
}
view["viewer"] = viewer;
let mut out = json!({ "group": view });
if !reads_members {
return Ok(Json(out));
@@ -308,7 +312,7 @@ pub async fn get_group(
let access = host
.group_record(group, uri, &format!("{NS}.access"), "self")
.map_err(XrpcError::internal)?;
if let Some(access) = access.filter(|a| Access::of(a, uri).can_read(&roles, me_or)) {
if let Some(access) = access.filter(|a| Access::of(a, uri).can_read(&roles, &me)) {
for key in ["public", "grants", "people", "writableBy"] {
if let Some(v) = access.get(key) {
space[key] = v.clone();
@@ -347,9 +351,11 @@ fn accepted(host: &Host, members: &str, did: &str) -> anyhow::Result<bool> {
Ok(writers.iter().any(|w| w.did == did && w.data != empty))
}
/// Every group here: its handle and spaces, and for one whose meta anyone
/// may read, its profile and rules. Unauthenticated.
pub async fn list_groups(State(host): State<Arc<Host>>) -> Answer {
/// Every group here: to someone signed in, its handle and spaces, and for
/// one whose meta anyone signed in may read, its profile and rules; to no
/// one signed in, each one's DID and handle alone.
pub async fn list_groups(State(host): State<Arc<Host>>, headers: HeaderMap) -> Answer {
let me = caller(&host, &headers, &format!("{NS}.listGroups")).await?;
let mut groups = Vec::new();
let mut cursor: Option<String> = None;
loop {
@@ -361,6 +367,10 @@ pub async fn list_groups(State(host): State<Arc<Host>>) -> Answer {
let Ok(handle) = group_of(&host, did) else {
continue;
};
if me.is_none() {
groups.push(signed_out(did, handle));
continue;
}
let mut view = base(&host, did, &handle)?;
if host.deactivation(did)?.is_some() {
view["deactivated"] = json!(true);
crates/group-host/src/index_api.rs+7−9
@@ -1,12 +1,12 @@
//! The space index, served: what is in one of a group's spaces, and the
//! pictures and files there, for whoever its access record lets read the
//! space, asked on every call. The index holds copies; it never decides
//! who sees them.
//! space, signed in, asked on every call. The index holds copies; it
//! never decides who sees them.
use crate::Host;
use crate::api::{Params, invalid, page, param};
use crate::authority::Access::Write;
use crate::group_api::{caller, group_of};
use crate::group_api::{group_of, signed_in};
use crate::rbac::{Access, NS};
use crate::time::iso;
use crate::xrpc::XrpcError;
@@ -42,7 +42,8 @@ async fn readable(
let space = param(p, "space")?;
group_of(host, group).map_err(|_| not_found("unknown group"))?;
host.active(group).map_err(|_| not_found("unknown group"))?;
let me = caller(host, headers, &format!("{NS}.{lxm}")).await?;
// Someone not signed in reads no space, a public one included.
let me = signed_in(host, headers, &format!("{NS}.{lxm}")).await?;
let named = SpaceRef::parse(space).ok().filter(|s| s.authority == group);
let access = match named {
Some(_) => host
@@ -51,11 +52,8 @@ async fn readable(
None => None,
};
let access = access.ok_or_else(|| not_found("not one of this group's spaces"))?;
let roles = match &me {
Some(me) => host.roles(group, me).map_err(XrpcError::internal)?,
None => Vec::new(),
};
if !Access::of(&access, space).can_read(&roles, me.as_deref().unwrap_or_default()) {
let roles = host.roles(group, &me).map_err(XrpcError::internal)?;
if !Access::of(&access, space).can_read(&roles, &me) {
return Err(XrpcError::new(
StatusCode::UNAUTHORIZED,
"NotAuthorized",
crates/group-host/tests/group_config.rs+6−4
@@ -482,13 +482,15 @@ async fn shows_an_image_to_whoever_may_see_a_record_that_holds_it() {
let (h, did, [alice, bob, carol]) = group().await;
let cid = |b: &Json| b["ref"]["$link"].as_str().unwrap().to_string();
// The avatar of a group listed on the network: anyone's to see, as an
// image and nothing more, kept for good.
// The avatar of a group listed on the network: anyone's to see who is
// signed in, as an image and nothing more, kept for good; no one's who
// is not.
let (_, up) = upload(&h, &alice, &did, b"face".to_vec(), "image/png").await;
let avatar = up["blob"].clone();
let body = json!({"group": did, "displayName": "Riders", "avatar": avatar});
assert_eq!(call(&h, &alice, "updateProfile", body).await.0, 200);
let (status, headers, bytes) = image(&h, &did, &cid(&avatar), None).await;
assert_eq!(image(&h, &did, &cid(&avatar), None).await.0, 404);
let (status, headers, bytes) = image(&h, &did, &cid(&avatar), Some(&carol)).await;
assert_eq!((status, bytes.as_slice()), (200, &b"face"[..]));
assert_eq!(headers["content-type"], "image/png");
assert_eq!(headers["x-content-type-options"], "nosniff");
@@ -502,7 +504,7 @@ async fn shows_an_image_to_whoever_may_see_a_record_that_holds_it() {
);
// Unlisted, its profile is its readers' alone: a member's, not a
// stranger's, nor anyone's not signed in.
// stranger's.
let meta = meta_space(&did);
let hide = json!({"group": did, "space": meta, "access": {"grants": [{"role": "member", "scopes": ["space:*?action=read"]}]}});
assert_eq!(call(&h, &alice, "updateSpace", hide).await.0, 200);
crates/group-host/tests/group_handle.rs+2−1
@@ -174,7 +174,8 @@ async fn takes_a_domain_that_names_it_and_its_address_back() {
("#identity", json!("riders.test"))
);
// Its address stays.
let (_, shown) = get(&h, &format!("{NS}.getGroup"), &format!("group={did}"), &[]).await;
let lxm = format!("{NS}.getGroup");
let (_, shown) = get(&h, &lxm, &format!("group={did}"), &[auth(&h, &alice, &lxm)]).await;
assert_eq!(
(
shown["group"]["handle"].clone(),
crates/group-host/tests/groups.rs+19−5
@@ -259,10 +259,9 @@ async fn shows_a_group_as_each_viewer_may_see_it() {
json!({"member": false, "roles": [], "actions": []})
);
assert_eq!(theirs.get("members"), None);
// Nobody signed in: the public face alone.
// Nobody signed in: what anyone can learn of it already, and no more.
let anyone = view(&h, &did, None).await;
assert_eq!(anyone["group"]["displayName"], "Riders");
assert_eq!(anyone["group"].get("viewer"), None);
assert_eq!(anyone, json!({"group": {"did": did, "handle": RIDERS}}));
}
fn rule_at(rkey: &str, title: &str, order: Option<i64>, at: &str) -> Write {
@@ -372,7 +371,7 @@ async fn its_access_records_say_who_reads_and_writes_its_spaces() {
#[tokio::test]
async fn lists_every_group_here() {
let h = start(&[], false).await;
let [alice, _, _] = people(&h).await;
let [alice, _, dave] = people(&h).await;
let open = start_group(
&h,
&alice,
@@ -395,7 +394,10 @@ async fn lists_every_group_here() {
.await;
// An account that is no group is not listed.
h.host.create_account("plain.groups.test").await.unwrap();
let (status, listed) = get(&h, &format!("{NS}.listGroups"), "", &[]).await;
// To someone signed in, a member of neither: the profile and rules of
// the one whose meta anyone signed in may read.
let lxm = format!("{NS}.listGroups");
let (status, listed) = get(&h, &lxm, "", &[auth(&h, &dave, &lxm)]).await;
assert_eq!(status, 200);
let groups = listed["groups"].as_array().unwrap();
assert_eq!(groups.len(), 2);
@@ -407,6 +409,18 @@ async fn lists_every_group_here() {
);
assert_eq!(of(&closed).get("displayName"), None);
assert_eq!(of(&closed)["handle"], "hikers.groups.test");
// To no one signed in, each by its DID and handle alone.
let (status, listed) = get(&h, &lxm, "", &[]).await;
assert_eq!(status, 200);
let mut groups = listed["groups"].as_array().unwrap().clone();
groups.sort_by_key(|g| g["handle"].as_str().unwrap().to_string());
assert_eq!(
groups,
[
json!({"did": closed, "handle": "hikers.groups.test"}),
json!({"did": open, "handle": RIDERS}),
]
);
}
#[tokio::test]
crates/group-host/tests/index.rs+43−0
@@ -218,6 +218,49 @@ async fn indexes_a_member_writing_at_another_host() {
assert_eq!(got.status, 401);
}
#[tokio::test]
async fn a_public_space_is_for_anyone_signed_in() {
let h = start(&[], false).await;
let [alice, _, carol] = people(&h).await;
let did = start_group(
&h,
&alice,
json!({"handle": RIDERS, "displayName": "Riders"}),
)
.await;
let lxm = format!("{NS}.createSpace");
let body = json!({"group": did, "type": "fyi.opensocial.board", "skey": "open", "access": {"public": true, "grants": []}});
let (status, made) = post(&h, &lxm, &body, &[auth(&h, &alice, &lxm)]).await;
assert_eq!(status, 200, "{made}");
let space = made["space"].as_str().unwrap();
let picture = h.host.upload_blob(&did, b"a map", "image/png").unwrap();
h.host
.space_write(
&did,
space,
&[create(
"one",
json!({"$type": NOTE, "text": "Open", "map": picture}),
)],
)
.await
.unwrap();
let query = format!("group={did}&space={space}");
// A stranger signed in reads it.
let (status, page) = list(&h, Some(&carol), &query).await;
assert_eq!((status, texts(&page)), (200, vec!["Open".to_string()]));
// No one signed in reads it, nor its files.
let (status, said) = list(&h, None, &query).await;
assert_eq!(
(status, said["error"].as_str().unwrap()),
(401, "AuthMissing")
);
let cid = picture["ref"]["$link"].as_str().unwrap();
let blob = format!("{NS}.getSpaceBlob");
let got = read(&h, &blob, &format!("{query}&repo={did}&cid={cid}"), &[]).await;
assert_eq!(got.error(), (401, "AuthMissing".into()));
}
#[tokio::test]
async fn pages_filters_and_finds_one() {
let h = start(&[], false).await;
crates/group-host/tests/lifecycle.rs+7−1
@@ -153,8 +153,14 @@ async fn a_group_switched_off_is_read_by_nobody() {
let (_, shown) = get(&h, &lxm, &format!("group={did}"), &[auth(&h, &alice, &lxm)]).await;
assert_eq!(shown["group"]["deactivated"], true);
assert_eq!(shown["group"].get("displayName"), None);
let (_, listed) = get(&h, &format!("{NS}.listGroups"), "", &[]).await;
let lxm = format!("{NS}.listGroups");
let (_, listed) = get(&h, &lxm, "", &[auth(&h, &alice, &lxm)]).await;
assert_eq!(listed["groups"][0]["deactivated"], true);
// To no one signed in, as any other: its DID and handle.
let (_, listed) = get(&h, &lxm, "", &[]).await;
assert_eq!(listed["groups"][0].get("deactivated"), None);
let (_, shown) = get(&h, &format!("{NS}.getGroup"), &format!("group={did}"), &[]).await;
assert_eq!(shown["group"].get("deactivated"), None);
// Off twice, or on when on, changes nothing.
assert!(!h.host.deactivate_account(&did, &alice.did, &[]).unwrap());
docs/design/groups.md+17−9
@@ -115,10 +115,15 @@ Details:
## What each person sees, and finding a group
`getGroup` answers anyone and gives more to those allowed more. Everyone
gets the group's DID, handle, address, and the URIs of its two spaces.
Whoever may read `meta` also gets the profile and the rules, in order. A
signed-in caller gets `viewer`: whether they are a member, their roles and
Someone not signed in learns of a group only what anyone can already
learn of it from its DID document: its DID and handle. `getGroup` and
`listGroups` tell them that and nothing more, whatever the group's access
records say, since `public` means anyone signed in.
`getGroup` gives more to those allowed more. Everyone signed in gets the
group's DID, handle, address, and the URIs of its two spaces. Whoever may
read `meta` also gets the profile and the rules, in order. A signed-in
caller gets `viewer`: whether they are a member, their roles and
actions, and for a member whether their own repo in `members` holds
anything yet. Whoever may read `members` gets the members, the roles and
what each may do, and the spaces, with a space's access shown only to
@@ -128,9 +133,11 @@ switched-off group shows only the first part and `deactivated: true`.
A group that wants to be found says so with its declaration, a
`fyi.opensocial.declaration` record in its public repo pointing at
`meta`. The host writes it when `public` is among `meta`'s readers and
removes it when not. `listGroups` lists every group on the host, adding
the profile and rules of those whose `meta` is readable by `public`. A
hidden group still appears with its DID, handle, address and space URIs.
removes it when not. `listGroups` lists every group on the host to
someone signed in, adding the profile and rules of those whose `meta` is
readable by `public`. A hidden group still appears with its DID, handle,
address and space URIs. To someone not signed in, it lists each group by
its DID and handle alone.
`getActorGroups` lists the switched-on groups a person is in that the
caller is in too, with each group's member count, and its display name and
@@ -156,8 +163,9 @@ names that blob in `updateProfile`. An upload no record takes within a
day is swept away, and a blob goes when its last reference does.
The host serves images at `/img/{did}/{cid}` to whoever may see a record
holding them: anyone, for the public repo or for `meta` while the group is
declared; otherwise whoever may read the space, signed in to the console.
holding them: anyone, for the public repo; otherwise whoever may read the
space, signed in to the console, which for `meta` while the group is
declared is anyone signed in.
A switched-off group's images are not served.
`putRule` adds or changes a rule and `deleteRule` removes one. Rules keep
docs/design/signing-in.md+6−0
@@ -40,6 +40,12 @@ is derived from the host's rotation secret, so it needs no storage. The
sign-in asks for `atproto` alone, which proves the account and grants
nothing.
Someone not signed in is shown no group, since the host tells them
nothing of one but its DID and handle ([groups](groups.md#what-each-person-sees-and-finding-a-group)).
The console's home page names the host and asks them to sign in; a
group's page shows its handle and asks the same. Either opens the
sign-in dialog, which comes back to the page it was opened on.
A person types their handle or DID. The host finds their PDS and its
authorization server, pushes the request with PKCE and a fresh DPoP key,
and sends the browser there. On return it exchanges the code, checks the
docs/design/spaces.md+4−3
docs/reference/api.md+4−4
harness/e2e/flows.spec.mjs+44−7
harness/e2e/pages.mjs+11−7
lexicons/fyi/opensocial/defs.json+4−6
lexicons/fyi/opensocial/getGroup.json+1−1
lexicons/fyi/opensocial/listGroups.json+1−1
web/src/lib/organisms/SignInDialog.svelte+13−3
web/src/lib/organisms/SiteFooter.svelte+6−1
web/src/lib/templates/Welcome.sveltenew+16−0
web/src/routes/g/[handle]/+page.svelte+5−0
web/src/routes/+layout.svelte+2−1
web/src/routes/+page.svelte+26−18
web/src/routes/+page.ts+7−5
web/src/app.css+20−0
web/src/tokens.css+14−0
web/static/atmo/anisota.jpgnew+0−0
A binary file, not shown.
web/static/atmo/beacon-bits.jpgnew+0−0
A binary file, not shown.
web/static/atmo/blacksky.jpgnew+0−0
A binary file, not shown.
web/static/atmo/blento.jpgnew+0−0
A binary file, not shown.
web/static/atmo/bluesky.jpgnew+0−0
A binary file, not shown.
web/static/atmo/eurosky.jpgnew+0−0
A binary file, not shown.
web/static/atmo/flashes.jpgnew+0−0
A binary file, not shown.
web/static/atmo/gander.jpgnew+0−0
A binary file, not shown.
web/static/atmo/germ.jpgnew+0−0
A binary file, not shown.
web/static/atmo/leaflet.jpgnew+0−0
A binary file, not shown.
web/static/atmo/northsky.jpgnew+0−0
A binary file, not shown.
web/static/atmo/offprint.jpgnew+0−0
A binary file, not shown.
web/static/atmo/pckt.jpgnew+0−0
A binary file, not shown.
web/static/atmo/plyr.jpgnew+0−0
A binary file, not shown.
web/static/atmo/popfeed.jpgnew+0−0
A binary file, not shown.
web/static/atmo/semble.jpgnew+0−0
A binary file, not shown.
web/static/atmo/skylight.jpgnew+0−0
A binary file, not shown.
web/static/atmo/spark.pngnew+0−0
A binary file, not shown.
web/static/atmo/stream-place.jpgnew+0−0
A binary file, not shown.
web/static/atmo/tangled.jpgnew+0−0
A binary file, not shown.