Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
15966f2
fix(dev-mode): refuse browser and admin requests for a foreign host
LeeroyHannigan Oct 28, 2026
23dd692
docs(dev-mode): document the browser host check and its setting
LeeroyHannigan Oct 28, 2026
fa2f68e
Merge origin/main into fix/dev-mode-browser-host
LeeroyHannigan Nov 5, 2026
03f1773
Merge origin/main into fix/dev-mode-browser-host
LeeroyHannigan Nov 14, 2026
8291dce
fix(dev-mode): leave a repeated Host header to the repeated header re…
LeeroyHannigan Nov 14, 2026
ec02041
Merge origin/main into fix/dev-mode-browser-host
LeeroyHannigan Nov 17, 2026
2b1f0ca
Merge origin/main into fix/dev-mode-browser-host
LeeroyHannigan Nov 25, 2026
122be9a
fix(dev-mode): read a host port only when it is digits
LeeroyHannigan Nov 25, 2026
bad3f3d
test(dev-mode): build the banner's host lines where the app tests rea…
LeeroyHannigan Nov 25, 2026
47ecd4f
test(dev-mode): check the exact answers of the two requests the guard…
LeeroyHannigan Nov 25, 2026
4a72ee5
test(dev-mode): check that server.dev_allowed_hosts reaches the guard
LeeroyHannigan Nov 25, 2026
9b0fa13
docs(dev-mode): fix the host check docs and shorten the setting's copies
LeeroyHannigan Nov 25, 2026
1439151
test(dev-mode): send the admin GETs that pass the host check without …
LeeroyHannigan Nov 25, 2026
57e5261
docs(dev-mode): list the host check in the README and fix doc comments
LeeroyHannigan Nov 25, 2026
662ef93
docs(config): say which dev_allowed_hosts values stop a production build
LeeroyHannigan Nov 25, 2026
bcbd3e4
Merge branch 'main' into fix/dev-mode-browser-host
LeeroyHannigan Nov 27, 2026
a662edb
Merge origin/main into fix/dev-mode-browser-host
LeeroyHannigan Dec 1, 2026
f3fdc0f
test(dev-mode): expect the answer main gives a request with no token
LeeroyHannigan Dec 1, 2026
e61bc61
Merge origin/main into fix/dev-mode-browser-host
LeeroyHannigan Dec 4, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,10 @@ jobs:
# a dev-mode server. This job starts one and exercises the data plane.
runs-on: extenddb_ubuntu-2404_4-core
timeout-minutes: 40
# The server reads the listed name at startup, and the wire test that
# checks a listed name is served reads it too, so every step gets it.
env:
EXTENDDB__SERVER__DEV_ALLOWED_HOSTS: app.test
steps:
- uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6.1.0

Expand Down
66 changes: 48 additions & 18 deletions crates/app/src/cmd_serve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,9 @@ fn is_loopback_host(host: &str) -> bool {

/// Print the developer-mode banner lines: the mode notice, the credentials to
/// sign with, a warning block when the server is not bound to loopback, and an
/// advisory when an ambient `AWS_ACCESS_KEY_ID` would not verify.
/// advisory when an ambient `AWS_ACCESS_KEY_ID` would not verify. The banner
/// ends with the browser host rule and a note for each entry dropped from
/// `server.dev_allowed_hosts`.
///
/// Resolving here (not just in `serve()`) fails fast on a misconfigured
/// `EXTENDDB_DEV_*` pair before daemonizing, and gives the invoking user the
Expand All @@ -411,12 +413,16 @@ fn print_dev_mode_banner(
use extenddb_server::dev_credentials;

let dev_creds = dev_credentials::resolve()?;
let dev_hosts = extenddb_server::parse_dev_allowed_hosts(
app_config.server.dev_allowed_hosts.as_deref().unwrap_or(""),
);
let lines = dev_mode_banner_lines(
&config::redact_password(app_config.storage.connection_config()),
app_config.server.bind_addr.trim(),
port,
&dev_creds,
dev_credentials::ignored_aws_env_key(&dev_creds).as_deref(),
&dev_hosts,
);
// Same stream split as the main banner: stdout for the daemon parent,
// stderr in foreground mode so supervisors capture one stream.
Expand All @@ -443,6 +449,7 @@ fn dev_mode_banner_lines(
port: u16,
dev_creds: &[extenddb_server::dev_credentials::DevCredential],
ignored_aws_key: Option<&str>,
dev_hosts: &(Vec<String>, Vec<String>),
) -> Vec<String> {
use extenddb_server::dev_credentials;

Expand Down Expand Up @@ -500,6 +507,16 @@ fn dev_mode_banner_lines(
EXTENDDB_DEV_SECRET_ACCESS_KEY to seed an additional credential."
));
}
// The host rule the server enforces, so the operator sees it without
// reading the log. Dropped entries are named too.
let (kept, dropped) = dev_hosts;
lines.push(format!(" {}", extenddb_server::dev_host_rule_line(kept)));
for entry in dropped {
lines.push(format!(
" Note: {}",
extenddb_server::dev_host_dropped_entry_note(entry)
));
}
lines
}

Expand Down Expand Up @@ -528,6 +545,12 @@ mod tests {
}
}

/// The banner of a server with no listed hosts, as one string.
fn banner(host: &str, port: u16, creds: &[DevCredential], ignored: Option<&str>) -> String {
dev_mode_banner_lines(":memory:", host, port, creds, ignored, &Default::default())
.join("\n")
}

#[test]
fn loopback_hosts_are_recognised() {
for host in ["127.0.0.1", "127.1.2.3", "::1", "localhost"] {
Expand All @@ -540,16 +563,14 @@ mod tests {

#[test]
fn loopback_dev_banner_has_no_exposure_warning() {
let text =
dev_mode_banner_lines(":memory:", "127.0.0.1", 18080, &[example()], None).join("\n");
let text = banner("127.0.0.1", 18080, &[example()], None);
assert!(text.contains("plain HTTP on loopback"), "{text}");
assert!(!text.contains("WARNING"), "{text}");
}

#[test]
fn non_loopback_dev_banner_warns_with_the_publish_command() {
let text =
dev_mode_banner_lines(":memory:", "0.0.0.0", 18080, &[example()], None).join("\n");
let text = banner("0.0.0.0", 18080, &[example()], None);
// The banner used to say "on loopback" whatever the bind was.
assert!(!text.contains("plain HTTP on loopback"), "{text}");
assert!(text.contains("plain HTTP on 0.0.0.0"), "{text}");
Expand All @@ -564,7 +585,7 @@ mod tests {

#[test]
fn non_loopback_dev_banner_without_the_example_pair_drops_the_public_wording() {
let text = dev_mode_banner_lines(":memory:", "0.0.0.0", 9000, &[team()], None).join("\n");
let text = banner("0.0.0.0", 9000, &[team()], None);
assert!(
text.contains("WARNING: dev mode is listening on 0.0.0.0:9000"),
"{text}"
Expand All @@ -582,14 +603,12 @@ mod tests {

#[test]
fn dev_banner_keeps_the_ignored_aws_key_note() {
let text = dev_mode_banner_lines(
":memory:",
let text = banner(
"127.0.0.1",
18080,
&[example()],
Some("ASIAFOREIGNSESSION01"),
)
.join("\n");
);
assert!(
text.contains("'ASIAFOREIGNSESSION01' will be rejected"),
"{text}"
Expand All @@ -599,14 +618,7 @@ mod tests {

#[test]
fn dev_banner_names_the_switch_when_it_removed_the_ignored_example_key() {
let text = dev_mode_banner_lines(
":memory:",
"127.0.0.1",
18080,
&[team()],
Some(EXAMPLE_ACCESS_KEY_ID),
)
.join("\n");
let text = banner("127.0.0.1", 18080, &[team()], Some(EXAMPLE_ACCESS_KEY_ID));
assert!(
text.contains(&format!("'{EXAMPLE_ACCESS_KEY_ID}' will be rejected")),
"{text}"
Expand All @@ -617,6 +629,24 @@ mod tests {
);
}

#[test]
fn dev_banner_ends_with_the_host_rule_and_each_dropped_entry() {
let hosts = extenddb_server::parse_dev_allowed_hosts("app.test, bad host");
let lines =
dev_mode_banner_lines(":memory:", "127.0.0.1", 18080, &[example()], None, &hosts);
assert_eq!(
lines[lines.len() - 2..],
[
" ExtendDB serves a browser request, and any request to /management or \
/metrics, only when its host is an IP address, localhost, a name ending in \
.localhost, or a name in server.dev_allowed_hosts (environment variable \
EXTENDDB__SERVER__DEV_ALLOWED_HOSTS). Listed hosts: app.test",
" Note: dev_allowed_hosts entry 'bad host' was ignored: list a bare host name \
with no port, scheme or wildcard, such as app.test.",
]
);
}

/// Test wrapper so clap has a top-level `Parser` to drive `ServeArgs`.
#[derive(Parser)]
struct TestCli {
Expand Down
26 changes: 25 additions & 1 deletion crates/app/src/manage_http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,18 @@ pub fn resolve_endpoint(
} else {
None
};
Ok((format!("{addr}:{}", app_config.server.port), use_tls, cert))
Ok((host_port(addr, app_config.server.port), use_tls, cert))
}

/// `addr:port` for the TCP connect and the `Host` header. An IPv6 literal goes
/// in brackets, which the `Host` header requires; a developer-mode server
/// refuses a management request whose `Host` is not a valid host.
fn host_port(addr: &str, port: u16) -> String {
if addr.contains(':') && !addr.starts_with('[') {
format!("[{addr}]:{port}")
} else {
format!("{addr}:{port}")
}
}

/// Build a Basic auth header value.
Expand Down Expand Up @@ -480,3 +491,16 @@ fn dispatch_cache(c: &Ctx<'_>, action: CacheAction) -> anyhow::Result<(u16, Stri
};
c.req("POST", "/management/cache/invalidate", Some(&body))
}

#[cfg(test)]
mod tests {
use super::host_port;

#[test]
fn host_port_brackets_an_ipv6_bind_address() {
assert_eq!(host_port("127.0.0.1", 18443), "127.0.0.1:18443");
assert_eq!(host_port("localhost", 18443), "localhost:18443");
assert_eq!(host_port("::1", 18443), "[::1]:18443");
assert_eq!(host_port("[::1]", 18443), "[::1]:18443");
}
}
7 changes: 7 additions & 0 deletions crates/config/src/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,13 @@ pub fn build_config_entries(cfg: &AppConfig) -> Vec<(String, String)> {
.throttling_enabled
.map_or("none".into(), |b| b.to_string()),
),
(
"server.dev_allowed_hosts".into(),
cfg.server
.dev_allowed_hosts
.clone()
.unwrap_or_else(|| "none".into()),
),
(
format!("storage.{backend}.connection_string"),
r("connection_string", cfg.storage.connection_config()),
Expand Down
10 changes: 10 additions & 0 deletions crates/config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,15 @@ pub struct ServerConfig {
/// client can hold a connection open. Default 30.
#[serde(default = "default_request_timeout_secs")]
pub request_timeout_secs: u64,
/// Developer mode only: a single comma-separated string of bare host names
/// (no port, scheme or wildcard). The dev-mode host guard serves a browser
/// request, and any request to `/management` or `/metrics`, only under an
/// IP address, `localhost`, a `.localhost` name or one of these names.
/// `docs/manuals/05-admin-guide.md` describes the setting. A production
/// build does not use the value, but an array or a table still stops it at
/// startup.
#[serde(default)]
pub dev_allowed_hosts: Option<String>,
}

fn default_request_timeout_secs() -> u64 {
Expand All @@ -100,6 +109,7 @@ impl Default for ServerConfig {
tls: TlsConfig::default(),
throttling_enabled: None,
request_timeout_secs: default_request_timeout_secs(),
dev_allowed_hosts: None,
}
}
}
Expand Down
22 changes: 22 additions & 0 deletions crates/server/src/console/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,28 @@ const CONTENT_SECURITY_POLICY: &str = "default-src 'none'; script-src 'self'; \
style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'; \
base-uri 'none'; form-action 'self'; frame-ancestors 'none'";

/// Render a standalone 403 page for a browser request the dev-mode host guard
/// refused before any session exists. `message` is the guard's own text, which
/// names the host and the setting; it is HTML-escaped here.
pub(crate) fn host_refused_page(message: &str) -> String {
let content = format!(
r#"<div style="max-width:560px;margin:3rem auto">
<div class="card">
<h1>Request refused</h1>
{alert}
</div>
</div>"#,
alert = html::alert_error(message),
);
html::layout_full(
"Request refused",
r#"<nav><span class="brand">extenddb Console</span></nav>"#,
&content,
None,
None,
)
}

/// Shared state for console handlers.
pub struct ConsoleState {
pub sessions: SessionStore,
Expand Down
Loading
Loading