跳转到内容
简体中文

redactedUrlLabel

此内容尚不支持你的语言。

redactedUrlLabel(value): string

Defined in: src/util/RedactUrlCredentials.ts:433

The loggable identity of value: scheme, host, port and path, with the userinfo and the query string removed.

Keeping the path matters — it is what tells two connections to the same host apart (/ws/orders vs /ws/audit), so reducing to the origin alone would trade away the whole diagnostic value of the line. The query is dropped rather than kept for the same reason the userinfo is: a WebSocket endpoint is commonly authenticated with a ?token=….

Unlike redactUrlCredentials this normalises (the parse is a real URL parse), which is fine for a label but not for echoing back what an operator typed.

The label shows no credential the v0.17.0 label kept out, and names no host that is not the URL’s own. Three rules, in this order:

  1. Every userinfo is masked before anything is parsed or cut, by the scan of redactUrlCredentials — to the last @ before the next ://, across /, ?, # and commas, since a pasted password carries all four (#1458). A list entry that does not begin with a scheme:// is masked to its own last @: user:password@host, the server form memjs takes and nats.js accepts, which WHATWG would read as the scheme user: and printed as user://password@host.
  2. Nothing behind the first ? or # is shown. A query is where a token goes when the userinfo does not carry one, and v0.17.0 never printed one. When that ? or # lies inside a masked userinfo — a password that carries it, or a query token with an @ in it, which read the same — the label ends at the ***.
  3. A host is named only if every reading agrees on it. When a masked userinfo contains a / in front of which WHATWG reads a valid authority (https://host/a@b, amqp://user:12/PW1@host), the same bytes are a URL for that authority with an @ in its path, and also a password ending in /a or /PW1: the host behind the @ is wrong for the first reading and the one in front of the / is a password for the second, so the label ends at the *** and names neither. Where WHATWG reads no valid authority there (user:pa/PW1@host — pa is no port) the scan’s reading is the only one, and its host is named. A userinfo in which a host stands in front of a comma may have taken earlier entries of a list with it (nats://u:p@h1,v:q@h2 is one URL to WHATWG and two to a server list), so its ***@ stays in the label; user:a in amqp://user:a,b@host is no host, and that comma is the password’s.

Only a value that is unambiguously one URL is rebuilt from its parse — it begins with scheme://, holds no , and no second ://, and every mask in it hid a userinfo only. Two shapes reach this function as a matter of course through BrokerActor’s lifecycle events and are not one: the scheme-less entry above, and a joined server list, which the parser can take for one URL with the rest of the list for a path (nats://u:p1@h1,nats://u:p2@h2 is the host h1,nats and the path //u:p2@h2, and the nats:// the JetStream actors put in front of a list does the same with no comma at all). Those are cut instead, the list as a whole, since a query is free to contain commas. A masked entry keeps *** where its credential was (***@h1:4222), and the list keeps its shape, so an operator still sees which servers it names. A value with no credential anywhere (<unknown>, localhost:4222) comes back as it is, minus any query, so the function stays total.

string

string