1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
//! Runtime configuration for nerve-ipc-core.
//!
//! [`Config`] controls the WebSocket bind address and port, the expected
//! browser extension ID for Origin checking, the token storage path, and the
//! Unix Domain Socket path.
//!
//! [`Config::default`] provides production-safe defaults:
//!
//! | Field | Default |
//! |---|---|
//! | `bind_addr` | `127.0.0.1` |
//! | `ws_port` | `9001` |
//! | `allowed_extension_id` | `""` (origin checking disabled) |
//! | `token_path` | `~/.anvesha/token` |
//! | `uds_path` | `/tmp/nerve.sock` |
//!
//! # Security note
//!
//! `bind_addr` must always be `127.0.0.1`. Setting it to `0.0.0.0` would
//! expose the daemon to the local network, which violates the local-first
//! security model.
use Ipv4Addr;
use PathBuf;
/// Runtime configuration for nerve-ipc-core.
///
/// The bind address is always `127.0.0.1` — exposing the daemon on `0.0.0.0`
/// would make it reachable from the LAN, which is a security violation for a
/// local-first system.
///
/// # Examples
///
/// ```
/// use nerve_ipc_core::Config;
///
/// // Default configuration: origin checking disabled (empty extension ID).
/// let config = Config::default();
/// assert_eq!(config.allowed_origin(), None);
///
/// // Production: enforce origin checking against a specific extension ID.
/// let config = Config {
/// allowed_extension_id: "abcdefghijklmnopqrstuvwxyzabcdef".to_string(),
/// ..Config::default()
/// };
/// assert_eq!(
/// config.allowed_origin(),
/// Some("chrome-extension://abcdefghijklmnopqrstuvwxyzabcdef".to_string()),
/// );
/// ```