-
Notifications
You must be signed in to change notification settings - Fork 2
fix(tlsnotary): hostname-based scheme, default /tlsn path for public … #819
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: stabilisation
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,19 +170,21 @@ export function extractDomainAndPort(targetUrl: string): { | |
|
|
||
| /** | ||
| * Build a public WebSocket URL from a base HTTP(S)/WS(S) URL and a local port. | ||
| * Path mode: when the base URL has a path, route through a reverse proxy at | ||
| * `url.host` (port preserved) that maps `<path>/<port>` to the local port | ||
| * (single nginx rule). No-path mode: connect directly to `url.hostname` on | ||
| * the target port. | ||
| * Local bases keep direct ws://localhost:<port> URLs for development. Public | ||
| * bases always route through a TLS reverse proxy path, defaulting to | ||
| * /tlsn/<port>/ when no explicit path is provided. | ||
| */ | ||
| export function buildWsUrl(base: string, port: number | string): string { | ||
| const url = new URL(base) | ||
| const secure = url.protocol === "https:" || url.protocol === "wss:" | ||
| const wsScheme = secure ? "wss" : "ws" | ||
| const path = url.pathname.replace(/\/+$/, "") | ||
| return path | ||
| ? `${wsScheme}://${url.host}${path}/${port}/` | ||
| : `${wsScheme}://${url.hostname}:${port}` | ||
| const isLocal = | ||
| url.hostname === "localhost" || url.hostname === "127.0.0.1" | ||
|
|
||
| if (isLocal) { | ||
| return `ws://${url.hostname}:${port}` | ||
| } | ||
|
|
||
| const path = url.pathname.replace(/\/+$/, "") || "/tlsn" | ||
| return `wss://${url.hostname}${path}/${port}/` | ||
| } | ||
|
Comment on lines
+179
to
188
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Any base URL whose hostname is a private-network address (e.g. |
||
|
|
||
| /** | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isLocalcheck omits the IPv6 loopback address::1. When a base URL likehttp://[::1]:53550is passed,url.hostnameis::1, which falls through to the public branch and produceswss://::1/tlsn/7047/. That string is an invalid URL (IPv6 literals in URLs require brackets), so any downstreamnew URL(...)call or WebSocket constructor on the result will throw.