A remote actor is believed only from its own origin
S1 and S2 of the roadmap. RemoteActorService: - FetchObject accepts a document only when its id is the address it was served from; a same-origin document naming another address is asked for at that address once (how GoToSocial serves its key URIs), anything else is dropped; - GetActorByKeyId accepts a key only when the actor lists it, its owner is the actor and it lives on the actor's origin, whether the keyId points at the actor or at a key document; - a refetch for a key or an actor happens at most once per five minutes, so a bad signature cannot make us hammer a host; - the cache row is written by one atomic upsert on ActorURI; - every fetch is signed by the instance actor, never by the persona that happened to receive the activity. The inbox refuses an activity whose id is not on its actor's origin, and an Undo of someone else's activity; a Create's object, an Update and a Delete must be on the actor's origin too, and a cross-origin object is refetched from its own origin before it is trusted. Tests: a fake peer on two origins serves forged actors, foreign-owned keys, cross-origin key documents, aliases and a GoToSocial-style key address (integration, PRIVAPUB_TEST_MONGOD=1). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012CzABvBkbcFqoHdmi8b9WB
This commit is contained in:
1 parent
ccc3597699
commit
a060204dd6
9 files changed
+593
-81
No files matched your search
@@ -0,0 +1,24 @@
|
||||
namespace PrivaPub.Federation.Objects
|
||||
{
|
||||
public static class Origin
|
||||
{
|
||||
public static string Of(string uri) =>
|
||||
Uri.TryCreate(uri, UriKind.Absolute, out var parsed) ? Of(parsed) : default;
|
||||
|
||||
public static string Of(Uri uri) =>
|
||||
uri is { IsAbsoluteUri: true } && (uri.Scheme == Uri.UriSchemeHttps || uri.Scheme == Uri.UriSchemeHttp)
|
||||
? $"{uri.Scheme}://{uri.IdnHost.ToLowerInvariant()}:{uri.Port}"
|
||||
: default;
|
||||
|
||||
public static bool Same(string first, string second)
|
||||
{
|
||||
var origin = Of(first);
|
||||
return origin != default && origin == Of(second);
|
||||
}
|
||||
|
||||
public static bool IsDocumentAt(string id, Uri location) =>
|
||||
Uri.TryCreate(id, UriKind.Absolute, out var parsed)
|
||||
&& location is { IsAbsoluteUri: true }
|
||||
&& Uri.Compare(parsed, location, UriComponents.HttpRequestUrl, UriFormat.UriEscaped, StringComparison.Ordinal) == 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user