@effectstream/runtime 0.104.0 → 0.104.3
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/package.json +12 -12
- package/src/api/http-server.ts +32 -2
- package/src/api/trust-proxy.test.ts +22 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@effectstream/runtime",
|
|
3
|
-
"version": "0.104.
|
|
3
|
+
"version": "0.104.3",
|
|
4
4
|
"license": "(MIT OR Apache-2.0)",
|
|
5
5
|
"homepage": "https://effectstream.github.io/docs/",
|
|
6
6
|
"repository": {
|
|
@@ -13,17 +13,17 @@
|
|
|
13
13
|
},
|
|
14
14
|
"exports": "./src/mod.ts",
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@effectstream/concise": "0.104.
|
|
17
|
-
"@effectstream/config": "0.104.
|
|
18
|
-
"@effectstream/coroutine": "0.104.
|
|
19
|
-
"@effectstream/crypto": "0.104.
|
|
20
|
-
"@effectstream/db": "0.104.
|
|
21
|
-
"@effectstream/event-client": "0.104.
|
|
22
|
-
"@effectstream/event-server": "0.104.
|
|
23
|
-
"@effectstream/log": "0.104.
|
|
24
|
-
"@effectstream/sm": "0.104.
|
|
25
|
-
"@effectstream/sync": "0.104.
|
|
26
|
-
"@effectstream/utils": "0.104.
|
|
16
|
+
"@effectstream/concise": "0.104.3",
|
|
17
|
+
"@effectstream/config": "0.104.3",
|
|
18
|
+
"@effectstream/coroutine": "0.104.3",
|
|
19
|
+
"@effectstream/crypto": "0.104.3",
|
|
20
|
+
"@effectstream/db": "0.104.3",
|
|
21
|
+
"@effectstream/event-client": "0.104.3",
|
|
22
|
+
"@effectstream/event-server": "0.104.3",
|
|
23
|
+
"@effectstream/log": "0.104.3",
|
|
24
|
+
"@effectstream/sm": "0.104.3",
|
|
25
|
+
"@effectstream/sync": "0.104.3",
|
|
26
|
+
"@effectstream/utils": "0.104.3",
|
|
27
27
|
"@fastify/cors": "^11.0.1",
|
|
28
28
|
"@metamask/json-rpc-engine": "^10.0.3",
|
|
29
29
|
"pg": "8.21.0",
|
package/src/api/http-server.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import fastify, {
|
|
1
|
+
import fastify, {
|
|
2
|
+
type FastifyInstance,
|
|
3
|
+
type FastifyReply,
|
|
4
|
+
type FastifyRequest,
|
|
5
|
+
type FastifyServerOptions,
|
|
6
|
+
} from "fastify";
|
|
2
7
|
import { evmRpcEngine } from "./rpc-evm/eip1193.ts";
|
|
3
8
|
import { appliedBlockStatus } from "./apply-status.ts";
|
|
4
9
|
import { finalizedStreamStatus } from "./stream-status.ts";
|
|
@@ -53,6 +58,23 @@ import {
|
|
|
53
58
|
import { PrimitiveRegistry } from "@effectstream/sm";
|
|
54
59
|
import { ConfigNetworkType, getWriteNamespace, usePaimaStaticConfig } from "@effectstream/config";
|
|
55
60
|
|
|
61
|
+
/**
|
|
62
|
+
* Parse `EFFECTSTREAM_TRUST_PROXY` into Fastify's `trustProxy` option.
|
|
63
|
+
*
|
|
64
|
+
* - `true` / `1` / empty → `true` (trust every hop; the default)
|
|
65
|
+
* - `false` / `0` → `false`
|
|
66
|
+
* - anything else → comma-separated proxy IPs / CIDRs
|
|
67
|
+
*/
|
|
68
|
+
export function parseTrustProxy(raw: string | undefined): boolean | string[] {
|
|
69
|
+
const value = (raw ?? "").trim();
|
|
70
|
+
if (value === "" || value.toLowerCase() === "true" || value === "1") return true;
|
|
71
|
+
if (value.toLowerCase() === "false" || value === "0") return false;
|
|
72
|
+
return value
|
|
73
|
+
.split(",")
|
|
74
|
+
.map((entry) => entry.trim())
|
|
75
|
+
.filter((entry) => entry.length > 0);
|
|
76
|
+
}
|
|
77
|
+
|
|
56
78
|
function tableListContains(
|
|
57
79
|
list: Array<{ table_name: string | null }>,
|
|
58
80
|
name: string,
|
|
@@ -168,7 +190,15 @@ export const startHttpServer = function* (
|
|
|
168
190
|
// Use dbConn directly; queries are executed via pgtyped PreparedQuery.run
|
|
169
191
|
// Allow any webpage to access the server.
|
|
170
192
|
// This node is not specific for a specific website.
|
|
171
|
-
|
|
193
|
+
// trustProxy decides what `request.ip` means. Deployments front this server
|
|
194
|
+
// with nginx/Caddy, and without it Fastify reports the proxy's address for
|
|
195
|
+
// every client — so anything keyed per IP (the rate limiter above all)
|
|
196
|
+
// shares ONE bucket across every user behind the proxy.
|
|
197
|
+
const serverOptions: FastifyServerOptions = {
|
|
198
|
+
routerOptions: { maxParamLength: 300 },
|
|
199
|
+
trustProxy: parseTrustProxy(ENV.EFFECTSTREAM_TRUST_PROXY),
|
|
200
|
+
};
|
|
201
|
+
const server = fastify(serverOptions);
|
|
172
202
|
// OpenAPI Docs
|
|
173
203
|
yield* registerOpenApiDocumentation(server, ENV.EFFECTSTREAM_API_PORT);
|
|
174
204
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { describe, expect, test } from "bun:test";
|
|
2
|
+
import { parseTrustProxy } from "./http-server.ts";
|
|
3
|
+
|
|
4
|
+
describe("parseTrustProxy", () => {
|
|
5
|
+
test("defaults to trusting every hop", () => {
|
|
6
|
+
expect(parseTrustProxy(undefined)).toBe(true);
|
|
7
|
+
expect(parseTrustProxy("")).toBe(true);
|
|
8
|
+
expect(parseTrustProxy("true")).toBe(true);
|
|
9
|
+
expect(parseTrustProxy("TRUE")).toBe(true);
|
|
10
|
+
expect(parseTrustProxy("1")).toBe(true);
|
|
11
|
+
});
|
|
12
|
+
test("can be switched off", () => {
|
|
13
|
+
expect(parseTrustProxy("false")).toBe(false);
|
|
14
|
+
expect(parseTrustProxy("0")).toBe(false);
|
|
15
|
+
});
|
|
16
|
+
test("a bare number that is not 0/1 is treated as an address list entry", () => {
|
|
17
|
+
expect(parseTrustProxy("2")).toEqual(["2"]);
|
|
18
|
+
});
|
|
19
|
+
test("a list becomes trimmed proxy addresses", () => {
|
|
20
|
+
expect(parseTrustProxy(" 127.0.0.1, 10.0.0.0/8 ,")).toEqual(["127.0.0.1", "10.0.0.0/8"]);
|
|
21
|
+
});
|
|
22
|
+
});
|