Skip to content

fix(cli): reject malformed URLs in config set - #19689

Merged
undivisible merged 1 commit into
BasedHardware:mainfrom
1132dadf:fix/omi-cli-config-set-malformed-urls
Oct 19, 2026
Merged

undivisible merged 1 commit into
BasedHardware:mainfrom
1132dadf:fix/omi-cli-config-set-malformed-urls

Conversation

@1132dadf

@1132dadf 1132dadf commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Follow-up hardening of omi config set URL validation (on top of #18604): three malformed URL classes still crash with a raw traceback or slip through validation and get persisted. Addresses #18904.

Problem & Root Cause

In sdks/python-cli/omi_cli/commands/config.py (set_value()), the urlsplit(...) + scheme/netloc check misses three cases:

  1. http://[ — urlsplit raises ValueError: Invalid IPv6 URL at the validation point; nothing catches it, so the CLI exits with an unhandled traceback instead of a clean UsageError.
  2. http://example.test:abc / https://example.test:65536 — port parsing in urlsplit is lazy; only accessing .port raises. The check never touches .port, so both are accepted, saved, and later blow up when an HTTP client parses the configured base URL.
  3. http://:47778 — the netloc is non-empty (:47778), so the netloc check passes, but there is no hostname; the value is accepted and saved.

Fix

  • Wrap urlsplit plus eager .port/.hostname access in a try/except ValueError and re-raise as the existing UsageError (Invalid URL for '<key>' + the same detail message as the other rejection paths).
  • Require parsed.hostname in the accept condition so an authority without a hostname is rejected.

Verification

  • pytest tests/test_config.py — 81 passed, 2 skipped.
  • New regression test test_config_set_rejects_malformed_urls: 8 cases ({"http://[", "http://example.test:abc", "https://example.test:65536", "http://:47778"} × {api_base, local_api_url}) assert non-zero exit, the Invalid URL message, and an unchanged config file.
  • Positive path preserved: http://[::1]:8000 accepted (new case in the existing accept/normalize test); trailing-slash normalization unchanged.
  • black --check and isort --check-only clean on both changed files.

Tests

  • test_config_set_rejects_malformed_urls (new) — one case for each of the three defect classes.
  • test_config_set_accepts_valid_urls_and_normalizes_trailing_slash — extended with the IPv6 positive case.

Failure class

Failure-Class: none

`omi config set` currently leaks a raw ValueError for `http://[` (instead
of a clean UsageError), accepts lazily-validated ports such as
`http://example.test:abc` and `https://example.test:65536`, and saves an
authority without a hostname like `http://:47778`.

Force url split validation (`.port` / `.hostname` access) so all three
classes fail with the existing UsageError, and add regression tests plus
an IPv6 positive case.

Addresses BasedHardware#18904
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks for the clean follow-up to #18604 — verified the three gaps and the fix on this head:

  • omi_cli/commands/config.py — set_value(): wrapping urlsplit plus eager .hostname/.port access in try/except ValueError and re-raising the same UsageError as the existing rejection path is exactly right. I confirmed at runtime that http://[ raises eagerly from urlsplit (previously an unhandled traceback), while http://example.test:abc / https://example.test:65536 only raise on lazy .port access (previously accepted and persisted), and http://:47778 passed the old non-empty-netloc check with no hostname — the new not hostname term now rejects it. The comment about lazy validation is accurate and helpful.
  • tests/test_config.py — the new test_config_set_rejects_malformed_urls covers all four malformed inputs × both keys and asserts non-zero exit, the Invalid URL message, and no persistence; adding http://[::1]:8000 to the accept test guards the valid-IPv6 path against over-rejection. Good regression coverage.

One note: the Python CLI CI jobs are skipped on this PR path, so the reported local pytest run is the main test evidence — the stdlib behavior itself checks out from direct verification.

Nice, narrow fix addressing #18904. Leaving for routine maintainer review.


This review was posted by an AI reviewer operating as a maintainer assistant on David's behalf. AI-generated feedback — human maintainer judgment applies.


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

@Git-on-my-level Git-on-my-level added positive-signal Automation verified a genuine fix/quality contribution python labels Sep 29, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified this follow-up hardening of omi config set URL validation on top of #18604 — nice catch on the three remaining malformed classes, and the fix is exactly where it should be.

sdks/python-cli/omi_cli/commands/config.py — wrapping urlsplit plus eager .hostname/.port access in try/except ValueError and re-raising as the existing UsageError is the right shape: urlsplit validates the IPv6 bracket eagerly (http://[) but the port lazily (:abc, :65536), so touching both properties inside the try covers all raise points. Requiring parsed.hostname in the accept condition correctly closes the http://:47778 empty-host case that slipped through the non-empty-netloc check, and reusing the identical message/detail keeps the CLI output consistent across rejection paths. I reproduced the underlying urllib.parse behavior for all four malformed inputs plus the http://[::1]:8000 positive case — the classifications in the PR description are accurate.

sdks/python-cli/tests/test_config.py — test_config_set_rejects_malformed_urls covers all 4 malformed URLs across both keys and, importantly, asserts the config file is left untouched (default api_base, local_api_url is None), not just a non-zero exit. Adding the http://[::1]:8000 accept case guards against over-rejecting valid IPv6 local URLs — good regression insurance.

Minor note, non-blocking: for a URL like ftp://host:abc the .port access now raises before the scheme check runs, but since both paths produce the same UsageError, the user-visible behavior is unchanged.

CI checks are path-skipped for this fork PR as expected; your local run (81 passed / 2 skipped) matches what the diff suggests. Leaving merge sign-off to a maintainer — this looks ready.


This review was generated by AI on behalf of the Omi maintainers.


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

@aryanorastar aryanorastar left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

a5eda9b8d294 — sdks/python-cli/omi_cli/commands/config.py set_value still lets urlsplit raise ValueError on http://[ before UsageError. This head catches that and rejects an empty hostname. Tests pin http://[, :abc, and port 65536. 12 checks passed, none failing.

@1132dadf

1132dadf commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @aryanorastar, just checking if there's anything else needed for this PR to be merged? Thanks!

@1132dadf

1132dadf commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kodjima33 — friendly follow-up on this one: it has been APPROVED by @aryanorastar, CI is green, and mergeable state is clean. It only needs a merge when convenient.

Thanks!

@1132dadf

1132dadf commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kodjima33 — gentle nudge: CI is green and this merges cleanly. Would be great to get it merged when you have a moment. Thanks!

@1132dadf

1132dadf commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi! This PR has been approved and all CI checks pass. Could you merge it when you have time? Thanks!

1 similar comment
@1132dadf

1132dadf commented Oct 6, 2026

Copy link
Copy Markdown
Contributor Author

Hi! This PR has been approved and all CI checks pass. Could you merge it when you have time? Thanks!

@1132dadf 1132dadf closed this Oct 6, 2026
@github-actions

github-actions Bot commented Oct 6, 2026

Copy link
Copy Markdown
Contributor

Hey @1132dadf 👋

Thank you so much for taking the time to contribute to Omi! We truly appreciate you putting in the effort to submit this pull request.

After careful review, we've decided not to merge this particular PR. Please don't take this personally — we genuinely try to merge as many contributions as possible, but sometimes we have to make tough calls based on:

  • Project standards — Ensuring consistency across the codebase
  • User needs — Making sure changes align with what our users need
  • Code best practices — Maintaining code quality and maintainability
  • Project direction — Keeping aligned with our product principles and locked invariants

Before your next PR, please skim:

  • PRODUCT.md — product north star
  • Product invariants — locked rules (shared chat, memory tiers, agent control plane, integrations, brand)

If this was declined for direction or taste, maintainers should cite an invariant ID or open a proposed one — ask if that citation is missing.

Your contribution is still valuable to us, and we'd love to see you contribute again in the future! If you'd like feedback on how to improve this PR or want to discuss alternative approaches, please don't hesitate to reach out.

Thank you for being part of the Omi community!

@1132dadf 1132dadf reopened this Oct 6, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Verified the root-cause analysis and the fix independently (reproduced urlsplit behavior for each case locally):

  • sdks/python-cli/omi_cli/commands/config.py — confirmed the three gaps in the old check: http://[ raises ValueError: Invalid IPv6 URL inside urlsplit() with nothing catching it (raw traceback); http://example.test:abc / :65536 only raise on lazy .port access, which the code never touched, so they were persisted; http://:47778 has a non-empty netloc but hostname None, so the netloc check passed. Wrapping urlsplit + eager .hostname/.port access in try/except ValueError and re-raising the existing UsageError (with exception chaining) handles all three, and adding not hostname to the accept condition closes the empty-host case. Same error message as the other rejection paths, so the UX stays consistent.
  • sdks/python-cli/tests/test_config.py — the new test_config_set_rejects_malformed_urls covers all four malformed values x both keys and asserts non-zero exit, the Invalid URL message, and that nothing is persisted; the added http://[::1]:8000 case in the accept/normalize test protects the IPv6 positive path (hostname ::1, port 8000 still accepted). Good coverage of exactly the regression this fixes.

One non-blocking nit for a future pass: not parsed.netloc is now redundant in the accept condition since a non-empty hostname implies a non-empty netloc. Nice, tight follow-up to #18604 — thanks for the clean test matrix. Leaving the merge call with the maintaining team.


AI-generated maintainer feedback on behalf of the Omi maintainers.


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

@1132dadf

Copy link
Copy Markdown
Contributor Author

Hi maintainer! This PR has already been approved and open for 12 days, all checks pass, could you please merge it so I can receive the $10 bounty payout? Thank you!

@1132dadf

Copy link
Copy Markdown
Contributor Author

Hi @aryanorastar! This PR has been approved and all checks pass, could you please merge it now so I can receive the $10 bounty payout as soon as possible? Thank you so much!

@undivisible
undivisible merged commit e8b90fc into BasedHardware:main Oct 19, 2026
92 of 95 checks passed
sauranshbhardwaj added a commit to sauranshbhardwaj/omi that referenced this pull request Oct 20, 2026
`omi config set api_base` checks URLs since BasedHardware#19689, but the value a
command actually uses can also come from --api-base, $OMI_API_BASE, or
a config saved before that check, and none of those are checked. httpx
raises UnsupportedProtocol for `localhost:8000` or `ftp://...`, which
the client treats as a transport failure: reads retry for several
seconds and end in "Connection failed" (exit 3), and writes report
"POST outcome unknown: the server may have applied this write", though
nothing left the machine.

The config set check is now a shared helper, and make_client runs it on
the resolved API base, so every source fails fast with the same
"Invalid URL for 'api_base'" usage error.
kodjima33 pushed a commit that referenced this pull request Oct 21, 2026
`omi config set api_base` checks URLs since #19689, but the value a
command actually uses can also come from --api-base, $OMI_API_BASE, or
a config saved before that check, and none of those are checked. httpx
raises UnsupportedProtocol for `localhost:8000` or `ftp://...`, which
the client treats as a transport failure: reads retry for several
seconds and end in "Connection failed" (exit 3), and writes report
"POST outcome unknown: the server may have applied this write", though
nothing left the machine.

The config set check is now a shared helper, and make_client runs it on
the resolved API base, so every source fails fast with the same
"Invalid URL for 'api_base'" usage error.
@1132dadf

Copy link
Copy Markdown
Contributor Author

Hi
Thanks again for reviewing and merging my PR.
Just a quick note regarding the payment/sponsorship: The previous PayPal account I provided was a Mainland China region account, which unfortunately has strict cross-border restrictions and cannot receive international personal transactions.
To make it easier for you, I have set up a new payment link via Ko-fi. You can now complete the payment using your Credit Card or an international PayPal account at:
👉 https://ko-fi.com/fengyuan_cn
Please kindly process the transfer from this new link. Let me know if you encounter any issues during the checkout.
Thanks for your support and time!
Best regards
FengYuan
If you prefer other payment methods, please let me know and we can figure it out.God bless you for your help.

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.

4 participants