Repository navigation
fix(ui-server): post-#1891 access policy and WS upgrade hardening - #1898
Conversation
SummaryThe following content is AI-generated and provides a summary of the pull request: fix(ui-server): Reject ports in
|
There was a problem hiding this comment.
The PR is well-structured and the three changes (whitespace-aware nonEmpty, trailing-dot fix for localhost.:80, and port-rejection in allowedHosts) are each correct and well-tested. The main concern is in ConfigurationSchema.ts: the port-detection logic in the new allowedHosts refine function duplicates knowledge that already lives in normalizeHost/isValidPort, using two independent regex patterns instead of deriving port-absence from the normalization result itself. This creates a fragile maintenance surface where edge cases (e.g. leading-zero ports, future port-format changes) could silently diverge between the schema validator and the runtime matcher.
PR Bot Information
Version: 1.22.9
- LLM:
anthropic--claude-4.6-sonnet - File Content Strategy: Full file content
- Correlation ID:
7150de27-1dc9-4631-9e64-b0cfadf1ef50 - Agent Instructions:
- Event Trigger:
pull_request.opened
…edges - ConfigurationSchema: reject allowedHosts entries that carry a port (e.g., 'gateway.example.com:8080', '[::1]:8080'). Runtime host matching strips ports, so a port-bearing entry was silently equivalent to its host-only form. Operators are now forced to spell out host-only entries at config load time, matching how matching actually works. - UIServerNet: normalizeHost strips a trailing dot after the colon split rather than from the whole input, so a Host header like 'localhost.:80' now resolves to 'localhost' instead of leaving the trailing dot intact and failing the allowlist match. - UIServerAccessPolicy: nonEmpty treats whitespace-only forwarded values as absent, and hasForwardedHeaders consumes nonEmpty so the two helpers agree. A whitespace-only X-Forwarded-Proto no longer flips forwardedHeadersPresent to true and triggers an Ambiguous* denial. Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
67512ea to
89a305c
Compare
…ion writes The onSocketError listener was previously attached only after the prologue and bad-header guards had already written their rejection responses, and was removed before the auth-failure rejection write. A client TCP-reset between an upgrade event and the destroy callback could fire 'error' on the Duplex socket with no listener, which Node escalates to an unhandled exception and crashes the process. The listener is now attached at the top of the upgrade handler and only removed once webSocketServer.handleUpgrade takes ownership of the socket. All three rejection paths (bad upgrade headers, prologue failure, auth failure) keep the listener until socket.destroy(), neutralising the DoS vector. Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
…ded parsing - Schema: split UIServerListenOptions validation so non-object values surface 'must be a non-array object' instead of the misleading 'accessPolicy must be configured under uiServer' message. - Forwarded parser: unescape RFC 7230 quoted-pair sequences inside double-quoted Forwarded parameter values. - getForwardedClientAddress: propagate forwarded.kind === 'error' before the trustedProxy gate, matching getForwardedProtocol and getForwardedHost (no behavioral change today; closes a latent asymmetry if the upstream untrusted-peer gate is reordered). - UIServerAccessCache: document identity-based cache invalidation for trustedProxies; reload flows must construct a new configuration. - getForwardedProtocol / getForwardedHost: distinguish length === 0 (new InvalidForwardedProtocol / InvalidForwardedHost reasons) from length > 1 (existing Ambiguous reasons), matching the existing InvalidForwardedClient / AmbiguousForwardedClient pattern. Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
Summary
Follow-up to #1891 consolidating post-merge review findings: a high-severity DoS in the WebSocket upgrade rejection path, an
allowedHostsschema gap, and several hardening items in the forwarded-header parser and configuration validation.Changes
Security
errorlistener at the top of the handler instead of after the rejection writes. A client TCP-reset between an upgrade event and a rejection write previously fired'error'on theDuplexsocket with no listener, which Node escalates to an unhandled exception — a process-level DoS reachable by any unauthenticated client.Configuration validation
accessPolicy.allowedHostsentries containing a port now fail schema validation at config load. Runtime matching was already port-agnostic, so runtime behavior is unchanged.UIServerListenOptionssplits object-shape validation from theaccessPolicyrejection so non-object values surface'must be a non-array object'instead of the misleading'accessPolicy must be configured under uiServer'message.Forwarded-header parser
Forwardedparameter values: RFC 7230 quoted-pair sequences inside double-quoted values are now unescaped.X-Forwarded-Proto/X-Forwarded-Host: comma-only inputs (e.g.,,,) are denied with newinvalid-forwarded-protocol/invalid-forwarded-hostreasons, mirroring the existinginvalid-forwarded-clientpattern. Multi-value inputs keep theambiguous-*reasons.nonEmpty/hasForwardedHeadersalign on a whitespace-aware empty check. Whitespace-only forwarded values (e.g.X-Forwarded-Proto: ' ') are treated as absent.getForwardedClientAddresspropagatesforwarded.kind === 'error'before thetrustedProxygate, matchinggetForwardedProtocolandgetForwardedHost. No current behavior change; closes a latent asymmetry.Host normalization
normalizeHoststrips a trailing dot from the host part after the colon split.Host: localhost.:80now resolves tolocalhostand matchesallowedHosts: ['localhost']instead of being denied ashost-not-allowed.Documentation
UIServerAccessCacheJSDoc documents identity-based cache invalidation: mutatingaccessPolicy.trustedProxiesin place will not refresh the normalized set; reload flows must construct a new configuration.Defaults that change observable behavior
accessPolicy.allowedHostsentries containing a port fail config validation at load time. Strip the port suffix from existing entries; runtime matching is unchanged.Validation
pnpm typecheck,pnpm lint,pnpm format,pnpm build,pnpm test— 0 errors, 0 warnings, 0 fail, 6 skipped.