Skip to content

feat(lock): add secure-input policy for password fields#53

Merged
BlackHole1 merged 1 commit into
mainfrom
feat/secure-input-password-fields
Jul 3, 2026
Merged

feat(lock): add secure-input policy for password fields#53
BlackHole1 merged 1 commit into
mainfrom
feat/secure-input-password-fields

Conversation

@BlackHole1

Copy link
Copy Markdown
Member

In Chrome password fields the OS coerces the keyboard to ABC via macOS secure event input, and LockIME sometimes never reverted to the locked source — you'd land on ABC and stay there. The lock's state machine is purely event-driven, so a mismatch that goes stable with no follow-up notification (the secure-field ASCII coercion, or a flaky background CJKV select) was never re-examined; and leaving the field ends secure input without reliably posting a source-change notification, so nothing re-triggered the lock on blur.

This adds an Enforce in password fields toggle (General ▸ Password Fields, revertsInSecureInput, off by default). Off, LockIME respects macOS secure input and leaves the coercion alone; on, it keeps enforcing the locked source even there. The policy threads config → LockEngine.applyLockController and gates enforcement on the process-global IsSecureEventInputEnabled(), covering the continuous lock and autonomous one-shot switches alike; the explicit lockime://switch-source API stays ungated.

Two enabling fixes make it work:

  • Trailing reconcile — every force arms a bounded re-check (maxReconcileRetries) that runs once the settle window closes, so a switch that silently didn't take is corrected without waiting on a notification that never comes.
  • Secure-input poll — because blur posts no notification, respect mode polls IsSecureEventInputEnabled() (secureInputPollInterval) only while a secure field keeps it gated, re-asserting the lock the instant secure input turns off.

The scheduler and secure-input probe are injected so the state machine stays deterministically testable; new tests cover the reconcile and retry cap, the gate in both modes, the one-shot exemption, poll-driven recovery with no blur notification, and the config round-trip. Every user-facing string is translated for all nine SupportedLanguage cases.

Verification. All 345 tests pass. On a real machine I confirmed the respect behavior and the poll's detect→re-force logic end to end via os_log: leaving a synthetic secure field that posts no notification, the poll fires and re-forces the target. I could not drive Chromium's native secure input under CDP automation, so the last mile — the frontmost app visibly switching back to your IME in real Chrome — is unverified here and worth a manual smoke test (lock to your IME, type in a Chrome password box, tab to a normal field, confirm it returns within ~0.5s). If a frontmost app freshly out of secure input resists the background switch, the follow-up is to force FocusNudge on the secure-input recovery path.

Closes #52

Issue #52: in Chrome password fields the OS coerces the keyboard to
ABC via secure event input, and LockIME sometimes never reverted to
the locked source. The state machine is purely event-driven, so a
mismatch that goes *stable* with no follow-up notification — the
secure-field ASCII coercion, or a flaky background CJKV `select` —
was never re-examined and stayed stuck on ABC.

Add a `revertsInSecureInput` toggle (General ▸ Password Fields, off by
default). Off, LockIME respects macOS secure input and leaves the
coercion alone; on, it keeps enforcing the locked source even there.
The policy threads config → `LockEngine.apply` → `LockController` and
gates enforcement on the process-global `IsSecureEventInputEnabled()`,
covering the continuous lock and autonomous one-shot switches alike;
the explicit `lockime://switch-source` API stays ungated.

Two enabling fixes make it work. Every `force` now arms a bounded
trailing reconcile (`maxReconcileRetries`) that re-checks once the
settle window closes, so a switch that silently didn't take is
corrected without waiting on a notification that never comes. And
because leaving a password field ends secure input without reliably
posting a source-change notification, respect mode polls
`IsSecureEventInputEnabled()` (`secureInputPollInterval`) only while a
secure field keeps it gated, re-asserting the lock the instant secure
input turns off.

The scheduler and secure-input probe are injected so the state machine
stays deterministically testable.

Refs #52

Signed-off-by: Kevin Cui <bh@bugs.cc>
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You’ve reached a temporary PR review limit under our Fair Usage Limits Policy.

Your recent review volume is higher than typical usage, so adaptive limits are currently applied.

Next review available in: 16 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1ac6458d-8473-45ab-9dac-a271f87a10ae

📥 Commits

Reviewing files that changed from the base of the PR and between f538212 and 04d1923.

📒 Files selected for processing (11)
  • Sources/LockIME/AppState.swift
  • Sources/LockIME/Localizable.xcstrings
  • Sources/LockIME/UI/Settings/GeneralSettingsPane.swift
  • Sources/LockIMEKit/LockEngine/LockController.swift
  • Sources/LockIMEKit/LockEngine/LockEngine.swift
  • Sources/LockIMEKit/Rules/LockConfiguration.swift
  • Tests/LockIMEKitTests/LockConfigurationTests.swift
  • Tests/LockIMEKitTests/LockControllerTests.swift
  • Tests/LockIMEKitTests/LockEngineTests.swift
  • Tests/LockIMEKitTests/Support/MockInputSourceProvider.swift
  • docs/DESIGN.md
✨ Finishing Touches
✨ Simplify code
  • Create PR with simplified code
  • Commit simplified code in branch feat/secure-input-password-fields

Comment @coderabbitai help to get the list of available commands.

@BlackHole1 BlackHole1 merged commit 65d2391 into main Jul 3, 2026
3 checks passed
@BlackHole1 BlackHole1 deleted the feat/secure-input-password-fields branch July 3, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] Input method switches to ABC randomly in Chrome password input boxes and LockIME fails to revert to the target input method

1 participant