badmfck-api-server 6.0.13 → 6.0.14

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 CHANGED
@@ -1,5 +1,22 @@
1
1
  # Changelog
2
2
 
3
+ ## 6.0.14 — 2026-11-19
4
+
5
+ ### Added
6
+
7
+ - **Microservice callers limited by address.** `allowedIps` per caller in the host's `clients` (IPs and
8
+ subnets, IPv4/IPv6): a leaked key is useless from anywhere else. A call from another address gets 403
9
+ before its signature is checked, and the host logs the key id and address. Behind nginx the address
10
+ is `X-Real-IP`, believed only from `trustedProxies` (loopback by default). Without `allowedIps` any
11
+ address is accepted, as before; a malformed or empty list stops the host at startup.
12
+
13
+ ### Fixed
14
+
15
+ - **Deployer log flooded with "ignored" errors** (since 6.0.13). The project-name check also ran on
16
+ the deployer's own `<project>_state_.json` files and on `setup.json` when `setup_path` is the projects
17
+ folder, and logged an error for each at every rescan (once a minute). Files without `name` are now
18
+ skipped silently, and a config with a bad name is reported once, not every minute.
19
+
3
20
  ## 6.0.13 — 2026-11-19
4
21
 
5
22
  ### Before you upgrade
package/README.md CHANGED
@@ -260,8 +260,8 @@ new MicroserviceHost({
260
260
  requests: [REQ_FEES_ACTUAL, REQ_MERCHANT_ACTUAL],
261
261
  privateKey: secrets.CRM_MS_KEY, // the host's private key: signs its answers
262
262
  clients: {
263
- gate: { publicKey: "MCowBQYDK2VwAyEA…" }, // may call everything in `requests`
264
- reports: { publicKey: "MCowBQYDK2VwAyEA…", requests: ["REQ_FEES_ACTUAL"] },
263
+ gate: { publicKey: "MCowBQYDK2VwAyEA…", allowedIps: ["127.0.0.1", "::1"] }, // everything in `requests`, from this server only
264
+ reports: { publicKey: "MCowBQYDK2VwAyEA…", requests: ["REQ_FEES_ACTUAL"], allowedIps: ["10.8.0.0/24"] },
265
265
  },
266
266
  });
267
267
 
@@ -279,6 +279,12 @@ const fees = await REQ_MICROSERVICE_CALL.request({ id: "crm", requestName: "REQ_
279
279
 
280
280
  - **Who may call what.** The host knows each caller by its key id and refuses requests outside that caller's
281
281
  `requests` list. A request can't be replayed, changed on the way, or redirected to another host.
282
+ - **From where.** `allowedIps` (IPs and subnets, IPv4/IPv6) limits where a caller's key works, so a leaked key
283
+ is useless anywhere else. A call from another address gets `403` before its signature is even checked, and
284
+ the host logs the key id and address. The address is the real client's: behind nginx it is `X-Real-IP`
285
+ (`proxy_set_header X-Real-IP $remote_addr;`), believed only from `trustedProxies` (loopback by default);
286
+ otherwise the TCP peer. List both `127.0.0.1` and `::1` for a caller on the same server — `localhost` can
287
+ resolve to either. Without `allowedIps` any address is accepted; a malformed or empty list stops the host.
282
288
  - **Operations run once.** Each call carries an operation id (`op`) that stays the same across retries: the
283
289
  host runs it once and answers repeats from its job store. Pass your own `op` (a payment or transfer id) to
284
290
  make it stable beyond this process. The default store is memory, so a restart forgets it: a handler that
@@ -193,6 +193,7 @@ export declare class ConfigService extends BaseService {
193
193
  private dir;
194
194
  private busy;
195
195
  private retake;
196
+ private reportedNames;
196
197
  private watchDebounceTimer;
197
198
  private _lastConfigHash;
198
199
  constructor(dir: string);
@@ -140,6 +140,7 @@ class ConfigService extends BaseService_1.BaseService {
140
140
  dir;
141
141
  busy = false;
142
142
  retake = false;
143
+ reportedNames = new Set();
143
144
  watchDebounceTimer = null;
144
145
  _lastConfigHash = null;
145
146
  constructor(dir) {
@@ -181,9 +182,15 @@ class ConfigService extends BaseService_1.BaseService {
181
182
  try {
182
183
  const file = fs_1.default.readFileSync(path_1.default.resolve(this.dir, f));
183
184
  const config = JSON.parse(file.toString());
184
- const nameProblem = projectNameProblem(config?.name);
185
+ if (config?.name === undefined)
186
+ continue;
187
+ const nameProblem = projectNameProblem(config.name);
185
188
  if (nameProblem) {
186
- (0, LogService_1.logError)(`Deployer: ${f} ignored — ${nameProblem}`);
189
+ const key = f + "\0" + String(config.name);
190
+ if (!this.reportedNames.has(key)) {
191
+ this.reportedNames.add(key);
192
+ (0, LogService_1.logError)(`Deployer: ${f} ignored — ${nameProblem}`);
193
+ }
187
194
  continue;
188
195
  }
189
196
  temp.set(config.name, config);
@@ -4,6 +4,7 @@ import { HTTPRequestVO, IError } from "../structures/Interfaces";
4
4
  export interface IMicroserviceCaller {
5
5
  publicKey: string;
6
6
  requests?: string[];
7
+ allowedIps?: string[];
7
8
  }
8
9
  export interface IMicroserviceHostOptions {
9
10
  id: string;
@@ -45,6 +45,7 @@ const LogService_1 = require("../LogService");
45
45
  const async_hooks_1 = require("async_hooks");
46
46
  const Trace_1 = require("../helper/Trace");
47
47
  const crypto_1 = __importDefault(require("crypto"));
48
+ const IpAllowList_1 = require("../helper/IpAllowList");
48
49
  class MemoryJobStore {
49
50
  #jobs = new Map();
50
51
  get(key) { return this.#jobs.get(key) ?? null; }
@@ -64,6 +65,7 @@ class MicroserviceHost extends BaseService_1.BaseService {
64
65
  options;
65
66
  #store;
66
67
  #auth = null;
68
+ #allowedIps = new Map();
67
69
  constructor(opt) {
68
70
  super("Microservice-host-" + opt.id);
69
71
  if (!opt.clients && !opt.securityKey)
@@ -73,6 +75,16 @@ class MicroserviceHost extends BaseService_1.BaseService {
73
75
  throw new Error(`MicroserviceHost "${opt.id}": "clients" needs "privateKey" — the host signs its answers`);
74
76
  InterceptorSignedAuth_1.InterceptorSignedAuth.publicKeyOf(opt.privateKey);
75
77
  this.#auth = new InterceptorSignedAuth_1.InterceptorSignedAuth(kid => opt.clients?.[kid]?.publicKey ?? null);
78
+ for (const [kid, c] of Object.entries(opt.clients)) {
79
+ if (c.allowedIps === undefined)
80
+ continue;
81
+ const built = IpAllowList_1.IpAllowList.build(c.allowedIps);
82
+ if (built.error)
83
+ throw new Error(`MicroserviceHost "${opt.id}": clients.${kid}.allowedIps: ${built.error}`);
84
+ if (!built.list)
85
+ throw new Error(`MicroserviceHost "${opt.id}": clients.${kid}.allowedIps is empty — list the addresses, or remove it to allow any`);
86
+ this.#allowedIps.set(kid, built.list);
87
+ }
76
88
  }
77
89
  this.options = opt;
78
90
  this.#store = opt.jobStore ?? new MemoryJobStore();
@@ -105,6 +117,12 @@ class MicroserviceHost extends BaseService_1.BaseService {
105
117
  async #handleSigned(req) {
106
118
  if (!this.#auth)
107
119
  return { ...DefaultErrors_1.default.UNAUTHORIZED, details: "this host takes no signed calls" };
120
+ const claimed = InterceptorSignedAuth_1.InterceptorSignedAuth.parseHeader(String(req.headers["authorization"]).slice("signature ".length)).kid;
121
+ const ips = claimed ? this.#allowedIps.get(claimed) : undefined;
122
+ if (ips && !IpAllowList_1.IpAllowList.allows(ips, req.ip)) {
123
+ (0, LogService_1.logWarn)(`MicroserviceHost ${this.options.id}: rejected call — key "${claimed}" from ${req.ip ?? "unknown address"}, not in its allowedIps`);
124
+ return { ...DefaultErrors_1.default.FORBIDDEN, details: "address not allowed" };
125
+ }
108
126
  const verdict = await this.#auth.verify(req);
109
127
  if (!verdict.kid) {
110
128
  (0, LogService_1.logWarn)(`MicroserviceHost ${this.options.id}: rejected call — ${verdict.error}`);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "6.0.13",
3
+ "version": "6.0.14",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",