@evanp/activitypub-bot 0.42.1 → 0.43.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.markdownlint.json +1 -0
- package/CHANGELOG.md +40 -0
- package/README.md +87 -9
- package/lib/activitypubclient.js +12 -5
- package/lib/index.js +4 -2
- package/package.json +1 -1
package/.markdownlint.json
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,46 @@ and this project adheres to
|
|
|
9
9
|
|
|
10
10
|
## [Unreleased]
|
|
11
11
|
|
|
12
|
+
## [0.43.1] - 2026-04-22
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
- `ActivityPubClient` now falls back from RFC 9421 to draft-cavage-12
|
|
17
|
+
signatures on `400`, `401`, or `403` responses (previously only 401 and
|
|
18
|
+
403), so remote servers that reject RFC 9421 with a 400 — e.g.
|
|
19
|
+
Pleroma-Relay's `"missing signature header"` — now trigger the
|
|
20
|
+
double-knock instead of failing the request.
|
|
21
|
+
- Signature-policy caching is no longer overeager: successful RFC 9421
|
|
22
|
+
requests no longer store a per-origin policy, and only confirmed
|
|
23
|
+
draft-cavage-12 fallbacks are cached. This prevents origins whose
|
|
24
|
+
public endpoints don't actually verify signatures (e.g. public
|
|
25
|
+
actor fetches) from pinning the wrong scheme.
|
|
26
|
+
- Fallback on auth-shaped errors now also fires when the stored policy
|
|
27
|
+
is the legacy `rfc9421` value, so existing caches from earlier
|
|
28
|
+
releases self-correct on their next failure.
|
|
29
|
+
|
|
30
|
+
## [0.43.0] - 2026-04-22
|
|
31
|
+
|
|
32
|
+
### Added
|
|
33
|
+
|
|
34
|
+
- Top-level exports for `LitePubRelayClientBot` and `LitePubRelayServerBot`
|
|
35
|
+
from `@evanp/activitypub-bot`.
|
|
36
|
+
- Back-compat aliases `RelayClientBot` and `RelayServerBot`, each re-exported
|
|
37
|
+
as the corresponding Mastodon relay class.
|
|
38
|
+
- README documentation for the `--allow-private`, `--redis-url`, and
|
|
39
|
+
`--trust-proxy` command-line options.
|
|
40
|
+
- README sections for `BotContext.duplicate()`, `updateNote()`, `deleteNote()`,
|
|
41
|
+
`getFollowersId()`, `isFollower()`, `isFollowing()`, `isPendingFollowing()`,
|
|
42
|
+
`followers()`, `following()`, `isLocal()`, and `onIdle()`.
|
|
43
|
+
|
|
44
|
+
### Changed
|
|
45
|
+
|
|
46
|
+
- `.markdownlint.json` disables `MD013` inside code blocks so the CLI
|
|
47
|
+
help-output block can include longer option descriptions verbatim.
|
|
48
|
+
- README now documents `Bot.actorOK()` with its actual `actorId` parameter
|
|
49
|
+
name, and `BotContext.announceObject()` with its optional `actors` argument.
|
|
50
|
+
- `get botID ()` in the README was a typo for `get botId ()`; corrected.
|
|
51
|
+
|
|
12
52
|
## [0.42.1] - 2026-04-22
|
|
13
53
|
|
|
14
54
|
### Added
|
package/README.md
CHANGED
|
@@ -64,6 +64,9 @@ Options:
|
|
|
64
64
|
--intake <number> Number of background intake workers
|
|
65
65
|
--index-file <path> HTML page to show at root path
|
|
66
66
|
--profile-file <path> HTML page to show for bot profiles
|
|
67
|
+
--allow-private flag to allow private network requests
|
|
68
|
+
--redis-url <url> Redis connection URL for rate limiting
|
|
69
|
+
--trust-proxy <value> Express 'trust proxy' setting (e.g. "1", "loopback", "true")
|
|
67
70
|
-h, --help Show this help
|
|
68
71
|
```
|
|
69
72
|
|
|
@@ -139,6 +142,24 @@ Path to the HTML file to show for bot profile pages. Like `--index-file`, any ex
|
|
|
139
142
|
|
|
140
143
|
Falls back to the `PROFILE_FILE` environment variable. The default profile file is in `web/profile.html`.
|
|
141
144
|
|
|
145
|
+
#### --allow-private
|
|
146
|
+
|
|
147
|
+
Boolean flag. When set, the server will make outbound HTTP requests to private IP addresses (loopback, link-local, private, unique-local). By default these are blocked by `SafeAgent` to protect against SSRF. Enable this only when you need to reach ActivityPub peers on your local network or container network — for example, during development or integration testing.
|
|
148
|
+
|
|
149
|
+
Falls back to the `ALLOW_PRIVATE` environment variable. Default is `false`.
|
|
150
|
+
|
|
151
|
+
#### --redis-url
|
|
152
|
+
|
|
153
|
+
Redis connection URL used to back the rate-limit store. If unset, rate-limit counters live in memory, which is fine for a single-process deployment but loses state on restart and doesn't coordinate across multiple instances. Provide a Redis URL to share limits across processes.
|
|
154
|
+
|
|
155
|
+
Falls back to the `REDIS_URL` environment variable. Default is unset (in-memory limiter).
|
|
156
|
+
|
|
157
|
+
#### --trust-proxy
|
|
158
|
+
|
|
159
|
+
Express [`trust proxy`](https://expressjs.com/en/guide/behind-proxies.html) setting. Needed when the server runs behind a reverse proxy or load balancer so that `req.ip`, rate limiting, and logged client IPs reflect the real client rather than the proxy. Numeric values are parsed as a hop count (`1` means trust one hop), boolean-like values (`true`, `false`) toggle trust on or off, and any other value is passed through as a string (e.g. `"loopback"`, or a specific IP or CIDR range).
|
|
160
|
+
|
|
161
|
+
Falls back to the `TRUST_PROXY` environment variable. Default is unset (Express default, no proxy trust).
|
|
162
|
+
|
|
142
163
|
### Config file
|
|
143
164
|
|
|
144
165
|
The config file defines the bots provided by this server.
|
|
@@ -188,13 +209,21 @@ A *DoNothingBot* instance will only do default stuff, like accepting follows.
|
|
|
188
209
|
A *FollowBackBot* will follow back anyone who follows it. Useful for collecting
|
|
189
210
|
public information.
|
|
190
211
|
|
|
191
|
-
####
|
|
212
|
+
#### MastodonRelayClientBot
|
|
213
|
+
|
|
214
|
+
A *MastodonRelayClientBot* can be the client of a Mastodon relay.
|
|
192
215
|
|
|
193
|
-
|
|
216
|
+
#### MastodonRelayServerBot
|
|
194
217
|
|
|
195
|
-
|
|
218
|
+
A *MastodonRelayServerBot* will act as a relay server for remote Mastodon servers.
|
|
196
219
|
|
|
197
|
-
|
|
220
|
+
#### LitePubRelayClientBot
|
|
221
|
+
|
|
222
|
+
A *LitePubRelayClientBot* can be the client of a LitePub (Pleroma) relay.
|
|
223
|
+
|
|
224
|
+
#### LitePubRelayServerBot
|
|
225
|
+
|
|
226
|
+
A *LitePubRelayServerBot* will act as a relay server for remote Pleroma servers and other LitePub-relay-compliant servers.
|
|
198
227
|
|
|
199
228
|
## API
|
|
200
229
|
|
|
@@ -246,6 +275,11 @@ A [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Fun
|
|
|
246
275
|
|
|
247
276
|
A [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) for the username of the bot. Should match the constructor argument.
|
|
248
277
|
|
|
278
|
+
#### get type ()
|
|
279
|
+
|
|
280
|
+
A getter for the type of the bot. This should be an Activity Streams 2.0 object type;
|
|
281
|
+
the default is `Service`.
|
|
282
|
+
|
|
249
283
|
#### get _context ()
|
|
250
284
|
|
|
251
285
|
A protected [getter](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get) for the context of the bot. (The default implementation stashes the context in a private variable, so this protected
|
|
@@ -277,11 +311,11 @@ Called when the server receives a public activity to its shared inbox. This can
|
|
|
277
311
|
|
|
278
312
|
Called when one of the bot's objects is shared by another actor. The first argument is the object, and the second is the `Announce` activity itself. This method is called after the activity has been added to the `shares` collection.
|
|
279
313
|
|
|
280
|
-
#### async actorOK (
|
|
314
|
+
#### async actorOK (actorId, activity)
|
|
281
315
|
|
|
282
316
|
Lets the bot override the default check for matching the actor who sent an activity with the
|
|
283
317
|
actor who did the activity. Usually, these need to be the same, but for some sub-protocols, like
|
|
284
|
-
relays, it can be different. Returns a boolean saying whether the actor is OK.
|
|
318
|
+
relays, it can be different. `actorId` is the id of the actor who delivered the activity. Returns a boolean saying whether the actor is OK.
|
|
285
319
|
|
|
286
320
|
#### async handleActivity (activity)
|
|
287
321
|
|
|
@@ -309,7 +343,7 @@ When a public activity is received at the shared inbox of the server, this metho
|
|
|
309
343
|
|
|
310
344
|
This is the bot's control panel for working with the rest of the server.
|
|
311
345
|
|
|
312
|
-
#### get
|
|
346
|
+
#### get botId ()
|
|
313
347
|
|
|
314
348
|
Returns the username of the bot this context was created for.
|
|
315
349
|
|
|
@@ -333,6 +367,10 @@ Deletes the data stored for this key. There's no backup; it's just gone.
|
|
|
333
367
|
|
|
334
368
|
Checks to see if any data has been previously stored with this key; returns a boolean.
|
|
335
369
|
|
|
370
|
+
#### async duplicate (username)
|
|
371
|
+
|
|
372
|
+
Returns a new `BotContext` identical to this one but scoped to the given `username`. Used by `BotFactory` implementations to produce a per-bot context from a shared template without re-wiring the underlying storage, client, and formatter.
|
|
373
|
+
|
|
336
374
|
#### async getObject (id)
|
|
337
375
|
|
|
338
376
|
Given an [ActivityPub object identifier](https://www.w3.org/TR/activitypub/#obj-id), returns an [activitystrea.ms](#activitystreams) object.
|
|
@@ -355,6 +393,14 @@ The optional additional parameters are strings used for ActivityPub properties o
|
|
|
355
393
|
|
|
356
394
|
A shortcut for sending a reply with `content` to the `object`. Extracts and configures the right addressing properties and threading properties from `object`, and passes them to `sendNote()`.
|
|
357
395
|
|
|
396
|
+
#### async updateNote (note, content)
|
|
397
|
+
|
|
398
|
+
Updates a previously-sent `Note` with new `content`. Re-runs the microtext transformation, stores the updated object, and sends an `Update` activity to the original addressees.
|
|
399
|
+
|
|
400
|
+
#### async deleteNote (note)
|
|
401
|
+
|
|
402
|
+
Deletes a previously-sent `Note`. Replaces the stored object with a `Tombstone` and sends a `Delete` activity to the original addressees.
|
|
403
|
+
|
|
358
404
|
#### async likeObject (obj)
|
|
359
405
|
|
|
360
406
|
Sends a `Like` activity for the passed-in object in [activitystrea.ms](#activitystreams) form.
|
|
@@ -363,9 +409,9 @@ Sends a `Like` activity for the passed-in object in [activitystrea.ms](#activity
|
|
|
363
409
|
|
|
364
410
|
Sends an `Undo`/`Like` activity for the passed-in object in [activitystrea.ms](#activitystreams) form which was previously liked.
|
|
365
411
|
|
|
366
|
-
#### async announceObject (obj)
|
|
412
|
+
#### async announceObject (obj, actors = null)
|
|
367
413
|
|
|
368
|
-
Sends an `Announce` activity for the passed-in object in [activitystrea.ms](#activitystreams) form to followers.
|
|
414
|
+
Sends an `Announce` activity for the passed-in object in [activitystrea.ms](#activitystreams) form. If `actors` is `null` (the default), the `Announce` is addressed to the bot's followers. Otherwise, pass an array of actor IDs (or actor objects) to address the `Announce` to a specific set of recipients — useful for relay-style re-Announce.
|
|
369
415
|
|
|
370
416
|
#### async unannounceObject (obj)
|
|
371
417
|
|
|
@@ -401,6 +447,38 @@ Gets the `id` of the [ActivityPub Actor](https://www.w3.org/TR/activitypub/#acto
|
|
|
401
447
|
|
|
402
448
|
Gets the [WebFinger](https://en.wikipedia.org/wiki/WebFinger) identity of the [ActivityPub Actor](https://www.w3.org/TR/activitypub/#actors) with the given `id`.
|
|
403
449
|
|
|
450
|
+
#### getFollowersId ()
|
|
451
|
+
|
|
452
|
+
Returns the URL of this bot's `followers` collection. Synchronous.
|
|
453
|
+
|
|
454
|
+
#### async isFollower (obj)
|
|
455
|
+
|
|
456
|
+
Returns `true` if `obj` (an actor object in [activitystrea.ms](#activitystreams) form, or anything with an `id`) is in this bot's `followers` collection.
|
|
457
|
+
|
|
458
|
+
#### async isFollowing (obj)
|
|
459
|
+
|
|
460
|
+
Returns `true` if `obj` is in this bot's `following` collection.
|
|
461
|
+
|
|
462
|
+
#### async isPendingFollowing (obj)
|
|
463
|
+
|
|
464
|
+
Returns `true` if this bot has sent a `Follow` to `obj` that has not yet been accepted or rejected.
|
|
465
|
+
|
|
466
|
+
#### async \* followers ()
|
|
467
|
+
|
|
468
|
+
Async generator that yields each actor in this bot's `followers` collection, one at a time, across collection pages.
|
|
469
|
+
|
|
470
|
+
#### async \* following ()
|
|
471
|
+
|
|
472
|
+
Async generator that yields each actor in this bot's `following` collection, one at a time, across collection pages.
|
|
473
|
+
|
|
474
|
+
#### isLocal (url)
|
|
475
|
+
|
|
476
|
+
Returns `true` if `url` is served by this activitypub-bot instance (i.e. its origin matches the configured `--origin`). Synchronous.
|
|
477
|
+
|
|
478
|
+
#### async onIdle ()
|
|
479
|
+
|
|
480
|
+
Resolves when the background distribution queue has drained. Intended for test code that needs to wait for outbound activities to finish being delivered before asserting on their effects.
|
|
481
|
+
|
|
404
482
|
### activitystrea.ms
|
|
405
483
|
|
|
406
484
|
Activity Streams 2.0 objects are represented internally as [activitystrea.ms](https://www.npmjs.com/package/activitystrea.ms) library objects.
|
package/lib/activitypubclient.js
CHANGED
|
@@ -205,9 +205,9 @@ export class ActivityPubClient {
|
|
|
205
205
|
}
|
|
206
206
|
)
|
|
207
207
|
this.#logger.debug({ hostname, status: res.status }, 'response received')
|
|
208
|
-
if ([401, 403].includes(res.status) &&
|
|
208
|
+
if ([400, 401, 403].includes(res.status) &&
|
|
209
209
|
sign &&
|
|
210
|
-
|
|
210
|
+
lastPolicy === SignaturePolicyStorage.RFC9421) {
|
|
211
211
|
const body = await res.text()
|
|
212
212
|
this.#logger.debug(
|
|
213
213
|
{ url, status: res.status, body, headers: res.headers },
|
|
@@ -256,7 +256,10 @@ export class ActivityPubClient {
|
|
|
256
256
|
throw err
|
|
257
257
|
}
|
|
258
258
|
|
|
259
|
-
|
|
259
|
+
// Only cache draft-cavage-12 (i.e. the degraded fallback). Caching
|
|
260
|
+
// rfc9421 would pin origins whose public endpoints don't actually
|
|
261
|
+
// verify signatures, and block future re-probing when they upgrade.
|
|
262
|
+
if (lastPolicy === SignaturePolicyStorage.DRAFT_CAVAGE_12) {
|
|
260
263
|
await this.#policyStorage.set(parsed.origin, lastPolicy)
|
|
261
264
|
}
|
|
262
265
|
|
|
@@ -342,7 +345,8 @@ export class ActivityPubClient {
|
|
|
342
345
|
body
|
|
343
346
|
}
|
|
344
347
|
)
|
|
345
|
-
if ([401, 403].includes(res.status) &&
|
|
348
|
+
if ([400, 401, 403].includes(res.status) &&
|
|
349
|
+
lastPolicy === SignaturePolicyStorage.RFC9421) {
|
|
346
350
|
const body = await res.text()
|
|
347
351
|
this.#logger.debug(
|
|
348
352
|
{ url, status: res.status, body, headers: res.headers },
|
|
@@ -378,7 +382,10 @@ export class ActivityPubClient {
|
|
|
378
382
|
{ url, method, headers: res.headers, body }
|
|
379
383
|
)
|
|
380
384
|
}
|
|
381
|
-
|
|
385
|
+
// Only cache draft-cavage-12 (i.e. the degraded fallback). Caching
|
|
386
|
+
// rfc9421 would pin origins whose public endpoints don't actually
|
|
387
|
+
// verify signatures, and block future re-probing when they upgrade.
|
|
388
|
+
if (lastPolicy === SignaturePolicyStorage.DRAFT_CAVAGE_12) {
|
|
382
389
|
await this.#policyStorage.set(parsed.origin, lastPolicy)
|
|
383
390
|
}
|
|
384
391
|
}
|
package/lib/index.js
CHANGED
|
@@ -3,6 +3,8 @@ export { default as Bot } from './bot.js'
|
|
|
3
3
|
export { default as BotFactory } from './botfactory.js'
|
|
4
4
|
export { default as OKBot } from './bots/ok.js'
|
|
5
5
|
export { default as DoNothingBot } from './bots/donothing.js'
|
|
6
|
-
export { default as MastodonRelayClientBot } from './bots/mastodonrelayclient.js'
|
|
7
|
-
export { default as MastodonRelayServerBot } from './bots/mastodonrelayserver.js'
|
|
6
|
+
export { default as MastodonRelayClientBot, default as RelayClientBot } from './bots/mastodonrelayclient.js'
|
|
7
|
+
export { default as MastodonRelayServerBot, default as RelayServerBot } from './bots/mastodonrelayserver.js'
|
|
8
8
|
export { default as FollowBackBot } from './bots/followback.js'
|
|
9
|
+
export { default as LitePubRelayClientBot } from './bots/litepubrelayclient.js'
|
|
10
|
+
export { default as LitePubRelayServerBot } from './bots/litepubrelayserver.js'
|