Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,55 @@ Version 2.4.6

To be released.

### @fedify/fedify

- Fixed `signObject()` and the default activity transformers,
`autoIdAssigner()` and `actorDehydrator()`, dropping the default [FEP-ef61]
portable object verifier of the object they returned a copy of. Their
results now keep the verifier, so their accessors verify portable objects
as the original object's accessors do, and they no longer log
the warning that `clone()` logs when it drops the verifier.
[[#1399], [#1442]]

[FEP-ef61]: https://w3id.org/fep/ef61
[#1399]: https://github.com/fedify-dev/fedify/issues/1399
[#1442]: https://github.com/fedify-dev/fedify/pull/1442

### @fedify/testing

- Fixed `MockFederation.receiveActivity()` dropping the default [FEP-ef61]
portable object verifier of the received activity when it attaches its
document loaders to the activity passed to inbox listeners.
[[#1399], [#1442]]

### @fedify/vocab

- Added a warning when `clone()` drops the default [FEP-ef61] portable object
verifier of a vocabulary object, and documented that `clone()` does not
inherit it. Objects that Fedify parses for you, such as activities that
inboxes receive and the results of `Context.lookupObject()`, have
`Context.verifyPortableObject` as their default, so an existing
application that clones them now logs a warning in the
`["fedify", "vocab", "portable"]` category. A clone without a verifier
does not verify the portable objects embedded in it, and refuses to
dereference portable references. Pass
`verifyPortableObject: ctx.verifyPortableObject` to `clone()` to keep
verifying them, or `verifyPortableObject: undefined` to drop the verifier
deliberately without the warning. The `verifyPortableObject` option of
`clone()` now explicitly accepts `undefined`, so that the opt-out also
type-checks with `exactOptionalPropertyTypes`. [[#1399], [#1442]]

### @fedify/vocab-tools

- Generated `clone()` methods now log a warning in the
`["fedify", "vocab", "portable"]` category when they drop the default
[FEP-ef61] portable object verifier of the source object, i.e., when the
source has one and the call does not pass the `verifyPortableObject`
option. An explicit `verifyPortableObject: undefined` drops it without
the warning. Their API documentation now states that `clone()` does not
inherit the default verifier. Regenerate custom vocabularies to get
the warning. [[#1399], [#1442]]


Version 2.4.5
-------------
Expand Down
14 changes: 14 additions & 0 deletions changes.d/fedify/clone-portable-verifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
links:
'#1399': https://github.com/fedify-dev/fedify/issues/1399
'#1442': https://github.com/fedify-dev/fedify/pull/1442
---
- Fixed `signObject()` and the default activity transformers,
`autoIdAssigner()` and `actorDehydrator()`, dropping the default [FEP-ef61]
portable object verifier of the object they returned a copy of. Their
results now keep the verifier, so their accessors verify portable objects
as the original object's accessors do, and they no longer log
the warning that `clone()` logs when it drops the verifier.
[[#1399], [#1442]]

[FEP-ef61]: https://w3id.org/fep/ef61
11 changes: 11 additions & 0 deletions changes.d/testing/clone-portable-verifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
links:
'#1399': https://github.com/fedify-dev/fedify/issues/1399
'#1442': https://github.com/fedify-dev/fedify/pull/1442
---
- Fixed `MockFederation.receiveActivity()` dropping the default [FEP-ef61]
portable object verifier of the received activity when it attaches its
document loaders to the activity passed to inbox listeners.
[[#1399], [#1442]]

[FEP-ef61]: https://w3id.org/fep/ef61
15 changes: 15 additions & 0 deletions changes.d/vocab-tools/clone-portable-verifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
---
links:
'#1399': https://github.com/fedify-dev/fedify/issues/1399
'#1442': https://github.com/fedify-dev/fedify/pull/1442
---
- Generated `clone()` methods now log a warning in the
`["fedify", "vocab", "portable"]` category when they drop the default
[FEP-ef61] portable object verifier of the source object, i.e., when the
source has one and the call does not pass the `verifyPortableObject`
option. An explicit `verifyPortableObject: undefined` drops it without
the warning. Their API documentation now states that `clone()` does not
inherit the default verifier. Regenerate custom vocabularies to get
the warning. [[#1399], [#1442]]

[FEP-ef61]: https://w3id.org/fep/ef61
21 changes: 21 additions & 0 deletions changes.d/vocab/clone-portable-verifier.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
links:
'#1399': https://github.com/fedify-dev/fedify/issues/1399
'#1442': https://github.com/fedify-dev/fedify/pull/1442
---
- Added a warning when `clone()` drops the default [FEP-ef61] portable object
verifier of a vocabulary object, and documented that `clone()` does not
inherit it. Objects that Fedify parses for you, such as activities that
inboxes receive and the results of `Context.lookupObject()`, have
`Context.verifyPortableObject` as their default, so an existing
application that clones them now logs a warning in the
`["fedify", "vocab", "portable"]` category. A clone without a verifier
does not verify the portable objects embedded in it, and refuses to
dereference portable references. Pass
`verifyPortableObject: ctx.verifyPortableObject` to `clone()` to keep
verifying them, or `verifyPortableObject: undefined` to drop the verifier
deliberately without the warning. The `verifyPortableObject` option of
`clone()` now explicitly accepts `undefined`, so that the opt-out also
type-checks with `exactOptionalPropertyTypes`. [[#1399], [#1442]]

[FEP-ef61]: https://w3id.org/fep/ef61
11 changes: 11 additions & 0 deletions docs/manual/log.md
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,17 @@ related to looking up ActivityPub objects. When you are curious about the
lookup process, you can check the log messages in this category with the
`"debug"` level.

### `["fedify", "vocab", "portable"]`

*This category is available since Fedify 2.4.6.*

The `["fedify", "vocab", "portable"]` category is used for logging warnings
about [FEP-ef61 portable objects](./vocab.md#fep-ef61-portable-objects) in
the vocabulary API. For example, `clone()` logs a warning with the
`"warning"` level when it drops the default portable object verifier of
an object; see the [*Default verifiers* section](./vocab.md#default-verifiers)
of the *Vocabulary* chapter.

### `["fedify", "webfinger", "server"]`

*This category is available since Fedify 0.13.0.*
Expand Down
33 changes: 31 additions & 2 deletions docs/manual/vocab.md
Original file line number Diff line number Diff line change
Expand Up @@ -545,8 +545,34 @@ have `~Context.verifyPortableObject` as their default: activities that inboxes
receive, including queued ones, objects that `~Context.lookupObject()` returns,
and the activities passed to the `onOutboxError` callback. So
`create.getObject()` in an inbox listener verifies portable objects even
without options. A clone does not inherit the default; pass
`verifyPortableObject` to `clone()` if you need it.
without options.

A [clone](#immutability) does not inherit the default, though. Without
a verifier, the clone's accessors no longer verify embedded portable objects,
and refuse to dereference portable references. So pass `verifyPortableObject`
to `clone()` if you need it:

~~~~ typescript twoslash
import type { Context } from "@fedify/fedify";
import type { Create } from "@fedify/vocab";
declare const ctx: Context<void>;
declare const create: Create;
// ---cut-before---
const copy = create.clone(
{ summary: "A copy" },
// Keeps verifying portable objects that the copy's accessors dereference:
{ verifyPortableObject: ctx.verifyPortableObject },
);
~~~~

Cloning an object that has a default verifier without
the `verifyPortableObject` option logs a warning in the
[`["fedify", "vocab", "portable"]`](./log.md#fedify-vocab-portable) category.
Pass `verifyPortableObject: undefined` to drop the default deliberately
without the warning. Either way, nested objects that the clone shares with
the source keep their own defaults. To get a separate copy instead, serialize
the object and re-parse it with `fromJsonLd()`, passing the verifier again,
as the [*Immutability* section](#immutability) shows.

#### Compatible identifiers

Expand Down Expand Up @@ -950,6 +976,9 @@ return the shared instance. A parsed source can return a fresh object instead:
if its cached JSON-LD contains an embedded object with its own `@context`, the
accessor re-parses that object on each call. Hydrating that returned object
does not update the nested instance stored in the source or clone.
The clone also does not inherit the source's document loaders or default
portable object verifier; see the [*Default verifiers*
section](#default-verifiers).

If you need to preserve the received representation while resolving properties,
keep the received JSON-LD document. To resolve properties in a separate object
Expand Down
2 changes: 1 addition & 1 deletion mise.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pnpm = "10.28.0"
# check-each, test-each, check-versions) so they run identically on Windows,
# macOS, and Linux without Bash.
"aqua:nushell/nushell" = "0.114.0"
"github:dahlia/sacho" = "0.3.2"
"github:dahlia/sacho" = "0.4.0"

# Dependency providers <https://mise.jdx.dev/dev-tools/deps.html>
#
Expand Down
7 changes: 1 addition & 6 deletions packages/astro/compat/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,7 @@ async function testCompatibility(testCase: CompatibilityCase): Promise<void> {
astro: testCase.astro,
},
pnpm: {
overrides: {
...Object.fromEntries(tarballs),
// Version 1.2.0 requires @emnapi/* 2.0 prereleases, while its
// consumers still provide @emnapi/* 1.x.
"@napi-rs/wasm-runtime@^1.1.6": "1.1.6",
},
overrides: Object.fromEntries(tarballs),
},
},
null,
Expand Down
9 changes: 8 additions & 1 deletion packages/fedify/src/compat/transformers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { Activity } from "@fedify/vocab";
import { getLogger } from "@logtape/logtape";
import type { Context } from "../federation/context.ts";
import { getDefaultPortableObjectVerifier } from "../utils/portable-verifier.ts";
import type { ActivityTransformer } from "./types.ts";

const logger = getLogger(["fedify", "compat", "transformers"]);
Expand Down Expand Up @@ -38,7 +39,10 @@ export function autoIdAssigner<TContextData>(
"set the id for the activity.",
{ id: id.href },
);
return activity.clone({ id });
return activity.clone({ id }, {
// A clone does not inherit the default verifier, so keep it:
verifyPortableObject: getDefaultPortableObjectVerifier(activity),
});
}

/**
Expand Down Expand Up @@ -93,6 +97,9 @@ export function actorDehydrator<TContextData>(
if (activity.actorIds.length < 1) return activity;
return activity.clone({
actors: activity.actorIds,
}, {
// A clone does not inherit the default verifier, so keep it:
verifyPortableObject: getDefaultPortableObjectVerifier(activity),
});
}

Expand Down
13 changes: 10 additions & 3 deletions packages/fedify/src/sig/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ import type {
PortableActorKeyResolution,
PortableGatewayKeyResolution,
} from "./portable-key.ts";
import { getDefaultPortableObjectVerifier } from "../utils/portable-verifier.ts";

/** Classifies decoding failures without hiding unexpected loader errors. */
function classifyKeyJsonLdError(
Expand Down Expand Up @@ -1300,7 +1301,9 @@ async function resolveFetchedKey<T extends CryptographicKey | Multikey>(
// fetched from is then the only id it has, and the ownership check below
// needs an id to look for in the owner's document.
key = object.id == null
? (object as CryptographicKey).clone({ id: cacheKey }) as T
? (object as CryptographicKey).clone({ id: cacheKey }, {
verifyPortableObject: getDefaultPortableObjectVerifier(object),
}) as T
: object;
} else if (isActor(object)) {
// A host may only speak for actor ids on its own origin. Without this
Expand Down Expand Up @@ -1423,8 +1426,12 @@ async function resolveFetchedKey<T extends CryptographicKey | Multikey>(
// own, so that one fetch settled the question. Record the answer on the
// key, so that callers—and the key cache—never have to take it up again.
key = key instanceof CryptographicKey
? key.clone({ owner: ownerDocument.id! }) as T
: (key as Multikey).clone({ controller: ownerDocument.id! }) as T;
? key.clone({ owner: ownerDocument.id! }, {
verifyPortableObject: getDefaultPortableObjectVerifier(key),
}) as T
: (key as Multikey).clone({ controller: ownerDocument.id! }, {
verifyPortableObject: getDefaultPortableObjectVerifier(key),
}) as T;
} else if (
claimedOwnerId != null &&
claimedOwnerId.href !== ownerDocument?.id?.href
Expand Down
7 changes: 6 additions & 1 deletion packages/fedify/src/sig/owner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
isPortableUri,
isSamePublicKey as isSameKeyMaterial,
} from "./portable-key-id.ts";
import { getDefaultPortableObjectVerifier } from "../utils/portable-verifier.ts";
export { exportJwk, generateCryptoKeyPair, importJwk } from "./key.ts";

const logger = getLogger(["fedify", "sig", "owner"]);
Expand Down Expand Up @@ -338,7 +339,11 @@ export async function getKeyOwner(
// key at all.
if (object.id != null && object.id.href !== keyId.href) return null;
return await verifyKeyOwnership(
object.id == null ? object.clone({ id: keyId }) : object,
object.id == null
? object.clone({ id: keyId }, {
verifyPortableObject: getDefaultPortableObjectVerifier(object),
})
: object,
fetchOptions,
);
}
Expand Down
9 changes: 8 additions & 1 deletion packages/fedify/src/sig/proof.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import {
} from "./key.ts";
import { getNormalizationContextLoader } from "./ld.ts";
import { getPortableDid, isPortableId } from "./portable-key-id.ts";
import { getDefaultPortableObjectVerifier } from "../utils/portable-verifier.ts";

/**
* Known Object Integrity Proof `cryptosuite` values, used to keep
Expand Down Expand Up @@ -263,7 +264,10 @@ async function createProofInternal(
if (privateKey.algorithm.name !== "Ed25519") {
throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
}
const objectWithoutProofs = object.clone({ proofs: [] });
// Only serialized below, so it needs no portable object verifier:
const objectWithoutProofs = object.clone({ proofs: [] }, {
verifyPortableObject: undefined,
});
let compactMsg = await objectWithoutProofs.toJsonLd({
format: "compact",
contextLoader,
Expand Down Expand Up @@ -427,6 +431,9 @@ export async function signObject<T extends Object>(
}
const signed = object.clone({
proofs: [...existingProofs, proof],
}, {
// A clone does not inherit the default verifier, so keep it:
verifyPortableObject: getDefaultPortableObjectVerifier(object),
}) as T;
if (securedDocument != null) {
// Retain the secured JSON document so that embedding this object in
Expand Down
Loading
Loading