@servicenow/aiux 22.42.1 → 22.42.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.
@@ -15,9 +15,32 @@ import {fetch as undiciFetch} from 'undici';
15
15
  * authenticate as the interacting logged-in user).
16
16
  */
17
17
 
18
- // Hop-by-hop headers that must not be forwarded (RFC 7230 §6.1) + encoding
19
- // we don't want to re-interpret.
20
- const STRIP_REQUEST_HEADERS = new Set(['host', 'connection', 'content-length']);
18
+ // Hop-by-hop headers that must not be forwarded (RFC 7230 §6.1) + `host`,
19
+ // which we overwrite with the instance host below.
20
+ //
21
+ // `content-length` is deliberately NOT here: it is an end-to-end header, and
22
+ // the body is forwarded as an unread stream (see the content-type parser
23
+ // below), so undici cannot recompute it. Stripping it made undici fall back to
24
+ // `Transfer-Encoding: chunked`, which Glide's servlet stack rejects with
25
+ // 411 Length Required, killing every bodied POST, most visibly the single
26
+ // /api/now/v1/batch request that carries a page's widget data (DEF0879731).
27
+ // Since the proxy never touches the body bytes, the browser's own
28
+ // Content-Length stays numerically correct.
29
+ //
30
+ // `transfer-encoding` IS stripped: it describes the client->dev-server hop
31
+ // only, and undici throws `invalid transfer-encoding header` if it is set on
32
+ // an outgoing fetch (undici owns framing for the upstream hop). Same rationale
33
+ // as prod's h2-proxy, which strips host/connection/transfer-encoding/
34
+ // keep-alive/upgrade and passes content-length through untouched.
35
+ const STRIP_REQUEST_HEADERS = new Set([
36
+ 'host',
37
+ 'connection',
38
+ 'keep-alive',
39
+ 'transfer-encoding',
40
+ 'upgrade',
41
+ // undici rejects an outgoing `expect` header outright.
42
+ 'expect'
43
+ ]);
21
44
  const STRIP_RESPONSE_HEADERS = new Set([
22
45
  'transfer-encoding',
23
46
  'connection',
@@ -339,6 +339,21 @@ export async function createSimpleDevServer({
339
339
  // local dev tool — no graceful-drain requirement.
340
340
  const fastify = Fastify({logger: false, forceCloseConnections: true});
341
341
 
342
+ // Bind is wildcard (0.0.0.0), not loopback — macOS returns EACCES binding
343
+ // 127.0.0.1 on a privileged port (<1024), so :80 only works via wildcard.
344
+ // Reject anything not from the loopback interface here instead: local dev
345
+ // tool running unsandboxed customer code, must not be reachable from the LAN.
346
+ const LOOPBACK_ADDRESSES = new Set(['127.0.0.1', '::1', '::ffff:127.0.0.1']);
347
+ fastify.addHook('onRequest', async (req, reply) => {
348
+ if (!LOOPBACK_ADDRESSES.has(req.socket.remoteAddress)) {
349
+ return reply
350
+ .code(403)
351
+ .send(
352
+ 'Forbidden: this dev server only accepts connections from localhost.'
353
+ );
354
+ }
355
+ });
356
+
342
357
  // --- HMR client script ---
343
358
  // Served at a fixed path and injected into every rendered document (below) so
344
359
  // the browser opens the HMR WebSocket and full-reloads on rebuild. Null when