@bymax-one/nest-realtime 1.2.4 → 1.2.5
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/CHANGELOG.md +18 -1
- package/README.md +15 -0
- package/dist/internal/index.cjs +1 -0
- package/dist/internal/index.d.cts +20 -0
- package/dist/internal/index.d.ts +20 -0
- package/dist/internal/index.mjs +1 -0
- package/dist/websocket/index.cjs +1 -0
- package/dist/websocket/index.mjs +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [1.2.5] - 2026-11-01
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- **`ConnectionAuthContext.remoteAddress`, the TCP peer of the connection.** It is read from the
|
|
15
|
+
socket (`req.socket.remoteAddress` on SSE, `handshake.address` on WebSocket), never from a header,
|
|
16
|
+
so a client cannot forge it. It is distinct from `ip`, which on SSE comes from `X-Forwarded-For`.
|
|
17
|
+
An authenticator behind a reverse proxy can check it against its trusted proxies before believing
|
|
18
|
+
a forwarded header such as `X-Forwarded-Host`. It is `undefined` when the socket reports no
|
|
19
|
+
address. `SseRequest` gains an optional `socket` for it. Nothing existing changes.
|
|
20
|
+
|
|
21
|
+
### Internal
|
|
22
|
+
|
|
23
|
+
- The `internal` bundle budget in `pnpm size` is raised to make room for the line that reads the
|
|
24
|
+
peer address.
|
|
25
|
+
|
|
10
26
|
## [1.2.4] - 2026-11-01
|
|
11
27
|
|
|
12
28
|
### Fixed
|
|
@@ -618,7 +634,8 @@ First published release.
|
|
|
618
634
|
rather than by the manual sweep that raised the NestJS floors — that sweep
|
|
619
635
|
asked about NestJS and never put the same question to the other ten peers.
|
|
620
636
|
|
|
621
|
-
[Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.
|
|
637
|
+
[Unreleased]: https://github.com/bymaxone/nest-realtime/compare/v1.2.5...HEAD
|
|
638
|
+
[1.2.5]: https://github.com/bymaxone/nest-realtime/compare/v1.2.4...v1.2.5
|
|
622
639
|
[1.2.4]: https://github.com/bymaxone/nest-realtime/compare/v1.2.3...v1.2.4
|
|
623
640
|
[1.2.3]: https://github.com/bymaxone/nest-realtime/compare/v1.2.2...v1.2.3
|
|
624
641
|
[1.2.2]: https://github.com/bymaxone/nest-realtime/compare/v1.2.1...v1.2.2
|
package/README.md
CHANGED
|
@@ -668,6 +668,21 @@ const hooks: IConnectionLifecycleHooks = {
|
|
|
668
668
|
Like `roles`, it is a **connect-time snapshot**: a `revalidate` that keeps the connection alive
|
|
669
669
|
does not refresh it. The library never reads a key.
|
|
670
670
|
|
|
671
|
+
#### Client address versus peer address
|
|
672
|
+
|
|
673
|
+
`authenticate` receives two addresses, and only one of them can be trusted on its own:
|
|
674
|
+
|
|
675
|
+
| Field | SSE | WebSocket | Forgeable by the client |
|
|
676
|
+
| --------------- | -------------------------------------------- | ------------------- | --------------------------- |
|
|
677
|
+
| `ip` | `X-Forwarded-For` first value, else `req.ip` | `handshake.address` | Yes on SSE, no on WebSocket |
|
|
678
|
+
| `remoteAddress` | `req.socket.remoteAddress` | `handshake.address` | No |
|
|
679
|
+
|
|
680
|
+
`remoteAddress` is the TCP peer, read from the socket and never from a header. Behind a reverse
|
|
681
|
+
proxy it is the proxy's address. Use it to decide whether a forwarded header such as
|
|
682
|
+
`X-Forwarded-Host` may be believed: read it only when `remoteAddress` is one of your proxies. It is
|
|
683
|
+
`undefined` when the socket reports no address, and an IPv4 peer can arrive in its IPv4-mapped form
|
|
684
|
+
(`::ffff:10.0.0.1`), which is passed through as reported.
|
|
685
|
+
|
|
671
686
|
### Rooms
|
|
672
687
|
|
|
673
688
|
| Room ID | Used for | Auto-joined |
|
package/dist/internal/index.cjs
CHANGED
|
@@ -59,6 +59,18 @@ interface ConnectionAuthContext {
|
|
|
59
59
|
* without validating the proxy chain.
|
|
60
60
|
*/
|
|
61
61
|
readonly ip: string;
|
|
62
|
+
/**
|
|
63
|
+
* The TCP peer address of the connection: the socket's own `remoteAddress`, never read
|
|
64
|
+
* from a header, so a client cannot forge it. It is the proxy's address when one sits
|
|
65
|
+
* in front of the application, and it is distinct from `ip`, which on SSE comes from
|
|
66
|
+
* `X-Forwarded-For`. Use it to decide whether a forwarded header such as
|
|
67
|
+
* `X-Forwarded-Host` may be believed, by checking it against the proxies you trust.
|
|
68
|
+
*
|
|
69
|
+
* `undefined` when the socket reports no address. A peer on IPv4 can arrive in its
|
|
70
|
+
* IPv4-mapped IPv6 form (`::ffff:10.0.0.1`); the value is passed through as the socket
|
|
71
|
+
* reports it.
|
|
72
|
+
*/
|
|
73
|
+
readonly remoteAddress?: string | undefined;
|
|
62
74
|
/** Raw User-Agent. */
|
|
63
75
|
readonly userAgent: string | undefined;
|
|
64
76
|
/** Transport kind initiating the connection. */
|
|
@@ -1014,6 +1026,14 @@ interface SseRequest {
|
|
|
1014
1026
|
readonly headers: Readonly<Record<string, SseHeaderValue>>;
|
|
1015
1027
|
/** Remote address as the HTTP framework resolved it, when it resolves one. */
|
|
1016
1028
|
readonly ip?: string | undefined;
|
|
1029
|
+
/**
|
|
1030
|
+
* The underlying connection, when the framework exposes it (Express and Fastify do as
|
|
1031
|
+
* `req.socket`). Its `remoteAddress` is the TCP peer, unlike `ip`, which a trusted-proxy
|
|
1032
|
+
* setting can derive from a header.
|
|
1033
|
+
*/
|
|
1034
|
+
readonly socket?: {
|
|
1035
|
+
readonly remoteAddress?: string | undefined;
|
|
1036
|
+
} | undefined;
|
|
1017
1037
|
/** Parsed query string. Values are narrowed to strings by the caller. */
|
|
1018
1038
|
readonly query: Readonly<Record<string, unknown>>;
|
|
1019
1039
|
}
|
package/dist/internal/index.d.ts
CHANGED
|
@@ -59,6 +59,18 @@ interface ConnectionAuthContext {
|
|
|
59
59
|
* without validating the proxy chain.
|
|
60
60
|
*/
|
|
61
61
|
readonly ip: string;
|
|
62
|
+
/**
|
|
63
|
+
* The TCP peer address of the connection: the socket's own `remoteAddress`, never read
|
|
64
|
+
* from a header, so a client cannot forge it. It is the proxy's address when one sits
|
|
65
|
+
* in front of the application, and it is distinct from `ip`, which on SSE comes from
|
|
66
|
+
* `X-Forwarded-For`. Use it to decide whether a forwarded header such as
|
|
67
|
+
* `X-Forwarded-Host` may be believed, by checking it against the proxies you trust.
|
|
68
|
+
*
|
|
69
|
+
* `undefined` when the socket reports no address. A peer on IPv4 can arrive in its
|
|
70
|
+
* IPv4-mapped IPv6 form (`::ffff:10.0.0.1`); the value is passed through as the socket
|
|
71
|
+
* reports it.
|
|
72
|
+
*/
|
|
73
|
+
readonly remoteAddress?: string | undefined;
|
|
62
74
|
/** Raw User-Agent. */
|
|
63
75
|
readonly userAgent: string | undefined;
|
|
64
76
|
/** Transport kind initiating the connection. */
|
|
@@ -1014,6 +1026,14 @@ interface SseRequest {
|
|
|
1014
1026
|
readonly headers: Readonly<Record<string, SseHeaderValue>>;
|
|
1015
1027
|
/** Remote address as the HTTP framework resolved it, when it resolves one. */
|
|
1016
1028
|
readonly ip?: string | undefined;
|
|
1029
|
+
/**
|
|
1030
|
+
* The underlying connection, when the framework exposes it (Express and Fastify do as
|
|
1031
|
+
* `req.socket`). Its `remoteAddress` is the TCP peer, unlike `ip`, which a trusted-proxy
|
|
1032
|
+
* setting can derive from a header.
|
|
1033
|
+
*/
|
|
1034
|
+
readonly socket?: {
|
|
1035
|
+
readonly remoteAddress?: string | undefined;
|
|
1036
|
+
} | undefined;
|
|
1017
1037
|
/** Parsed query string. Values are narrowed to strings by the caller. */
|
|
1018
1038
|
readonly query: Readonly<Record<string, unknown>>;
|
|
1019
1039
|
}
|
package/dist/internal/index.mjs
CHANGED
package/dist/websocket/index.cjs
CHANGED
package/dist/websocket/index.mjs
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bymax-one/nest-realtime",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.5",
|
|
4
4
|
"description": "Realtime backend → frontend communication for NestJS — dual-transport SSE (default) and WebSocket (opt-in) with a unified server-side API.",
|
|
5
5
|
"author": "Bymax One <support@bymax.one>",
|
|
6
6
|
"license": "MIT",
|