Skip to content

fix(cli): reject non-ASCII characters in developer API keys - #20406

Merged
kodjima33 merged 4 commits into
BasedHardware:mainfrom
1132dadf:fix/cli-reject-non-ascii-api-key
Oct 3, 2026
Merged

kodjima33 merged 4 commits into
BasedHardware:mainfrom
1132dadf:fix/cli-reject-non-ascii-api-key

Conversation

@1132dadf

@1132dadf 1132dadf commented Oct 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

omi auth login now rejects developer API keys containing non-ASCII characters (e.g. a CJK character or emoji) with a clean usage error, instead of accepting the key and only failing later during the verification round-trip. Closes #20401.

Root cause

validate_api_key_format() in sdks/python-cli/omi_cli/auth/api_key.py only checks the omi_dev_ prefix and a minimum length, so a key like omi_dev_aaaaaaaaaaaaaaaaaaaa中 passes client-side validation and proceeds to the HTTP verification call, producing a confusing late failure instead of an immediate input error. All login entry points (--api-key, piped stdin, interactive paste) funnel through this function, so a single check covers all of them.

Test plan

  • New unit tests assert that a key ending in a CJK character, a key ending in an emoji, a key with an interior space, and a key containing a control byte all raise UsageError from validate_api_key_format().
  • New CLI-level test asserts omi --json auth login --api-key "omi_dev_…中" exits with code 1 (usage error) and performs zero API round-trips.
  • pytest tests/test_auth_api_key.py on this host: all validation/login-rejection tests pass. The remaining tests in that file error only on this Windows host due to the pre-existing owner-only DACL read-back check added in 0c4d6e7 (_secure_file.py), unrelated to this change; the Linux CI job runs the full suite via the POSIX secure-file path.

Review in cubic

Failure class (fixes)

Failure-Class: none

validate_api_key_format now rejects keys containing non-ASCII characters with a clear UsageError before any network round-trip, matching the issue repro (key with a CJK character passes prefix+length checks today).

@cubic-dev-ai cubic-dev-ai 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.

All reported issues were addressed across 2 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread sdks/python-cli/omi_cli/auth/api_key.py Resolved
Follows the non-ASCII rejection from 33f01d1: a key with an interior space or a control byte still slipped through isascii()+length checks and failed late at the HTTP verification round-trip. The backend pattern is omi_dev_ + 32 hex chars, so printable-ASCII-only is the correct client-side contract.
@1132dadf

1132dadf commented Oct 3, 2026

Copy link
Copy Markdown
Contributor Author

Hi @kodjima33 — could you take a look at this PR when you have a moment?

It fixes #20401 (CLI currently rejects non-ASCII developer keys as invalid input). The change is scoped to sdks/python-cli: three-tier validation (prefix → isascii → printable ASCII 0x21–0x7E) plus 5 unit tests. CI is green (Hygiene ✅, Mobile Release Eligibility ✅), mergeable state is clean.

Thanks!

@Git-on-my-level Git-on-my-level added python positive-signal Automation verified a genuine fix/quality contribution security-review Touches auth, provider routing, secrets, or security-sensitive surfaces labels Oct 3, 2026
@Git-on-my-level

Copy link
Copy Markdown
Member

Thanks @1132dadf - nice, tight fix. Reviewed both changed files at the current head.

sdks/python-cli/omi_cli/auth/api_key.py

  • The two new guards in validate_api_key_format() run on cleaned (post-strip) input, so the existing trim-leading/trailing-whitespace behavior is preserved, and both guards only raise UsageError - no behavior change for valid keys.
  • Ordering is sensible: prefix check, then ASCII, then printable-range (0x21-0x7E), then minimum length, so errors get progressively more specific.
  • Cross-checked the backend: keys are minted as omi_dev_ + secrets.token_hex(16) and validated server-side against omi_dev_[0-9a-f]{32} (backend/database/dev_api_key.py), so real keys are always lowercase hex and can never trip the new checks.
  • Since login_with_api_key() funnels every entry point (--api-key, piped stdin, interactive paste) through this validator, one change covers all of them - good factoring.

sdks/python-cli/tests/test_auth_api_key.py

  • Good coverage of the new branches: CJK character, emoji, interior space, and a control byte, plus a CLI-level test asserting exit code 1 with zero HTTP round-trips (route.call_count == 0) - exactly the regression this PR fixes (confusing late failure during the verification call).

The implementation looks correct and well-tested. Since this touches an auth-adjacent input path, it needs maintainer sign-off before merge rather than automated approval.


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

@kodjima33 kodjima33 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.

Scoped, well-tested input-validation fix (41 lines); closes #20401; CI green. Merging.

@kodjima33
kodjima33 merged commit 76b5063 into BasedHardware:main Oct 3, 2026
45 of 46 checks passed
@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 security-review Touches auth, provider routing, secrets, or security-sensitive surfaces

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bounty proposal] CLI rejects non-ASCII developer keys as input errors (US$25 proposed)

3 participants