Skip to content

[CFX-7608] Reject a non-http/https URL in dr auth set-url - #912

Open
chasdr wants to merge 4 commits into
mainfrom
chas/CFX-7608-seturl-scheme
Open

[CFX-7608] Reject a non-http/https URL in dr auth set-url#912
chasdr wants to merge 4 commits into
mainfrom
chas/CFX-7608-seturl-scheme

Conversation

@chasdr

@chasdr chasdr commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

PR 3 of 3: #776 was PR 1, #911 is PR 2

Summary

dr auth set-url accepted any URL scheme and wrote it straight into drconfig.yaml, so dr auth set-url ftp://host stored a dead endpoint that only failed later at read time with a vaguer error. It now rejects a non-http/https URL at write time and exits non-zero. A bare host like app.datarobot.com is still accepted and defaults to https.

Notes for review

The http/https rule is one helper, config.RequireHTTPScheme, applied at both write paths that persist the endpoint: SetURLToConfig (set-url arg, the interactive picker, stdin, and dr auth login <url>) and SaveURLToConfig (the template-setup custom-host picker). SchemeHostOnly stays scheme-agnostic because export and GetBaseURL share it, so the rule sits on top rather than inside it.

Output

$ dr auth set-url ftp://app.datarobot.com
ERROR unsupported URL scheme "ftp", use https://
$ echo $?
1

Technical Changes

  • internal/config/api.go: add RequireHTTPScheme. SetURLToConfig and SaveURLToConfig both call it after SchemeHostOnly.
  • internal/auth/auth.go: ValidateEndpoint delegates its inline scheme check to the same helper. message byte-identical, no duplication.
  • cmd/auth/seturl/cmd.go: a bad arg prints the reason and exits non-zero instead of silently opening the picker. Run becomes RunE with SilenceErrors/SilenceUsage.
  • docs/commands/auth.md: note the rejection under set-url.
  • tests: RequireHTTPScheme table, both writers' scheme rows, set-url arg exits non-zero.

Breakdown

  • code: +43 / -17
  • tests: +84 / -0
  • docs: +4 / -0

Note

Low Risk
Localized URL validation on auth/config write paths with tests; no change to token handling or API auth flow beyond earlier rejection of bad endpoints.

Overview
dr auth set-url now rejects endpoints whose scheme is not http or https at configuration time, with a clear error and non-zero exit, instead of saving unusable values (e.g. ftp://) into drconfig.yaml or falling back to the interactive picker when the user passed an explicit bad URL.

Validation is centralized in config.RequireHTTPScheme, applied after normalization in SetURLToConfig and SaveURLToConfig (set-url, login, template setup). ValidateEndpoint uses the same helper. Bad schemes in the interactive picker still re-prompt because the error wraps ErrInvalidURL. Bare hosts still default to https via SchemeHostOnly.

Docs under set-url describe the rejection behavior; tests cover the helper, both write paths, and the set-url command argument path.

Reviewed by Cursor Bugbot for commit e8e4738. Configure here.

Why:
`dr auth set-url ftp://host` (and file://, gopher://, and the like) wrote
the bad scheme straight into drconfig.yaml. The endpoint only failed later
at read time, with a less obvious error. SchemeHostOnly normalizes but has
to stay scheme-agnostic because export and GetBaseURL share it, so the
http/https rule had no home on the write path.

Changes:
- add config.RequireHTTPScheme(baseURL), the http/https rule as one helper.
  SetURLToConfig calls it after SchemeHostOnly, so every set-url write path
  (arg, picker, stdin, and dr auth login <url>) rejects a bad scheme before
  it lands in the config file. A bare host still resolves to https.
- auth.ValidateEndpoint delegates its inline scheme check to the same
  helper. Message is byte-identical, no duplication.
- dr auth set-url <arg> now prints the reason and exits non-zero on an
  invalid arg instead of silently opening the interactive picker. Run
  becomes RunE, with SilenceErrors/SilenceUsage to match the other auth
  subcommands.
@chasdr
chasdr requested a review from a team as a code owner September 11, 2026 00:03
@chasdr
chasdr requested a lite review from Copilot September 11, 2026 00:03
@datarobot-pr-review-router

Copy link
Copy Markdown

🎫 Jira: CFX-7608 — dr still blames credentials for server errors on the .env and stored-profile paths

@github-actions github-actions Bot added the go Pull requests that update go code label Sep 11, 2026

This comment was marked as resolved.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stale Bugbot comment from a previous run.

Comment thread internal/config/api.go
… path

Why:
SetURLToConfig rejects a non-http/https scheme, but the template setup
custom-host picker writes through SaveURLToConfig, which skipped the check.
Typing ftp:// there still persisted an unusable endpoint.

Changes:
- SaveURLToConfig runs RequireHTTPScheme on a non-empty host before writing.
  The empty reset case is untouched, and saveHost already surfaces the error
  in the setup TUI.
- test: SaveURLToConfig("ftp://...") errors and persists nothing.
Why:
The interactive picker and stdin prompt only re-ask on ErrInvalidURL.
RequireHTTPScheme returned a plain error, so a custom URL with a bad scheme
aborted the whole set-url flow instead of letting the user retry, unlike a
malformed URL.

Changes:
- RequireHTTPScheme returns an error that unwraps to ErrInvalidURL, keeping
  its specific message for the read path and the arg path. The two picker
  paths (the errors.Is check in selectURLInteractively and readURLFromStdin)
  now re-ask on a bad scheme.
- test: a rejected scheme satisfies errors.Is(err, ErrInvalidURL).
@chasdr

chasdr commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit e8e4738. Configure here.

@datarobot-pr-review-router

Copy link
Copy Markdown

Code Ownership

Cli Maintainers

  • cmd/auth/seturl/cmd.go
  • cmd/auth/seturl/cmd_test.go
  • docs/commands/auth.md
  • internal/auth/auth.go
  • internal/config/api.go
  • internal/config/api_test.go

Review requested from the teams above. Labels will be removed automatically upon approval.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants