fix(matrix): guard transport new URL() against malformed input#109759
fix(matrix): guard transport new URL() against malformed input#109759ZengWen-DT wants to merge 1 commit into
Conversation
Wrap user-controlled URL parsing in Matrix transport with a shared helper that throws a stable Invalid URL error instead of leaking URL constructor TypeErrors from malformed homeservers, redirect locations, and endpoints. Co-authored-by: Cursor <[email protected]>
|
Codex review: needs changes before merge. Reviewed July 17, 2026, 3:24 AM ET / 07:24 UTC. Summary PR surface: Source +8, Tests +70. Total +78 across 2 files. Reproducibility: yes. from source and the submitted before/after harness: malformed Matrix URLs reach these constructors and produce parser errors. The remaining disclosure is source-reproducible because the patch retains Node's documented Review metrics: none identified. Merge readiness Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch. Rank-up moves:
Risk before merge
Maintainer options:
Copy recommended automerge instructionNext step before merge
Security Review findings
Review detailsBest possible solution: Throw a stable Matrix URL error without retaining raw parser state, or preserve only sanitized metadata such as a safe error code, then test the complete inspected error and cause chain for secret absence across homeserver and redirect inputs. Do we have a high-confidence way to reproduce the issue? Yes from source and the submitted before/after harness: malformed Matrix URLs reach these constructors and produce parser errors. The remaining disclosure is source-reproducible because the patch retains Node's documented Is this the best way to solve the issue? No as written. Centralizing defensive URL parsing is the right boundary, but retaining the unsanitized native cause conflicts with the stated non-disclosure objective. Full review comments:
Overall correctness: patch is incorrect AGENTS.md: found and applied where relevant. Codex review notes: model internal, reasoning high; reviewed against e01027dd28a8. Label changesLabel changes:
Label justifications:
Evidence reviewedPR surface: Source +8, Tests +70. Total +78 across 2 files. View PR surface stats
Security concerns:
Acceptance criteria:
What I checked:
Likely related people:
What the crustacean ranks mean
Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics. How this review workflow works
|
What Problem This Solves
Fixes an issue where Matrix transport callers would receive an uncaught
TypeError: Invalid URLwhen given malformed homeserver URLs, redirectLocationheaders, or absolute API endpoints, instead of a controlled application error.Why This Change Was Made
Matrix transport now parses user-controlled URLs through a shared
parseMatrixUrlhelper that wrapsnew URL()in try/catch and throws a stableError("Invalid URL")with the native parse failure retained ascause, matching the defensive pattern already used in the same file bywithoutMatrixStateAfterSyncParam. Valid homeserver, redirect, and endpoint handling is unchanged. Risk note: this only hardens URL parsing at transport entry points; it does not change SSRF policy decisions once a URL parses successfully.User Impact
Matrix channel setup and API calls now fail with a predictable typed error for malformed URLs, without echoing credential-bearing homeserver strings into diagnostics or logs.
Evidence
Before (upstream/main):
Premise (sibling pattern in the same file):
withoutMatrixStateAfterSyncParamalready wrapsnew URL(rawUrl)in try/catch without reflecting the supplied URL.After (this branch):
Harness (real exported functions, no mocks; redirect case uses a real loopback HTTP server):
Focused tests:
What was not tested: live Matrix homeserver setup with a real Synapse/Dendrite instance; the local harness proves transport entry points now fail closed with a stable non-disclosing error instead of a URL constructor
TypeError, including on redirectLocationheaders from a real HTTP server.AI-assisted: Cursor Composer; proof run manually on this machine.