Repository navigation
Conversation
Add one shared endpoint rule (an absolute https URL, or http on a loopback hostname) and apply it in every internal client before it sends. A value that fails the rule counts as unconfigured, so each caller keeps its existing failure result and sends no request.
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Executive SummaryThe bouncer client now derives its request URL from Assumptions: Files Reviewed (3 files)
Previous Review Summaries (3 snapshots, latest commit 0cf0229)Current summary above is authoritative. Previous snapshots are kept for context only. Previous review (commit 0cf0229)Status: No Issues Found | Recommendation: Merge Executive SummaryThe follow-up commit adds an absolute-path guard and an origin-equality check to Assumptions: Files Reviewed (2 files)
Previous review (commit c236f97)Status: No Issues Found | Recommendation: Merge Executive SummaryThe follow-up commit routes every request path through Assumptions: Files Reviewed (9 files)
Previous review (commit b238ca4)Status: No Issues Found | Recommendation: Merge Executive SummaryThe new shared endpoint rule is applied consistently across every changed client, each caller keeps its existing unconfigured result and sends no request, and the added tests cover both accepted and rejected endpoint shapes; I found no defects in the changed code. Assumptions: Files Reviewed (21 files)
Reviewed by deepseek-flash-latest · Input: 63.9K · Output: 8.3K · Cached: 591.4K Review guidance: REVIEW.md from base branch |
eshurakov
left a comment
There was a problem hiding this comment.
Bot - No critical issues found. Two minor, actionable notes:
-
packages/web-shared/src/lib/ai-gateway/worker-admin-fetch.ts:26validates the endpoint withparseInternalServiceUrlbut then discards the parsed URL and still builds the request by string concatenation (`${workerUrl}${path}`). An accepted value with a trailing slash or a path (e.g.https://worker.example.com/) yieldshttps://worker.example.com//admin/x. Build the request from the parsed URL so a validated value cannot produce a malformed endpoint. -
packages/web-shared/src/lib/notifications-worker-client.ts:55and:251report "NOTIFICATIONS_WORKER_URL is not configured" when the variable is set but falls outside the new rule. That is now a different failure than an unset value; logging an explicit unsupported-endpoint reason (asusage-record-clientand the Enkrypt handoff already do) would let operators tell the two apart.
|
bot: Both notes are addressed in c236f97.
Tests: |
eshurakov
left a comment
There was a problem hiding this comment.
Bot - Minor hardening gap in parseInternalServiceEndpoint: it validates the base URL but then resolves path with new URL(path, base), so a path that is not a single-slash-absolute reference still escapes the validated host. parseInternalServiceEndpoint("https://worker.example.com", "//evil.example.org/admin") returns https://evil.example.org/admin, which would send the Bearer INTERNAL_API_SECRET to that host. Every current caller passes a hardcoded path, so this is not exploitable today, but the helper exists to guarantee the request URL derives from the accepted base. Reject any path that does not start with exactly one / (or url-encode/throw) before resolving, and add a //host case to internal-service-url.test.ts.
`parseInternalServiceEndpoint` now accepts a request path only when it is absolute on the endpoint that passed the transport rule, and it checks that the resolved URL keeps that endpoint's origin. A path outside that form counts as unconfigured, so every caller keeps its existing failure result and sends nothing. Tests cover the accepted form and the rejected forms.
|
bot: Fixed in
Verification at
|
eshurakov
left a comment
There was a problem hiding this comment.
Bot - Reviewed the shared endpoint-validation change; no critical issues found. One actionable, non-blocking finding:
packages/web-shared/src/lib/bouncer/client.tspostWithResultstill assembles the request URL as${BOUNCER_URL}${path}. The new guards inpostanddeliverWireBodyvalidateBOUNCER_URLthroughparseInternalServiceUrlbut never normalize it, so a configured value with a trailing separator (e.g.https://bouncer.kiloapps.io/) produceshttps://bouncer.kiloapps.io//api/v1/decide, which the worker may not route. Build the URL withparseInternalServiceEndpoint(BOUNCER_URL, path)(as the worker admin and notifications clients now do) or strip the trailing separator, so the change's "never assembled by concatenation" guarantee actually covers the bouncer client.
The bouncer request URL now comes from the shared endpoint helper, as it already does in the worker admin and notifications clients, so the URL derives from the value the transport rule accepted. The unconfigured case is a tagged result, so each caller keeps its existing failure value without a second configuration check. Both helpers accept a null value, because the configured bouncer value is null when it is unset.
|
bot: Addressed the review remark on
Verification on 0de630f:
|
Evidence
Evidence: demonstrated — a real-socket harness drove the worker admin client, the notifications worker client, the gateway metrics emitter and the bouncer client from this head against a local HTTP listener. An accepted endpoint delivered its request at the single-separator path with its credential header; an endpoint outside the rule produced the client's existing unconfigured result and the listener received nothing.
Change
packages/web-shared/src/lib/internal-service-url.tsexportsparseInternalServiceUrl. An endpoint is used only when its value is an absolutehttpsURL, or anhttpURL on a loopback hostname (localhost,127.0.0.1,[::1]).parseInternalServiceEndpoint, which resolves a request path against the parsed endpoint. Only an absolute path on that endpoint is used, so a request URL always derives from the value the rule accepted. The worker admin client, the notifications worker client (dispatch and glanceable refresh), benchmark profile registration, both auto-routing decision fetchers and the bouncer client build their request URL through it, so a request URL is never assembled by concatenation and an accepted value that ends in a separator still produces one separator.postanddeliverWireBodykeep their existing values (null, andbouncer_not_configured) without a second configuration check.packages/web-shared/src/lib/ai-gateway/usage-publisher.tsuses the shared rule instead of its private copy, so one implementation serves every internal client. The existing publisher suite is the differential: behaviour is unchanged.null,{ kind: 'unavailable' }, the500unconfigured body,bouncer_not_configured, or its existing thrown error).Verification
The harness starts a listener bound to
0.0.0.0, drives the clients from this head, and reports what the listener received and which credential headers arrived. The accepted endpoint is the loopback address; the endpoint outside the rule is this machine's non-loopback address, so both cases use a real socket. Each configured endpoint ran in its own process, because the endpoints are read once at module load./admin/x200500unconfigured error/internal/v1/dispatch/ingest/api-metrics/api/v2/credit-event,/api/v1/usage-event,/api/v1/decide,/api/v1/charge-decide,/api/v1/signup-decide,/api/v1/releasedelivered: true; each caller returned its parsed verdictbouncer_not_configured, andnullfrom each verdict callerThe bouncer case ran in its own two processes with
--conditions=react-server, so the client'sserver-onlyguard resolves in a plain script instead of a bundler.Test suites, from the repository root:
pnpm --filter web exec jest internal-service-url worker-admin-fetch api-metrics.server auto-routing-benchmark-admin auto-routing-decision auto-routing-admin-client usage-record-client payer-state usage-region notifications-worker-client bouncer/client usage-publisher— 13 suites, 383 tests, all passing.pnpm --filter web exec jest packages/web-shared/src/lib/bouncer/client.test.ts packages/web-shared/src/lib/internal-service-url.test.ts— 2 suites, 119 tests, all passing. These pin the bouncer request URL for an accepted endpoint, including one that ends in a separator, and pin that a value outside the rule sends nothing.pnpm --filter @kilocode/web-shared run typecheck— clean.pnpm -w exec oxlint --config .oxlintrc.json packages/web-shared/src/lib— clean.Production prerequisites
O11Y_SERVICE_URLand of each worker admin endpoint that these clients call is anhttpsURL.Proxy answers
The owner's proxy gave these answers in the owner's place.
Answer: Also harden the sibling sites
Confidence: 0.60 · Precedent: Fix the root cause and the class of the issue on every affected surface: session 00eb2a1d3e4b, "if anything repeats the same mistake over and over again, fix the class"; a related bug in the same PR's area belongs in that PR (session a2f7aef14d65, "fix in the existing pr").