Developing a comprehensive ActivityPub security framework based on the concept of web origin.
ActivityPub standard does not specify authentication and authorization mechanisms. However, in some cases it hints at the importance of an object’s origin:
3. Objects
… Servers SHOULD validate the content they receive to avoid content spoofing attacks. (A server should do something at least as robust as checking that the object appears as received at its origin, but mechanisms such as checking signatures would be better if available).
7.3 Update Activity
… The receiving server MUST take care to be sure that the Update is authorized to modify its object. At minimum, this may be done by ensuring that the Update and its object are of same origin.
Implementations often rely on origin and ownership checks for determining the validity of activities and objects, but exact requirements are not documented and can be easily overlooked, leading to vulnerabilities such as GHSA-3fjr-858r-92rw.
This proposal attempts to formalize existing practices and provide guidance for implementers.
The key words “MUST”, “MUST NOT”, “REQUIRED”, “SHALL”, “SHALL NOT”, “SHOULD”, “SHOULD NOT”, “RECOMMENDED”, “MAY”, and “OPTIONAL” in this document are to be interpreted as described in RFC-2119.
The origin-based security model is designed for use in a network where a server is responsible for enforcing security boundaries between the hosted actors. This assumption is based on the general consensus that served objects can be trusted and that their ownership doesn’t require verification. Servers that publish objects without validation are not supported.
Object identifiers are assumed to be HTTP(S) URIs. The model can also be used with other kinds of identifiers, but that is not covered in this document.
Object identifiers are grouped together into protection domains called “origins”. This concept is similar to the “web origin” concept described in RFC-6454, and origins of object IDs are computed by the same algorithm.
The same-origin policy determines when a relationship between objects can be trusted. Different origins are considered potentially hostile and are isolated from each other to varying degrees. Actors sharing an origin are assumed to trust each other because the server enforces boundaries between them.
uri-scheme be the scheme component of the URI, converted to lowercase.uri-host be the host component of the URI, converted to lowercase.uri-port be the default port for the protocol given by uri-scheme. Otherwise, let uri-port be the port component of the URI.(uri-scheme, uri-host, uri-port).Origins are the same if they have identical schemes, hosts, and ports.
Authentication is the process of verifying the origin of an ActivityPub object. It is performed in order to protect an application from spoofing attacks.
Objects can be authenticated using the following methods:
If an object can’t be authenticated, it MUST be discarded.
Fetching from an origin is the primary authentication method, and other authentication methods described in this document depend on it. Consumers SHOULD attempt to fetch the object from its origin if other authentication methods are not available.
Non-anonymous ActivityPub objects can be authenticated by making an HTTP GET request with object’s ID as the target.
The last URI in the chain of redirects is object’s location. The location SHOULD match the ID of the retrieved object. If object’s location and ID are different, they MUST have the same origin.
If the object is protected, the server MAY require an HTTP signature.
Servers MUST validate all objects received from clients. Any activity representing an action that actor is not authorized to perform MUST be rejected. Special attention needs to be paid to media uploads, because malicious actors might attempt to bypass the validation by uploading ActivityPub documents as media. If the server allows clients to upload arbitrary files, it MUST serve media from a different origin (e.g. from a different subdomain).
As an additional protection in cases where an attacker was able to bypass the validation, consumers MUST verify that the response to a GET request contains the Content-Type header with the application/ld+json; profile="https://www.w3.org/ns/activitystreams" or application/activity+json media type (see GHSA-jhrq-qvrm-qr36 for more information).
Servers MUST NOT serve objects until they are validated.
Signature-based authentication can be used when:
The ID of the public key (or the verification method) MUST have the same origin as the object’s ID.
Servers MUST NOT share secret keys with clients.
Servers MUST NOT allow clients to create or update objects representing public keys, including such objects embedded within actors and other objects. Public keys can be identified by their properties publicKeyPem and publicKeyMultibase. Embedded public keys with a different origin are permitted.
In order to minimize damage in the event of a key compromise or insufficient validation, consumers MUST verify that the signing key has the same owner as the signed object. Consumers MUST also confirm the ownership of the key by verifying a reciprocal claim.
[!WARNING] JSON-LD consumers might be tricked into processing a specially crafted JSON object without
publicKeyPemandpublicKeyMultibaseproperties as a public key. Protections against attacks of that kind are not described in this document.
An embedded object can be trusted if the following conditions are met:
Consumers MUST NOT trust embedded objects that do not satisfy these conditions.
In order to mitigate impersonation risks resulting from consumers not verifying ownership during the authentication, originating servers MUST enforce actor isolation by recursively verifying embedded objects when a client submits an activity. If an embedded object is owned by a different local actor, the server must either authenticate the object or reject the activity.
Embedded non-anonymous objects SHOULD NOT be partial representations. A server that relies on embedding for authentication might save a partial representation of an object to the cache, replacing the full object.
[!NOTE] Partial representations could be marked to prevent caching. Potential methods for achieving this are discussed in the issue https://codeberg.org/silverpill/feps/issues/21.
Authorization is the process of verifying permission to create, read, update or delete an object.
Ownership is indicated by a property of an ActivityPub object. The name of this property differs depending on the object class:
id property.actor property, which describes the actor that performed the activity. This actor is considered to be the owner of the activity.owner and controller properties.attributedTo property, which describes the actor to which the object is attributed. This actor is considered to be the owner of the object.In some cases ownership might be implicit. Examples:
replies collection is owned by the actor to which the post is attributed.An anonymous object has the same owner as its wrapping object.
Applications can use the following algorithm to determine the owner of an object:
Link, return error.Object nor Collection, and the object has an attributedTo property, return error.Actor, return the value of the id property.VerificationMethod, return the value of the controller property.PublicKey, return the value of the owner property.Activity, return the value of the actor property.Object or Collection, return the value of the attributedTo property.The owner of an object MUST be an actor.
Identifier of an object and identifier of its owner MUST have the same origin.
[!WARNING] According to Activity Vocabulary,
actorandattributedToproperties can contain references to multiple actors. These scenarios are not covered by this document and implementers are expected to determine the appropriate authorization procedures on a case-by-case basis.
Owners are the same if their identifiers are identical after conversion of their schemes and hosts to lowercase.
The actor that creates an object MUST be its owner.
The owner of an object is permitted to modify and delete it. This permission might also be specified with reciprocal claims.
If the owner of an activity that modifies or deletes an object doesn’t have a permission to perform the operation, the activity MUST be rejected. If such activity is received from another server and the permission can not be verified, the recipient MAY accept the activity if its actor and the owner of the affected object have the same origin.
Examples:
Update and Delete activities, and objects indicated by their object property are expected to have the same owner.Undo activity and object indicated by its object property are expected to have the same owner.Add and Remove activities, and objects indicated by their target property are expected to have the same owner.Announce and Like activities don’t modify objects indicated by their object property, therefore their owners can be different.Servers MUST ensure that activities published by a client do not represent unauthorized actions. This includes activities embedded within other activities and objects.
The intended audience of an object is specified using the following properties: to, cc, bto, bcc and audience.
An object addressed to https://www.w3.org/ns/activitystreams#Public can be retrieved by anyone. When an object is not addressed to public, the server MUST verify that the GET request contains an HTTP signature created using a key whose owner belongs to the object’s intended audience.
The server MAY require a signature even if the object is public. In that case, the request can be signed with a key owned by a server actor.
Servers that implement proxyUrl endpoint MUST ensure that access to objects is restricted to actors that belong to intended audiences of these objects.
[!NOTE] Some servers always require signed requests in an attempt to limit access to public objects. However, this measure is often ineffective and can be circumvented by using a different domain name to serve the public key.
When ownership changes, the new owner ID MUST have the same origin as the old owner ID.
Claims are considered reciprocal when one object specifies a claim that is accompanied by a reverse claim specified in another object.
Examples:
Relationships between objects with different origins are possible, but they MUST be confirmed with reciprocal claims made by both origins. In that case, the same-origin policy can be bypassed.
Examples:
Move activity if the migrating actor is included in the target actor’s alsoKnownAs.CC0 1.0 Universal (CC0 1.0) Public Domain Dedication
To the extent possible under law, the authors of this Fediverse Enhancement Proposal have waived all copyright and related or neighboring rights to this work.