Skip to content

fix(repeater): answer undeliverable target URLs instead of dropping the ack - #784

Open
aborovsky wants to merge 10 commits into
masterfrom
fix/malformed-url-delivery
Open

aborovsky wants to merge 10 commits into
masterfrom
fix/malformed-url-delivery

Conversation

@aborovsky

@aborovsky aborovsky commented Sep 23, 2026 •

Copy link
Copy Markdown
Contributor

No description provided.

…ing the ack

When the bridge sends a request event whose payload cannot be constructed
into a Request, the throw previously escaped the event listener unanswered,
so the bridge burned its full timeout and reported a malformed URL as
repeater unavailability, flooding Sentry with Invalid URL. errors.

requestReceived now wraps only the construction step and, on failure, acks
the bridge with a { protocol, protocolError: { code, message } } variant —
distinct from an execution failure, which keeps its existing { message,
errorCode } reply. The rejection is a logger.error, not a captureException,
so these stop being Sentry events. The command hub is not invoked for a
payload that could not be constructed.
…e path

Replace the two disagreeing URL parsers on the request-execute path with a
single string-only TargetUrl decomposition that never throws:

- transformScript and handleResponseScript no longer call new URL(), which
  used to throw on an authority defect and short-circuit an otherwise
  deliverable request into ERR_INVALID_URL before libcurl ever saw it.
- configureCurl, resolveProxy and shouldApplyKerberos drop the legacy
  node:url parse(); all five consumers now share TargetUrl and agree on one
  behaviour for an unparseable authority (undefined hostname => skip virtual
  script, response script, proxy and Kerberos).
- Hostnames are raw-lowercased with no IDNA/punycode (behaviour change for
  internationalised domains in virtual-script and proxy-domain matching).
- The raw path is preserved byte-for-byte (PATH_AS_IS), carried over from the
  former buildRawPath.
Probe the six authority defects the WHATWG parser used to reject. Each now
travels through TargetUrl to libcurl and is answered with a returned
Response carrying libcurl's CURLE_URL_MALFORMAT failure — never a throw,
never a hang, and never the client-side ERR_INVALID_URL short-circuit. This
pins the observed behaviour on the supported Node runtime (engines: >=22
<=24) as a regression guard for the predicate relaxation.
Drop the WHATWG new URL() gate from Request. bright-cli and the bridge now
agree on which URLs are deliverable: any non-blank (after trim) URL is
accepted and travels to libcurl, so no shape the bridge dispatches is fatal
in the CLI constructor. The one surviving rejection — a blank URL — carries
the offending value through a userinfo-redacting formatter so credentials
never reach logs or Sentry.

Also update the malformed-payload launcher tests to use a blank URL, the
only shape that still fails construction after this relaxation.
@aborovsky aborovsky self-assigned this Sep 24, 2026
@aborovsky aborovsky added the Type: enhancement New feature or request. label Sep 24, 2026
@aborovsky

Copy link
Copy Markdown
Contributor Author

Summary

A Request the repeater cannot deliver used to throw in the constructor, and the throw escaped the Socket.IO event listener unanswered — so the bridge waited out its full timeout and reported a malformed target URL as repeater unavailability, flooding Sentry with Invalid URL. noise. Scanners deliberately probe malformed request-targets, so this was a steady stream.

This change makes an undeliverable URL a structured, immediate answer and lets every deliverable URL reach libcurl.

What changed

  • Answer the ack instead of dropping it. When a request event payload cannot be constructed, requestReceived now acks a { protocol, protocolError: { code, message } } variant — distinct from an execution failure, which keeps its { message, errorCode } reply. It is logged with logger.error, not reported to Sentry.
  • One non-throwing URL decomposition. A new TargetUrl replaces the two disagreeing URL parsers on the execute path (new URL() and the legacy node:url parse()). All five consumers — curl configuration, virtual-script lookup, response-script lookup, proxy resolution, Kerberos gating — now share it and agree on one behaviour for an unparseable authority (skip host-keyed behaviour rather than coercing a null hostname into a RegExp.test).
  • Relax the predicate. The constructor no longer rejects on a WHATWG parse failure; any non-blank (after trim) URL is accepted, so no shape the bridge dispatches is fatal in the CLI. The one surviving rejection — a blank URL — carries the offending value through a userinfo-redacting formatter so credentials never reach logs.

Intentional behaviour change

Hostnames are now raw-lowercased with no IDNA/punycode conversion. Virtual-script matching and proxy-domain matching therefore key on the raw hostname (☃.net stays ☃.net instead of xn--n3h.net). This is deliberate and applies only to internationalised-domain matching.

libcurl malformed-URL contract (verified)

Probed on the supported runtime (engines: >=22 <=24, Node 24). Each of the six authority defects the old WHATWG gate rejected now travels through TargetUrl to libcurl and is answered with a returned Response carrying libcurl's CURLE_URL_MALFORMAT failure (message: "Request failed: URL using bad/illegal format or missing URL") — never a throw, never a hang, and never the client-side ERR_INVALID_URL short-circuit. Pinned as a regression guard in HttpRequestExecutor.spec.

Verification

  • npm run test:unit — 323 passing (26 suites)
  • npm run lint — clean
  • npm run build — success

aborovsky and others added 2 commits September 24, 2026 10:05
…request ack

Replace the ad-hoc 'ERR_MALFORMED_REQUEST' string with a new
RepeaterErrorCodes.MALFORMED_REQUEST enum member, so the per-request
protocolError ack code is drawn from the same enum as the other repeater
error codes. The value is carried on the request ack only, never on the
deploy-time error event, so it does not affect critical-error handling.
@aborovsky

aborovsky commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor Author
  • E2E should succeed
  • Recheck if merge possible after 20th of October

@aborovsky aborovsky added Type: refactoring Changes in the way the code works internally without changing the output produced. and removed Type: enhancement New feature or request. labels Sep 29, 2026
Comment thread src/RequestExecutor/Request.ts Resolved
Rename Request.validateUrl to assertUrlNotBlank: the only check left is rejecting a blank url.
Remove D3/D4 decision labels, finding and task references, and comments
that restate the code. Flatten TargetUrl.spec nested describes to method
names.
Comment thread src/RequestExecutor/TargetUrl.ts Resolved

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Type: refactoring Changes in the way the code works internally without changing the output produced.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants