@sockethub/platform-xmpp 5.0.0-beta.0 → 5.0.0-beta.2

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/README.md CHANGED
@@ -26,16 +26,53 @@ updates through ActivityStreams messages.
26
26
  Credentials are sent to Sockethub via a `credentials` message before the
27
27
  `connect` verb. The XMPP platform accepts a single `password` field.
28
28
 
29
+ Authentication requires an encrypted connection: direct TLS (`xmpps://`) or
30
+ a successful STARTTLS upgrade. If the server does not offer encryption, the
31
+ connection fails before credentials are sent.
32
+ This requirement also applies to automatic reconnections.
33
+
29
34
  ### Credentials object
30
35
 
31
36
  | Field | Type | Required | Description |
32
- |---|---|---|---|
37
+ | --- | --- | --- | --- |
33
38
  | `type` | string | yes | Must be `"credentials"`. |
34
39
  | `userAddress` | string | yes | Bare JID, e.g. `user@jabber.net`. |
35
40
  | `resource` | string | yes | XMPP resource identifier (e.g. `"phone"`). |
36
41
  | `password` | string | yes | SASL password. Use this field for PLAIN-slot tokens too. |
37
- | `server` | string | no | Overrides the hostname from `userAddress`. |
38
- | `port` | number | no | Overrides the default port. |
42
+ | `server` | string | no | Overrides the host from `userAddress`. Host name or `xmpp(s)://` URI. |
43
+ | `port` | integer | no | Overrides the default port (1-65535). |
44
+
45
+ Without a `port`, a bare host is looked up through its `_xmpps-client` and
46
+ `_xmpp-client` SRV records, and its own addresses on ports 5223 (direct TLS)
47
+ and 5222. A bare host with a `port` skips SRV lookup and connects with
48
+ `xmpp://` (STARTTLS) on that port. For direct TLS, set `server` to an
49
+ `xmpps://` URI. The platform does not use HTTP host-meta discovery or the
50
+ WebSocket transport.
51
+
52
+ An internationalized host name (such as `bücher.example`) works only as a bare
53
+ host without a `port`. With a `port`, or inside an `xmpp(s)://` URI, it is
54
+ refused; use its ASCII form (`xn--bcher-kva.example`) instead.
55
+
56
+ ### Private addresses
57
+
58
+ The platform refuses to connect to loopback, private, link-local, and cloud
59
+ metadata addresses, using the same address rules as the
60
+ [outbound URL guard](../../docs/configuration.md#outbound-url-guard). To reach
61
+ an XMPP server on a private network, set `allowPrivateAddresses` in this
62
+ platform's `packageConfig` entry:
63
+
64
+ ```json
65
+ {
66
+ "packageConfig": {
67
+ "@sockethub/platform-xmpp": {
68
+ "allowPrivateAddresses": true
69
+ }
70
+ }
71
+ }
72
+ ```
73
+
74
+ Do not enable it on a server that accepts untrusted clients. Any client could
75
+ then make Sockethub connect to internal services.
39
76
 
40
77
  ### Password authentication
41
78
 
@@ -280,6 +317,31 @@ non-recoverable connection error.
280
317
  }
281
318
  ```
282
319
 
320
+ ## Incoming presence and roster
321
+
322
+ Live presence arrives as an `update` with `object.type` `presence`. `actor.id`
323
+ is the sender's full JID, with `actor.type` `room` for a joined room and
324
+ `person` otherwise; when the stanza has no `to`, `actor.name` is the resource
325
+ part. `object.presence` is the `<show>` value, `offline` for an `unavailable`
326
+ stanza, and `online` otherwise. A `<status>` element is copied to
327
+ `object.content`. The responses schema accepts only `away`, `chat`, `dnd`,
328
+ `xa`, `offline`, `online`, and `notauthorized`; a stanza with any other
329
+ `<show>` value is dropped and the server logs
330
+ `dropping malformed outbound message`.
331
+
332
+ Roster data (`jabber:iq:roster`) is trusted only from the server (a stanza
333
+ with no `from`) or from this account's own bare JID, per
334
+ [RFC 6121 section 2.1.6](https://www.rfc-editor.org/rfc/rfc6121#section-2.1.6).
335
+ Any other sender, including this account's full JID, is ignored and produces
336
+ no client event. Roster items with subscription `none`, `to`, or `from`
337
+ without a pending request are delivered as `request-friend`, with the contact
338
+ JID and roster name in `actor`. Items with a mutual (`both`) subscription are
339
+ delivered as a presence `update` with `object.presence` `online`; items where
340
+ this account's own subscription request is still pending (`from` with
341
+ `ask="subscribe"`) are delivered as a presence `update` with
342
+ `object.presence` `notauthorized`. Every roster
343
+ activity carries this account's bare JID in `target.id`.
344
+
283
345
  ## Features
284
346
 
285
347
  * **Instant messaging**: Send and receive one-on-one messages
@@ -0,0 +1,16 @@
1
+ import type { XmppClientInstance } from "@xmpp/client";
2
+ /**
3
+ * Refuse XMPP connections to loopback, private, link-local, and cloud
4
+ * metadata addresses, matching the outbound guard used by the HTTP platforms.
5
+ *
6
+ * Every socket gets the shared guarded DNS lookup, which checks the address
7
+ * actually connected to. IP-literal hosts skip DNS, so they are checked
8
+ * directly; `@xmpp/resolve` turns SRV and A records into IP literals, so
9
+ * discovered candidates are checked here too. Transports that do not use a
10
+ * host/port socket (WebSocket) are refused outright. xmpp.js treats a
11
+ * refusal as "no transport" and skips that candidate.
12
+ *
13
+ * The wrapper lives on the shared module-level prototypes, like
14
+ * {@link setTlsServername}, and its setting is refreshed on every call.
15
+ */
16
+ export declare function guardXmppConnections(client: XmppClientInstance, allowPrivateAddresses: boolean): void;
package/dist/index.d.ts CHANGED
@@ -48,6 +48,8 @@ export default class XMPP implements PersistentPlatformInterface {
48
48
  readonly sendToClient: PlatformSendToClient;
49
49
  /** @internal Set of bare JIDs for rooms this client has joined. */
50
50
  __knownRooms: Set<string>;
51
+ /** @internal Bare JID of the authenticated account, used by IncomingHandlers. */
52
+ __bareJid: string | undefined;
51
53
  protected __clientConstructor: (options: XmppClientOptions) => XmppClientInstance;
52
54
  protected __xml: (name: string, attrs?: Record<string, string | undefined>, ...children: (XmppElement | undefined)[]) => XmppElement;
53
55
  private readonly id;