fep

FEP-fe34: Origin-based security model

Summary

Developing a comprehensive ActivityPub security framework based on the concept of web origin.

Rationale

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.

Requirements

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.

Assumptions

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.

Origin

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.

Comparing origins

  1. Let uri-scheme be the scheme component of the URI, converted to lowercase.
  2. Let uri-host be the host component of the URI, converted to lowercase.
  3. If there is no port component of the URI, let uri-port be the default port for the protocol given by uri-scheme. Otherwise, let uri-port be the port component of the URI.
  4. Return the triple (uri-scheme, uri-host, uri-port).

Origins are the same if they have identical schemes, hosts, and ports.

Authentication

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.

Fetching from an origin

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.

Signatures

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 publicKeyPem and publicKeyMultibase properties as a public key. Protections against attacks of that kind are not described in this document.

Embedding

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

Authorization is the process of verifying permission to create, read, update or delete an object.

Ownership

Ownership is indicated by a property of an ActivityPub object. The name of this property differs depending on the object class:

In some cases ownership might be implicit. Examples:

An anonymous object has the same owner as its wrapping object.

Applications can use the following algorithm to determine the owner of an object:

  1. Run the duck typing algorithm specified in FEP-2277.
  2. If the type is Link, return error.
  3. If the type is neither Object nor Collection, and the object has an attributedTo property, return error.
  4. If the type is Actor, return the value of the id property.
  5. If the type is VerificationMethod, return the value of the controller property.
  6. If the type is PublicKey, return the value of the owner property.
  7. If the type is Activity, return the value of the actor property.
  8. If the type is 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, actor and attributedTo properties 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.

Comparing owners

Owners are the same if their identifiers are identical after conversion of their schemes and hosts to lowercase.

Create, update and delete

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:

Servers MUST ensure that activities published by a client do not represent unauthorized actions. This includes activities embedded within other activities and objects.

Access control

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.

Ownership transfer

When ownership changes, the new owner ID MUST have the same origin as the old owner ID.

Reciprocal claims

Claims are considered reciprocal when one object specifies a claim that is accompanied by a reverse claim specified in another object.

Examples:

Cross-origin relationships

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:

References

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.