Skip to content

[Hackathon] fix(cli): endpoint URLs with credentials, ?query or #fragment pass validation, and ci init --project skips validation entirely #444

Closed as not planned

Description

@bagusardin25

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)

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 written

With --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: call assertValidEndpointUrl on the resolved value, so ci init validates the endpoint whether or not --project is given. It runs before any file write. The existing assertSafeWorkflowValue and 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 plain http://. 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-url fails 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 existing describe('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/.
    • makeHttpClient with a userinfo endpoint: fetchImpl is never called.
  • src/commands/ci.spec.ts: ci init with --project and each of not a url, ftp://…, https://user:pw@…, and https://host/#/, plus one --dry-run case. 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:

Confirmations

  • I have searched existing issues and this is not a duplicate.
  • I have provided my Discord identity above for reward coordination.

Activity

  1. fyZhang66 commented on Oct 20, 2026

    @fyZhang66
    Contributor

    Thanks for the report. The second half (ci init --project skipping validation) was fixed in 0.15.0; the --dry-run branch 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.

  2. added
    wontfix
    on Oct 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    wontfix

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions