Skip to content

fix(cli): validate URL scheme and non-empty token in local configure and client - #18703

Closed
I-Am-Finite wants to merge 1 commit into
BasedHardware:mainfrom
I-Am-Finite:fix/cli-local-configure-validation
Closed

I-Am-Finite wants to merge 1 commit into
BasedHardware:mainfrom
I-Am-Finite:fix/cli-local-configure-validation

Conversation

@I-Am-Finite

@I-Am-Finite I-Am-Finite commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Validates that omi local configure only accepts valid http:// or https:// URLs with hosts and rejects empty/whitespace tokens, matching the validation already enforced in omi config set. Also hardens LocalOmiClient to validate input URLs and tokens before creating the HTTP client.

Problem & Root Cause

  • In sdks/python-cli/omi_cli/commands/local.py, configure did not validate --url or --token. Users or scripts supplying invalid URLs (e.g. ftp://, missing schemes, or empty hosts) or empty/whitespace tokens had their config saved in a corrupted state, leading to later crashes or confusing auth/transport errors during subsequent omi local commands.
  • In contrast, omi config set local_api_url and omi config set local_token explicitly validate URL schemes, host presence, and non-empty tokens.
  • LocalOmiClient also passed raw unvalidated URL schemes to httpx without verifying the presence of http/https schemes and valid netlocs.

Fix

  1. In sdks/python-cli/omi_cli/commands/local.py:
    • Validates that url uses http or https and contains a valid host via urlsplit, raising UsageError otherwise.
    • Validates that token is non-empty after stripping whitespace, raising UsageError otherwise.
    • Cleans leading/trailing whitespace and trailing slashes prior to saving.
  2. In sdks/python-cli/omi_cli/local_client.py:
    • Adds pre-flight URL scheme and netloc validation to LocalOmiClient.__init__, raising CliError with exit code 2 on invalid URLs.
    • Validates that tokens are not empty or whitespace-only.
  3. In sdks/python-cli/tests/test_local.py:
    • Added parameterized tests verifying invalid URL rejection in omi local configure.
    • Added parameterized tests verifying empty/whitespace token rejection in omi local configure.
    • Added unit tests for LocalOmiClient validation errors.

Verification

  • pytest sdks/python-cli/tests/test_local.py: 59 passed
  • black --check and isort --check: clean

Proposed Bounty ($25 USD)

Review in cubic

@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @I-Am-Finite — nice first contribution, and a genuinely useful hardening pass. Reviewed each changed file:

  • sdks/python-cli/omi_cli/commands/local.py — local configure now strips whitespace/trailing slashes and validates the URL (http/https scheme + host via urlsplit) and non-empty token before saving, raising UsageError otherwise. This mirrors the validation already enforced in omi config set (config.py set_value), which is the right precedent — the two config paths now behave consistently.
  • sdks/python-cli/omi_cli/local_client.py — LocalOmiClient.__init__ now validates the same URL rules before constructing the httpx.Client (CliError, exit code 2), rejects whitespace-only tokens, and builds base_url/Authorization from the cleaned values. This also covers the env-var path (OMI_LOCAL_API_URL / OMI_LOCAL_TOKEN), which configure never touches — good defense-in-depth.
  • sdks/python-cli/tests/test_local.py — parametrized coverage for invalid URLs (not-a-url, ftp://, empty host, missing scheme) and empty/whitespace tokens in configure, plus direct constructor tests for LocalOmiClient. The asserted exit codes match the actual constants (UsageError → 1, CliError → 2).

Verification I ran on the head commit:

  • Confirmed the parity claim against config.py — identical scheme/netloc/empty-token rules.
  • Checked the error-rendering path: Renderer.error() builds rich Text spans without markup parsing, so echoing the raw user-supplied URL in the error detail can't inject console markup (consistent with the existing escaping test at the top of this file).
  • Ran the full python-cli test suite in a clean container: test_local.py 59 passed; whole suite 600 passed, 1 skipped — matching the PR description.

Minor, non-blocking: the error details interpolate the raw URL as-is; fine given the Text-span rendering, just worth keeping in mind if error output ever moves to a markup-parsed surface.


This feedback is AI-generated on behalf of the Omi maintainers. Leaving the merge decision to a human maintainer — no urgency; this is a positive signal on a clean change.


by AI on behalf of David — if you need David’s attention urgently, please @Git-on-my-level and escalate with need human response.

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

Labels

positive-signal Automation verified a genuine fix/quality contribution python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants