Repository navigation
Description
Verified against (commit SHA or released version)
commit 988c035 (v0.14.0); Node 22.18.0, Windows 11
Discord Username / User ID
bagusardin_
What does this improvement do?
#18 made a bad API endpoint fail fast with a VALIDATION_ERROR (exit 5) instead of a retried fetch failed / UNAVAILABLE. Two gaps remain.
1. assertValidEndpointUrl accepts URL parts the CLI can never use. It checks only that the value parses and is http(s). Userinfo, a query, and a fragment all pass:
$ testsprite auth status --endpoint-url "https://user:[email protected]"
Error: Request cannot be constructed from a URL that includes credentials: https://user:[email protected]/api/cli/v1/me
Service is temporarily unavailable. The CLI retries with exponential backoff; if this persists, report it.
# exit 10, after 4 attempts (3 backoff sleeps)- The embedded password is printed in clear. It appears in the error message (stderr in text mode, the JSON envelope in
--output json) and in every--debugline ("url":"https://user:s3cretPW@…"). CI logs keep both. - The cause is reported as a service outage. undici refuses to build a request from a URL with credentials, so a retry can never succeed. This is the same misleading path Malformed
--endpoint-urlfails with an opaque "Invalid URL" / retried "fetch failed" instead of a clear validation error #18 closed for other malformed endpoints.
Query and fragment don't fail at all. They send the API key to the wrong path, because facadeBaseUrl appends /api/cli/v1 to the raw string:
--endpoint-url |
Request the server receives |
|---|---|
http://127.0.0.1:47811?x=1 |
GET /?x=1/api/cli/v1/me (the facade path lands inside the query string) |
http://127.0.0.1:47811/#frag |
GET / (the facade path is cut off as a fragment) |
The user then gets whatever the server root returns: an auth error, a not-found, or a non-JSON response. Nothing says "your endpoint URL is wrong". Realistic sources: a URL copied from a browser (https://staging.example.com/#/), tracking parameters, or a staging host behind HTTP basic auth.
2. ci init --project never runs the endpoint check. Without --project, ci init builds an API client to auto-detect the project, so the #18 guard runs:
$ testsprite ci init github --endpoint-url "ftp://staging.example.com"
# exit 5 VALIDATION_ERROR, no file writtenWith --project, no client is built, so nothing validates the endpoint. Whatever was given is pinned into the committed workflow, and the command exits 0:
$ testsprite ci init github --project proj_123 --endpoint-url "not a url"
Wrote .github/workflows/testsprite.yml … # exit 0, contains endpoint-url: "not a url"
$ testsprite ci init github --project proj_123 --endpoint-url "ftp://staging.example.com"
# exit 0, contains endpoint-url: "ftp://staging.example.com"
$ testsprite ci init github --project proj_123 --endpoint-url "https://user:[email protected]"
# exit 0, contains endpoint-url: "https://user:[email protected]"
# then prints: "2. Commit and push .github/workflows/testsprite.yml"The workflow is red on its first run, which is the "fails in CI with nothing explaining why" outcome the existing ci init endpoint warning is there to prevent. In the userinfo case, the CLI also tells the user to commit a password into their repository.
Expected: any endpoint the CLI cannot use fails before any request or file write. It returns the same VALIDATION_ERROR (exit 5, details.field: "endpoint-url") as other malformed endpoints, the error names the offending part, and the password is never echoed. This must hold on every path that accepts an endpoint, ci init --project included.
Who it hurts: CI users and coding agents. They get an exit 10 they're told to retry, a key sent to /, or a workflow that fails only after it has been pushed.
Details / implementation notes
Proposed approach. No new dependencies, no --output json shape change, and no new outbound calls:
-
src/lib/client-factory.ts,assertValidEndpointUrl: after the existing parse and scheme checks, reject:parsed.username || parsed.password: "must not contain credentials (user:password@)". The message must not include the raw URL.- a non-empty
parsed.search, or a raw value containing?: "must not contain a query string". - a non-empty
parsed.hash, or a raw value containing#: "must not contain a fragment".
The same field and exit code are used as today. The existing "is not a valid URL" message, which echoes the raw value, will mask any
user:pass@before echoing it, so an unparseable URL with credentials doesn't leak them either. -
src/commands/ci.ts,resolveEndpointUrl: callassertValidEndpointUrlon the resolved value, soci initvalidates the endpoint whether or not--projectis given. It runs before any file write. The existingassertSafeWorkflowValueand the loopback/private-host warning stay as they are. -
Unchanged: a path prefix (
https://host/prefix,https://host/api/cli/v1), trailing slashes, private and localhost hosts, and plainhttp://. The validator's existing contract "NOT an SSRF guard; private hosts are legitimate" (client-factory.ts) is untouched. -
Exit codes: the affected inputs move to 5, the code Malformed
--endpoint-urlfails with an opaque "Invalid URL" / retried "fetch failed" instead of a clear validation error #18 set for an invalid endpoint. Every one of them already fails today (an exit 10 outage, a wrong-path request, or a broken workflow), so no working configuration changes behavior.
Test plan. Mock-based, written to fail first on 988c035:
src/lib/client-factory.test.ts, extending the existingdescribe('assertValidEndpointUrl'):- userinfo with a password, with a username only, and in an unparseable URL. Asserts exit 5,
field: endpoint-url, and that the message does not contain the password. ?x=1, a bare?,#frag, and/#/. Asserts exit 5.- Still accepted: the existing allow-list plus
https://host/prefix/. makeHttpClientwith a userinfo endpoint:fetchImplis never called.
- userinfo with a password, with a username only, and in an unparseable URL. Asserts exit 5,
src/commands/ci.spec.ts:ci initwith--projectand each ofnot a url,ftp://…,https://user:pw@…, andhttps://host/#/, plus one--dry-runcase. Asserts exit 5 and that the injected fs never writes the workflow. A valid custom endpoint is still pinned as today.
A fix with these tests is ready on a local branch (every rejection case fails on 988c035 and passes with the fix). I'll open the PR as soon as this is triaged and assigned.
Duplicate check: searched open and closed issues and PRs for endpoint, endpoint-url, userinfo, credentials in URL, query, fragment, and ci init. Closest:
- Malformed
--endpoint-urlfails with an opaque "Invalid URL" / retried "fetch failed" instead of a clear validation error #18 (closed): added the scheme and parse check this extends. - [Hackathon] setup should validate endpoint-url before key verification #146/[Hackathon] setup should validate endpoint-url before key verification #147 (closed): setup validation order.
- [Hackathon] fix(http): on a corporate network the CLI fails every command, then blames the wrong thing (fetch failed, invalid key, no credits) #433: transport-error wording for a reachable-looking endpoint. Different layer: these URLs are rejected before any request.
- SSRF and Path Traversal via Server-Controlled Failure Bundle Metadata #59: bundle download URLs, a different surface.
Confirmations
- I have searched existing issues and this is not a duplicate.
- I have provided my Discord identity above for reward coordination.
Activity
fyZhang66 commentedon Oct 20, 2026
Thanks for the report. The second half (
ci init --projectskipping validation) was fixed in 0.15.0; the--dry-runbranch does not send requests, so nothing is at stake there. For the first half, an endpoint URL carrying userinfo, a query or a fragment is rejected by fetch itself, just with a less precise error, and we have no real case of someone configuring one. We're not taking a change for it. Closing as won't fix.