fix(security): docker hardening, homoglyph detection, async persist, public-bind warning
Summary
Three targeted fixes addressing open security and reliability issues:
- Unicode homoglyph bypass in prompt injection detector (#1925) — Cyrillic confusables, fullwidth ASCII, soft hyphens, RTL overrides now normalized before regex matching. Shared
is_obfuscation_char()helper prevents list drift. - Webhook router async persist + debug logging (#1933) — debug logs on the runtime-detection branch and best-effort docstring added to upstream's generation-counter persist() structure.
- Public-bind security warning (#1919) — loud stderr + log warning when
OPENHUMAN_CORE_HOSTis non-loopback without explicitOPENHUMAN_CORE_TOKEN
Note: Docker hardening (#1930) was originally in this PR but was dropped during merge-conflict resolution — upstream independently applied equivalent changes (
read_only,cap_drop,no-new-privileges, configurablemem_limit/cpus). #1930 can be closed separately.
Changes
| File | What | Issue |
|---|---|---|
src/openhuman/prompt_injection/detector.rs |
Cyrillic/fullwidth/zero-width normalization + is_obfuscation_char() helper |
#1925 |
src/openhuman/prompt_injection/tests.rs |
4 new homoglyph bypass tests | #1925 |
src/openhuman/webhooks/router.rs |
Best-effort docstring + debug logs on persist() branches | #1933 |
src/core/jsonrpc.rs |
Public-bind token warning | #1919 |
Test plan
- [x]
cargo fmt --all -- --check— clean - [x]
cargo check -p openhuman --lib— no errors - [x]
cargo test -p openhuman "prompt_injection"— 18/18 pass (4 new) - [x]
cargo test -p openhuman "webhooks::router"— 25/25 pass
Closes #1925, #1933. Addresses #1919.
🤖 Generated with Claude Code
This PR adds three independent hardening improvements: an RPC startup token check for public binds, expanded Unicode obfuscation detection to strip zero-width and homoglyph characters during prompt normalization, and regression tests to verify homoglyph bypasses are now caught. Webhook persistence documentation and debug logging clarify threading and skipped-write behavior. Infrastructure and Application Security 🎯 3 (Moderate) | ⏱️ ~25 minutes 🐰 A rabbit hops through Unicode fields, ✏️ Tip: You can configure your own custom pre-merge checks in the settings.📝 Walkthrough
Walkthrough
Changes
Layer / File(s)
Summary
RPC Startup Token Validation
src/core/jsonrpc.rsWhen binding the core RPC server to a public (non-loopback) address, a startup-time check verifies that
OPENHUMAN_CORE_TOKEN is explicitly set; if missing, an error log and red console warning explain the authentication requirement.
Prompt Injection Unicode Normalization and Tests
src/openhuman/prompt_injection/detector.rs, src/openhuman/prompt_injection/tests.rsis_obfuscation_char() centralizes detection of zero-width, formatting, and soft-hyphen-like Unicode characters (U+00AD, U+034F, U+180E, U+200E/U+200F, U+202A–U+202E, U+2066–U+2069). normalize_prompt() now strips these characters entirely (instead of mapping to space) and expands had_zwsp detection accordingly. Regression tests verify that "ignore" keyword disguises via Cyrillic homoglyphs, fullwidth variants, leet-speak combinations, and RTL overrides are all caught (score ≥ 0.45).
Webhook Persistence Observability
src/openhuman/webhooks/router.rspersist() documentation clarifies best-effort semantics and thread model (serialization on calling thread, writes offloaded to tokio::task::spawn_blocking when available, otherwise synchronous). Debug logs track skipped stale writes (generation mismatch) and the choice between async spawn vs inline execution.Estimated code review effort
Possibly related issues
OPENHUMAN_CORE_TOKEN) via complementary startup-time validation in src/core/jsonrpc.rs.Possibly related PRs
WebhookRouter::persist generation-skipping logic and spawn_blocking vs inline write branching in src/openhuman/webhooks/router.rs.src/openhuman/prompt_injection/detector.rs normalization and scoring logic alongside tests.rs updates.Suggested reviewers
Poem
Strips the homoglyphs that bypass shields,
Tokens guard the RPC gate with care,
Webhooks log their writes through the air—
Security bundled, neat and fair!🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name
Status
Explanation
Title check
✅ Passed
Title accurately summarizes the main changes (homoglyph detection, public-bind warning, async persist) with specific scope.
Linked Issues check
✅ Passed
Changes in detector.rs implement NFKD-style normalization, Cyrillic/fullwidth confusable mapping, and zero-width character stripping as required by
#1925.
Out of Scope Changes check
✅ Passed
Changes to jsonrpc.rs (
#1919), router.rs (#1933), and docker-compose.yml (#1930) are all in-scope security hardening items mentioned in PR objectives.
Docstring Coverage
✅ Passed
Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Description Check
✅ Passed
Check skipped - CodeRabbit’s high-level summary is enabled.
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Comment @coderabbitai help to get the list of available commands and usage tips.
@senamakel Merge conflict resolved in 8c43d806 — took upstream's generation counter + serialize-inside-closure structure and re-applied our docstring + debug logs on top, exactly as you suggested. All CI checks are green. Ready for re-review when you get a chance.
@coderabbitai re-review
@Liohtml Sure! I'll kick off a fresh review of PR #2011 now, picking up the merge-conflict resolution in 8c43d806 and the updated spawn_blocking / docstring / debug-log changes.
✅ Actions performed
Full review triggered.
@Liohtml The PR description and change table list docker-compose.yml modifications for #1930, and the PR says "Closes #1930" — but docker-compose.yml is not in the diff. The only changed files are jsonrpc.rs, detector.rs, tests.rs, and router.rs. Were the docker-compose changes lost during a rebase, or should the "Closes #1930" claim and the change table be updated? This needs to be resolved before merge.
Good catch @graycyrus — the docker-compose.yml changes were dropped during the merge-conflict resolution because upstream independently applied equivalent hardening (read_only, cap_drop: ALL, no-new-privileges, configurable mem_limit/cpus). I've updated the PR description to remove the #1930 claim and clarified that it can be closed separately. Thanks!
@graycyrus PR description has been updated — removed the #1930 claim and docker-compose.yml row from the change table. Could you dismiss your review when you get a chance? Thanks!