feat: make CORS origin configurable for cloud deployments
Summary
- Adds
OPENHUMAN_CORS_ORIGINenvironment variable to configure the JSON-RPC server'sAccess-Control-Allow-Originheader - Default (unset) preserves current behavior: wildcard
*for local/Tauri desktop - When set to a specific origin (e.g.
https://app.example.com), CORS is restricted to that origin only - Falls back to wildcard on invalid input so the server never crashes over a typo
Context
The JSON-RPC server in src/core/jsonrpc.rs hardcodes Access-Control-Allow-Origin: *. This is correct for the desktop case where the sidecar binds to 127.0.0.1, but becomes a security concern for Docker/cloud deployments where OPENHUMAN_CORE_HOST=0.0.0.0 — any website could make cross-origin requests to the API.
The .env.example already documents cloud deployment mode (OPENHUMAN_CORE_HOST=0.0.0.0) and gitbooks/features/cloud-deploy.md covers the setup. This change gives cloud deployers the ability to lock down CORS without modifying source code.
Test plan
- [ ] Verify local desktop still works with
OPENHUMAN_CORS_ORIGINunset (wildcard) - [ ] Set
OPENHUMAN_CORS_ORIGIN=https://example.comand verify CORS header reflects the value - [ ] Set
OPENHUMAN_CORS_ORIGINto an invalid string and verify fallback to wildcard
🤖 Generated with Claude Code
Summary by CodeRabbit
Release Notes
- New Features
- Added configurable CORS origin support, enabling operators to selectively restrict cross-origin requests to specific trusted origins instead of accepting all requests. Configuration is managed via an optional environment variable with a permissive default to maintain backward compatibility. This enhances security for production deployments.
No actionable comments were generated in the recent review. 🎉
ℹ️ Recent review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 10c03f9a-ba1a-48be-8471-0fb319c1ce14
📥 Commits
Reviewing files that changed from the base of the PR and between c441d2ea31f1f0a63239572ece496d38812f9962 and c6530c923a6736e1ad13aa51f38900af0981d980.
📒 Files selected for processing (2)
.env.examplesrc/core/jsonrpc.rs
💤 Files with no reviewable changes (1)
- src/core/jsonrpc.rs
✅ Files skipped from review due to trivial changes (1)
- .env.example
📝 Walkthrough
Walkthrough
Adds a commented OPENHUMAN_CORE_ALLOWED_ORIGINS entry to .env.example and a doc comment above with_cors_headers in src/core/jsonrpc.rs advising using that env var (comma-separated) for non-loopback Docker/cloud deployments instead of wildcarding CORS.
Changes
CORS docs and comments
| Layer / File(s) | Summary |
|---|---|
Env example and doc comment .env.example, src/core/jsonrpc.rs |
Adds a commented OPENHUMAN_CORE_ALLOWED_ORIGINS example to .env.example and a doc comment above with_cors_headers advising the env var be used (comma-separated origins) when the server binds to 0.0.0.0; no runtime logic changes. |
Estimated code review effort
🎯 1 (Trivial) | ⏱️ ~2 minutes
Possibly related PRs
- tinyhumansai/openhuman#2328: Related documentation/comment updates about
OPENHUMAN_CORE_ALLOWED_ORIGINSand CORS guidance. - tinyhumansai/openhuman#2266: Prior changes touching
src/core/jsonrpc.rsallowlist/CORS logic referenced by the new doc comment.
Suggested labels
rust-core, working
Suggested reviewers
- M3gA-Mind
- sanil-23
Poem
🐰 I nibbled docs beneath the moonlit code,
A hint for origins, in a safe, small node.
Commented lines to guide the cloud-bound host,
No logic changed, just a helpful post.
Hooray — deployment's safer, says this rabbit most.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title accurately describes the main change—making CORS origins configurable—which directly corresponds to the PR objectives and file modifications. |
| Docstring Coverage | ✅ Passed | Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%. |
| Linked Issues check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
| Out of Scope Changes check | ✅ Passed | Check skipped because no linked issues were found for this pull request. |
✏️ Tip: You can configure your own custom pre-merge checks in the settings.
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.
@hobostay CI is failing on changes in this PR — please fix before review.
@hobostay CI is failing on changes in this PR — please fix before review.
@hobostay CI is failing on changes in this PR — please fix before review.
Per pr-manager-lite finishing pass:
Merge with main: Resolved the src/core/jsonrpc.rs CORS conflict. Main now ships a proper Origin-echoing allowlist (is_origin_allowed keyed off OPENHUMAN_CORE_ALLOWED_ORIGINS), so the original OPENHUMAN_CORS_ORIGIN wildcard mechanism this PR introduced is superseded. Took main's with_cors_headers implementation, kept this PR's contribution by:
- documenting
OPENHUMAN_CORE_ALLOWED_ORIGINSin.env.examplefor the Docker / cloud deployment use case - adding a rustdoc note above
with_cors_headerspointing operators at the env var instead of wildcard
CodeRabbit comment (jsonrpc.rs:635 — log invalid OPENHUMAN_CORS_ORIGIN fallback): stale. The env var no longer exists; the invalid-value-falls-back-to-wildcard path it asked to log is gone. The spirit of the request (observability on the security-relevant path) is already satisfied by tracing::warn!("[cors] rejected disallowed origin: ...") introduced on main.
CI failures (Type Check / Rust Quality fmt+clippy / PR Submission Checklist): those failures were against the pre-merge code. cargo fmt --check and cargo check are clean on the merged tree; the CORS unit tests (8/8) pass.
Commits pushed to hobostay:fix/configurable-cors-origins:
abd87a5Merge branch 'main' into pr/2344c6530c9chore(pr-fix): drop stray blank line in with_cors_headers