Skip to content

fix(dev-mode): refuse browser and admin requests for a foreign host - #635

Open
LeeroyHannigan wants to merge 19 commits into
mainfrom
fix/dev-mode-browser-host
Open

LeeroyHannigan wants to merge 19 commits into
mainfrom
fix/dev-mode-browser-host

Conversation

@LeeroyHannigan

@LeeroyHannigan LeeroyHannigan commented Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator

Changes since the last review

  • 662ef9381 corrects the startup sentence for dev_allowed_hosts in the admin guide and in the doc comment of ServerConfig (your note on crates/config/src/lib.rs:92). The config loader reads a number or a boolean as its text, so only an array or a table stops a production build.

What

In developer mode, ExtendDB serves a browser request only when its Host is an IP address, localhost, a .localhost name, or a name in the new server.dev_allowed_hosts setting. The check covers every request to /management and /metrics in the same way, whether or not it looks like a browser request. Any other Host gets a 403.

Production builds do not install the check.

Why

A developer-mode server accepts requests signed with the documented example credentials, and before this change it answered them under any Host. With DNS rebinding, a web page's name points at the loopback address after the page loads. The page is then same-origin with the server, so the browser sends its requests without a preflight. Such a page could create, read and delete tables on a developer's local server. If it knew the admin password, it could also reach the management routes and /metrics. A rebinding page carries its own name in Host, which is none of the allowed values, so the check gives it a 403.

No issue tracks this change.

What is not affected

The AWS CLI, boto3, the JavaScript SDK and other SDK clients send no Origin or Sec-Fetch-Site header. The DynamoDB API serves them as before, also under a Docker Compose service name or host.docker.internal. A developer using the server from 127.0.0.1 or localhost, in a browser or an SDK, needs no configuration, and the console at localhost works unchanged.

How it decides

A request counts as a browser request when it carries an Origin or a Sec-Fetch-Site header. A browser sends Origin on every request whose method is not GET or HEAD, and on every cross-origin CORS request. It sends Sec-Fetch-* headers to loopback and https origins. SDK and CLI clients send neither, so outside the management routes and /metrics the check serves them on any host. A same-origin GET from a page carries no marker, so the check decides the management routes and /metrics on the Host alone.

The host comes from the Host header, or from the request target when there is no Host. A port after the host must be one or more digits. The check refuses any other value after the colon, such as userinfo, as an invalid host.

Other behaviour changes

  • extenddb manage now puts an IPv6 bind address in brackets in its endpoint and its Host header (crates/app/src/manage_http.rs). A dev server bound to ::1 then receives a valid Host.
  • A production build now accepts server.dev_allowed_hosts and does not use it. It reads a number or a boolean as its text, and an array or a table stops it at startup. Main refused the key as unknown, whatever its value.

Merging

The branch has main at a417b2f82 merged in, and git merge-tree against main is clean.

Testing done

  • Unit and router tests: crates/server/src/dev_host_guard/tests.rs has 30. They cover the host parser, the browser marker, the decision for each host class, and the router answers in developer and production mode. cmd_serve.rs checks the banner's host lines, and manage_http.rs checks the IPv6 brackets.
  • cargo test -p extenddb-server -p extenddb-config -p extenddb-app --lib at this head: 107 app, 25 config and 544 server tests pass. Five backup_store tests fail on the test host: they refuse their scratch paths, because the directories above those paths belong to another user there. This change does not touch backup_store.rs.
  • Wire tests: 6 in TestDevModeHostGuard in tests/test_dev_mode_authorization.py, which the run-integration-dev-mode job runs. Against a dev-mode server built from this head, with EXTENDDB__SERVER__DEV_ALLOWED_HOSTS=app.test, the file's 14 tests pass. They pass again in four runs in a row against one server. Without the variable, 13 pass and pytest skips the listed-host test.
  • Each new test fails on the code it checks. The port rows fail with the old port rule. The banner test fails on a banner without the host lines. The listed-host test gets 403 under app.test from a server whose serve passes None to the guard's allowed_hosts. The two exact-answer tests fail on a stub that answers 401, another 400 or 500, where the old != 403 asserts pass.
  • On the wire at this head, an admin GET under 127.0.0.1:1@evil.com gets 403 over HTTP/1.1, over h2c and as an absolute-form target with no Host.
  • cargo fmt --check, clippy with -D warnings and the 1.91.1 check pass on the three crates. Clippy with -W clippy::pedantic reports no warning on the lines this branch adds. actionlint reports the same findings for integration.yml as on main.
  • Before the last review, these measurements ran against a dev-mode server. It served the AWS CLI, boto3, the JavaScript SDK v3, and Node's fetch and node:http under 127.0.0.1, localhost and a Compose service name. A rebinding browser request to the API, to the console login, and to the management routes and /metrics gets a 403. The login POST sets no session cookie. The console login and SDK access at localhost were exercised in Chromium and Firefox.

Checklist

  • I have read CONTRIBUTING.md
  • All tests pass (cargo test --workspace)
  • Code is formatted (cargo fmt --check)
  • Clippy is clean (cargo clippy -- -W clippy::pedantic)
  • I have added or updated tests for new functionality
  • I have updated documentation if behavior changed
  • Breaking changes are noted below (if any)
  • If this changes the wire protocol, Storage trait, auth model, on-disk
    format, or public CLI surface, an RFC has been accepted or is linked
    below. Otherwise, an ADR captures the decision (link below).

ADR / RFC: n/a

Breaking changes

In developer mode, a browser request gets 403 when its host is a name other than localhost or a .localhost name, and server.dev_allowed_hosts does not list it. A browser request is one with an Origin or Sec-Fetch-Site header. Examples are a development proxy that forwards the browser's Host, a hosts-file alias, and a Compose service name that a browser uses. Each needs the name listed. The dev image guide covers each case, and the 403 names the host and the setting.

A call to /management or /metrics gets 403 under the same condition, with or without those headers. Examples are a metrics poller or extenddb manage --endpoint http://extenddb-dev:18080 in another container that uses the Compose service name. Such a client can use the dev container's IP address, which always passes, run extenddb manage in the dev container with docker exec, or list the name. Production builds serve requests as before.


By submitting this pull request, I confirm that my contribution is made under
the terms of the Apache License 2.0 and I agree to the Developer Certificate of
Origin (DCO). See CONTRIBUTING.md for details.

In developer mode the server serves plain HTTP on loopback and opens the IAM
policy decision for an authenticated caller, signing with a seeded example
credential. A web page whose name resolves to the loopback address is then
same-origin with the server, so a browser sends the page's requests to it with
no preflight and the page can sign them with the published credential.

The server now treats a request as a browser request when it carries an Origin
header or a Sec-Fetch-Site header. A browser sends Origin on every request
whose method is not GET or HEAD and on every cross-origin CORS request, and it
sends Sec-Fetch-* headers only to https and loopback URLs. A page script cannot
remove either header. The other Sec-Fetch-* headers do not count on their own,
because Node's built-in fetch sends Sec-Fetch-Mode by itself. The AWS SDKs, the
CLI and Node's fetch send neither header, measured against the CLI, boto3, the
JavaScript SDK v3 and the fetch in Node 22.

In developer mode a browser request is served only when its host is an IP
address, localhost, a name ending in .localhost, or a name the operator lists
in server.dev_allowed_hosts (environment variable
EXTENDDB__SERVER__DEV_ALLOWED_HOSTS). The host comes from the Host header, or
the request target when there is no Host. A missing, repeated or disagreeing
host, or a host that is not a valid name, is refused. Every other browser
request gets 403 before authentication, as the DynamoDB JSON error on the API
and the console error page on the console, naming the host and the setting.
The 403 carries the X-Frame-Options, X-Content-Type-Options and
Referrer-Policy headers that every other response carries.

A same-origin GET or HEAD from a page served over plain HTTP carries neither
header, and the management routes and /metrics answer GET with the admin
password. Every request to /management and below, and to /metrics, is
therefore checked against the host rule whether or not it carries either
header. A client that calls them through another name, such as a Compose
service name, needs that name listed. The CLI's management client connects to
the endpoint it is given or to the configured bind address, and it now puts an
IPv6 bind address in brackets, so a dev server bound to ::1 receives a valid
Host header. Any other request with neither header is served as before,
whatever its host, so a Compose service name, host.docker.internal and the
SDKs keep working on the API. The guard runs in developer-mode builds only;
production serving is unchanged.

The setting is parsed at startup. Entries that are not bare host names are
dropped and named in the startup banner, which states the rule in the sentence
the log also prints.

Tests cover the host parser, the browser marker with the headers Node's fetch
sends, and the decision for each host class, plus router-level cases for the
API, the console and the admin routes in developer and production mode. The
dev-mode wire tests send a browser request and an admin request under a
foreign host to a running server and check the 403 and its security headers.
Describe the developer-mode host check in the dev image guide and add
server.dev_allowed_hosts to the configuration reference and the sample config.

The guide names the headers that mark a browser request and when a browser
sends them, and states the host rule. Every request to the management routes
and /metrics is checked on the host, so a client in another container that
calls them by a Compose service name gets 403; the guide points it at the dev
container's IP address or at docker exec in the dev container instead. A name
is listed when a browser reaches the server through it, for example through a
development proxy that forwards Host or a hosts-file alias for the loopback
address. A listed name is trusted for browser requests as localhost is, so the
guide says to list a name that resolves to the loopback address only when the
developer controls that resolution, and not to list a single-label Compose
service name for a browser on the host. The server sends no CORS headers, so a
page on another origin cannot call it directly. A reverse proxy that rewrites
Host hides the browser's host and has to check Host itself; a proxy that
forwards Host keeps the check.

The guide lists what the check does not cover: a same-origin GET or HEAD from
a page served over plain HTTP, Firefox before 70 and EdgeHTML, and clients
that are not browsers, which a web page cannot drive. The setting is a single
string of bare host names, with no port, scheme or wildcard. The image
properties now say that docker exec can run the extenddb binary in the image,
which the guide's management example uses, but cannot open a shell.
crates/server/src/lib.rs conflicted in two places. The exports keep this
branch's dev_host_guard items and main's longer serve list. In the
router, main's registration layer and this branch's dev-mode host guard
are both installed. The guard is added after the registration layer, so
it runs first, and both still run before the security headers are added.
crates/app/src/cmd_serve.rs keeps the banner lines that main builds in dev_mode_banner_lines, and this branch adds the host rule and the dropped entry notes after them.

crates/config/src/lib.rs keeps request_timeout_secs from main and dev_allowed_hosts from this branch in ServerConfig and in its Default.

crates/server/src/lib.rs keeps the repeated header refusal, the security headers and the body timeout from main. The host guard from this branch goes inside those layers.

docs/manuals/05-admin-guide.md keeps the region and request_timeout_secs rows from main and the dev_allowed_hosts row from this branch.

tests/test_dev_mode_authorization.py keeps the stream ARN tests and their imports from main and the host guard tests and the requests import from this branch.
…fusal

Main now refuses a request with more than one host or authorization header on every route, in repeated_headers::refuse_repeated_headers (#355). In start_server that layer runs outside the dev-mode host guard. The guard never sees a repeated Host header, so its own refusal for that case cannot run.

This commit removes the RepeatedHost refusal from the guard and its case from the unit test. The guard reads the one Host header. A request with a repeated Host header still gets the 400 that main sends on every route.
docs/dev-image.md keeps the cc-debian13 base from main and the `docker exec`
sentence from this branch.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

#1325 adds a Content-Security-Policy to the console's HTML responses. It sets the header with a layer on the console router. The HTML 403 that reject_response in dev_host_guard.rs sends for paths under /console comes from a layer around the whole app, so it gets no policy. The page is built with host_refused_page, which loads console.js. When this branch takes #1325, the refused page needs the same header, from console::html_policy or CONTENT_SECURITY_POLICY in crates/server/src/console/mod.rs. The docs of #1325 say that every HTML response under /console carries the policy.

Both branches also add a block after use session::SessionStore; in crates/server/src/console/mod.rs. Git reports a conflict there, and the fix keeps both blocks.

@demohan demohan self-assigned this Nov 24, 2026

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The guard closes the rebinding path. On the merge-base, a page served under a rebinding name logs in to the console and reads the admin routes in headless Chromium 148 and Firefox 150; on this head both are refused, and the same page under localhost is served. 1762 probes over HTTP/1.1 and HTTP/2, run on head and the merge-base, give 1159 identical outcomes and 601 guard refusals, with the guard's empty 403 on HEAD the only other difference.

  • Loopback names and addresses, with or without a port, a trailing dot or mixed case, .localhost names, and IP addresses pass. Foreign and malformed hosts, a missing Host with a marker, and Host against absolute-form or :authority mismatches in both orders are refused. Duplicate Host still gets the existing 400.
  • //metrics, /%6detrics, /METRICS, /./metrics and /x/../metrics answer 404, and /metrics/, query strings and HEAD on admin routes answer 403.
  • The guard sits inside the repeated-header refusal and outside the registration check, routing, authentication and the body limit, and its 403s carry the security headers. There are no extension routes or other listeners to cover.
  • boto3, the AWS CLI, the JavaScript SDK v3, Node fetch and node:http are served as on the merge-base, including under a Compose-style Host and host.docker.internal, and the console works in a browser at localhost, 127.0.0.1 and app.localhost. The intended change is that an admin GET under a Compose service name gets 403.
  • The TOML string, the environment variable replacing it, dropped-entry notes and case-insensitive matching behave as documented. extenddb manage against ::1 works through --config and --endpoint.
  • Production builds of head and main answer alike on 12 rows over TLS, HTTP/1.1 and HTTP/2, and the guard is not installed even with the key set.
  • docs/dev-image.md followed step by step on an image built from this head holds, including the Compose service name 403 for extenddb manage.

fmt, both clippy variants and the 1.91.1 MSRV check are clean, 661 tests pass across the three touched crates, CI is green with the dev-mode job running the 5 new tests, and every negative control on the new unit and wire tests fails.

I will approve once the allowed-hosts setting has a test and the items below are in.


// Dev-mode host guard names, parsed and logged by `dev_host_guard`.
let raw_hosts = app_config.server.dev_allowed_hosts.as_deref();
let dev_allowed_hosts = crate::dev_host_guard::allowed_hosts(dev_mode, raw_hosts);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing tests that server.dev_allowed_hosts reaches the guard. With this line passing None, the 541 server unit tests and the 5 new wire tests pass, and a browser POST under the listed host app.test gets 403 where this head serves it. A wire test in the dev-mode job that sets EXTENDDB__SERVER__DEV_ALLOWED_HOSTS and checks a browser POST and an admin GET under that name would hold it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 4a72ee5. The dev-mode CI job now sets EXTENDDB__SERVER__DEV_ALLOWED_HOSTS=app.test for every step, and the new test_a_listed_host_is_not_refused sends two requests under Host: app.test. An unsigned ListTables with Origin: http://app.test expects 400 with the MissingAuthenticationToken body, and an admin GET with no credentials expects 401 Missing Authorization header. The admin GET first sent a wrong password, and the server counted it as a failed login. The third run of the file against one server then got 429. 1439151 removes the password.

With this line passing None, that test gets 403 under app.test and fails, and the other 13 tests in the file pass. The test skips when the variable doesn't list app.test, so a local run without it doesn't fail.

}
inner
} else {
match raw.split_once(':') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything after the first colon is dropped without checking it is a port, so userinfo or a junk port after a loopback name reads as that name. With admin Basic auth, GET /management/accounts answers 200 for Host: 127.0.0.1:1@evil.com, Host: localhost:x@evil.com, Host: 127.0.0.1:abc, the absolute-form target http://127.0.0.1:1@evil.com/... and h2c :authority: 127.0.0.1:1@evil.com. A browser does not send these values. Accepting only digits after the colon, refusing @, and these values as unit rows would close it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 122be9a. host_label reads a port only when it's one or more ASCII digits, after a name and after a bracketed IPv6 address, and returns None for anything else.

New unit rows cover 127.0.0.1:1@evil.com, localhost:x@evil.com, 127.0.0.1:abc, [::1]:abc and localhost:, and the absolute-form target http://127.0.0.1:1@evil.com/management/accounts with no Host. With the old port rule put back, host_label returns the loopback name for all five and evaluate allows the absolute-form row.

On a dev-mode server at this head, an admin GET under 127.0.0.1:1@evil.com gets 403 over HTTP/1.1, over h2c and as an absolute-form target.

Comment thread docs/dev-image.md Outdated
development environment forwards to the server, if it passes the browser's
`Host` through unchanged.

The server sends no CORS headers, so a page on another origin cannot call it

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"A page on another origin cannot call it directly" holds for API calls, whose preflight gets 405. A cross-origin form POST to /console/login under Host localhost gets 303 and a session cookie, because the guard reads Host and not Origin. The sentence can name API calls.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9b0fa13. The sentence now says a page on another origin can't call the DynamoDB API. The paragraph adds that a form on another origin can still post to the console login page. A form post needs no preflight, and the check reads the host from Host.

On a dev-mode server at this head, a form POST to /console/login under Host: localhost:18769 with Origin: http://app.test:3000 gets 303 with Location and Set-Cookie, the same answer as with a localhost Origin.

Comment thread docs/dev-image.md Outdated
web page whose name resolves to the loopback address cannot use the seeded
credential or log in to the console. The allowance for `.localhost` names
assumes a browser that resolves them to the loopback address itself. Chrome,
Firefox and Edge do; Safari on macOS hands them to the system resolver.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Safari on macOS hands .localhost names to the system resolver, and the guard allows every *.localhost name. Where that resolver forwards to the network, the rebinding the guard stops for other names is open for these, the same reason the doc gives for single-label Compose names. A sentence here, or allowing only localhost by default, would cover it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9b0fa13. The Safari sentence now goes on to say that the system resolver can pass a .localhost name to a DNS server on the network. That server can answer with its own address and serve a page under the name. When it then answers with the loopback address, the check serves that page's requests.

.localhost names stay allowed by default. Chrome, Firefox and Edge resolve them to the loopback address themselves, and your review had the console working at app.localhost.

Comment thread crates/config/src/lib.rs Outdated
/// `/management` and `/metrics` the same way whether or not it carries
/// either header. This stops a page whose name resolves to the loopback
/// address from driving the local server. Entries that are not bare host
/// names are dropped with a startup warning. Ignored outside a dev-mode

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A production build ignores a string value, and stops at startup on an array: invalid type: sequence, expected a string for key server.dev_allowed_hosts. The same wording is in 05-admin-guide.md:121 and extenddb.sample.toml:54.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 9b0fa13. The field doc and the admin guide row now say that a production build doesn't use the value. A value that isn't a string still stops it at startup. The sample config's comment on the setting is now two lines that point to the admin guide row.

With the config crate at this head, dev_allowed_hosts = "app.test,api.test" deserializes, and dev_allowed_hosts = ["app.test"] fails with invalid type: sequence, expected a string. On main both fail as an unknown field.

Comment thread crates/app/src/cmd_serve.rs Outdated
&dev_creds,
dev_credentials::ignored_aws_env_key(&dev_creds).as_deref(),
);
// The host rule the server enforces, so the operator sees it without

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the banner lines for the rule, the listed hosts and the dropped entries removed, the 96 app tests pass. The body's test for the dropped-entry note covers its text in the server crate.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in bad3f3d. dev_mode_banner_lines now takes the two lists that parse_dev_allowed_hosts returns, and it ends the banner with the rule line and a note for each dropped entry. dev_banner_ends_with_the_host_rule_and_each_dropped_entry checks those two lines by equality. With the lines removed from dev_mode_banner_lines, that test fails.

print_dev_mode_banner gets the lists from parse_dev_allowed_hosts, the function that the guard's allowed_hosts calls in serve.

Comment thread tests/test_dev_mode_authorization.py Outdated

def test_same_request_without_a_marker_is_not_refused(self, endpoint_url):
resp = _list_tables_unsigned(endpoint_url, {})
assert resp.status_code != 403, resp.text

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!= 403 passes on a 5xx, and with no admin password set in CI the admin GET passes on a 401, so neither shows the route is served. The same holds at :360.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 47ecd4f and 1439151, at both places. test_same_request_without_a_marker_is_not_refused asserts 400 and {"__type": "com.amazon.coral.service#MissingAuthenticationToken", "message": "Missing Authentication Token"} by equality. test_admin_get_under_the_endpoint_host_is_not_refused sends no credentials and asserts 401 with the body Missing Authorization header. It first sent a wrong password. A wrong password counts as a failed login, so the third run of the file against one server got 429.

Against a stub that answers 401, another 400 or a 500, both tests fail, and the old != 403 versions pass.

Comment thread docs/dev-image.md
address, and run `extenddb manage` inside the dev container, where `127.0.0.1`
reaches the server. The image has no config file, so give the endpoint:

```bash

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional. <pw> comes from the first-start log line or EXTENDDB_ADMIN_PASSWORD, and --password makes the CLI print its own warning to use EXTENDDB_PASSWORD.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done in 9b0fa13. The example is now docker exec -e EXTENDDB_PASSWORD <container> extenddb manage --endpoint http://127.0.0.1:18080 --user admin list-accounts. The paragraph says to set EXTENDDB_PASSWORD to the admin password from the first-start log line or EXTENDDB_ADMIN_PASSWORD.

-e with no value copies the variable from the shell, so the password isn't on the command line and the CLI prints no --password warning.

crates/server/src/response.rs keeps error_response from this branch, which
takes the status from the error and calls error_response_with_status. In
error_response_with_status the body now comes from error_document, as on main.
host_label took everything after the first colon of a Host header or a request
target as the port, unless that text held a second colon. A value such as
127.0.0.1:1@evil.com, 127.0.0.1:abc or localhost: then read as the loopback
name before the colon. The guard served an admin request under such a value.

host_label now reads a port only when it is one or more ASCII digits, after a
name and after a bracketed IPv6 address. For any other value it returns None,
so the guard refuses a browser request or an admin request that carries the
value. New unit rows cover userinfo, a port name and an empty port after a
loopback name. Another row sends an absolute-form target with userinfo and no
Host header.
…ch them

The dev-mode banner's host rule line and its notes for dropped entries came
from print_dev_mode_banner, which no test calls.

dev_mode_banner_lines now takes the names that parse_dev_allowed_hosts kept
and the entries it dropped. It ends the banner with the rule line and one note
for each dropped entry, in the same order as before. print_dev_mode_banner gets
the two lists from parse_dev_allowed_hosts, the function that the host guard's
allowed_hosts calls in serve. A new app test checks the last two banner lines
by equality.
… serves

test_same_request_without_a_marker_is_not_refused and
test_admin_get_under_the_endpoint_host_is_not_refused asserted only that the
status was not 403, so a 5xx passed both. The CI job sets no admin password,
and there the admin GET passed on a 401 for the wrong password.

The ListTables test now asserts 400 and the MissingAuthenticationToken body by
equality. The admin GET sends a password the server does not have and asserts
401 with the body Invalid credentials. Both answers come from authentication,
which runs after the host guard.
No test set server.dev_allowed_hosts. A serve that gave the guard no names
passed every server unit test and every dev-mode wire test.

The dev-mode CI job now sets EXTENDDB__SERVER__DEV_ALLOWED_HOSTS=app.test for
every step. The server reads the variable at startup, and the new
test_a_listed_host_is_not_refused reads it too. Under Host app.test the test
sends an unsigned ListTables with an Origin header and expects 400 with the
MissingAuthenticationToken body. It then sends an admin GET with a wrong
password and expects 401 with the body Invalid credentials. When the variable
does not list app.test, pytest skips the test with a reason that names the
variable. A local run against a server without the setting then does not fail.
docs/dev-image.md said that a page on another origin cannot call the server.
That holds for the DynamoDB API, whose preflight gets 405. A form on another
origin can still post to the console login page. A form post needs no
preflight, and the check reads the host from Host. The guide now says both.

The guide said that Safari hands .localhost names to the system resolver but
not what follows. That resolver can pass the name to a DNS server on the
network. The DNS server can serve a page under the name and then answer with
the loopback address. The guide now says so, and .localhost names stay allowed.

The docker exec example passed --password, which makes the CLI print a
warning. It now passes EXTENDDB_PASSWORD into the container and says where the
admin password comes from.

The admin guide, the sample config and the ServerConfig field doc said that a
production build ignores server.dev_allowed_hosts. A production build does not
use the value, but a value that is not a string still stops it at startup. The
admin guide and the field doc now say that. The sample config's 26-line comment
on the setting is now two lines that point to the admin guide row. The
ServerConfig field doc now states the host rule in one sentence and names the
admin guide. The AppState field doc no longer repeats the rule.
…credentials

Two tests check that an admin GET passes the host check, one under the
endpoint host and one under a listed name. Each sent a wrong password and
expected 401 "Invalid credentials". The server counts a wrong password as a
failed login. After 5 failures in 15 minutes it refuses that user from that
address. So the third run of the file against one server failed with 429.

The two GETs now send no Authorization header and expect 401 "Missing
Authorization header". The server answers a missing header before it checks
the rate limits, and it records no failure. A comment that repeated the
listed-host test's docstring is gone.
The README lists the server's HTTP checks that the WebAssembly build has no
counterpart for. The developer-mode host check is one of them. The list now
names it as the refusal of a browser request or a /management or /metrics
request whose host the check does not allow.

The host_label doc comment now lists two more malformed values that return
None. One is an opening bracket with no closing one. The other is text after
the closing bracket other than a port, such as `[::1]evil`. The module doc puts
DynamoDB and EdgeHTML in backticks, and dropped_entry_note, rule_line and
parse_dev_allowed_hosts are #[must_use]. That clears the five clippy::pedantic
warnings on lines this branch adds.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

The allowed-hosts setting now has a wire test in the dev-mode job (4a72ee5), and each thread has its fix and commit. 2b1f0ca merges main at a417b2f.

The body now lists the changes since your review and the IPv6 brackets in extenddb manage. Under Breaking changes it names the 403 for a browser request under a name the setting does not list. It also names the 403 for a client that calls /management or /metrics by a Compose service name.

demohan
demohan previously approved these changes Nov 25, 2026

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The items from the earlier review are resolved at 57e5261.

  • server.dev_allowed_hosts reaches the guard. With EXTENDDB__SERVER__DEV_ALLOWED_HOSTS=app.test, a browser POST under app.test, app.test:P, APP.TEST and app.test. answers 400 MissingAuthenticationToken, an admin GET answers 401 without credentials and 200 with them, over HTTP/1.1, h2c and absolute-form targets; without the setting each answers 403. The TOML string works, the variable replaces it, x.app.test and app.test.evil still answer 403, and the banner lists what the guard uses. test_a_listed_host_is_not_refused fails with None passed at serve.rs:658, and CI runs and passes it.
  • The port rule holds. Host: 127.0.0.1:1@evil.com, which answered 200 with the account list at ec02041, answers 403, as do localhost:x@evil.com, 127.0.0.1:abc, [::1]:abc and other junk-port and userinfo forms, through Host, h2c :authority and absolute-form targets. Over 551,880 generated values the host is read only from the whole value less a trailing dot, a digit port and brackets; head accepts nothing the earlier parser refused, and every form a client sends answers as it did. Restoring either half of the old rule fails the new unit rows.
  • The docs match: a cross-origin form POST to /console/login gets 303 and a session cookie, the API preflight gets 405, the docker exec -e example works, and the wire tests at :342 and :360 fail against stub servers answering 500, 401 or 400. fmt, clippy with and without sqlite-memory,dev-mode, the 1.91.1 check and 549 server, 25 config and 107 app tests are clean. The one failing CI job, wasm, fails building crates/core, which this PR does not touch; it fails on main since #398.

Comment thread crates/config/src/lib.rs Outdated
/// 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 a value that is not a string still

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A production build starts and listens with dev_allowed_hosts = 5, = true or = 1.5, twice each; only an array or a table stops it. In a dev-mode build = true lists a host named true. The same sentence is in docs/manuals/05-admin-guide.md:121. "an array or a table still stops it at startup" would match.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 662ef93. The config loader reads a number or a boolean as its text, so a production build starts with dev_allowed_hosts = 5, = true or = 1.5. Only an array or a table stops it. The doc comment and the admin guide now say that, with your wording.

The admin guide and the doc comment of ServerConfig.dev_allowed_hosts said
that a value that is not a string stops a production build at startup. The
config loader reads a number or a boolean as its text, so a production
build starts with dev_allowed_hosts = 5, = true or = 1.5. Only an array or
a table stops it. Both places now say that.
demohan
demohan previously approved these changes Nov 25, 2026

@demohan demohan left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

662ef93 changes only the sentence in crates/config/src/lib.rs and docs/manuals/05-admin-guide.md, which now names an array or a table, as a production build answers. The rest is as approved at 57e5261.

@LeeroyHannigan
LeeroyHannigan added this pull request to the merge queue Nov 27, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Nov 27, 2026
Main moved the WebAssembly build's section from README.md to its own
page, docs/webassembly.md (#1521). The merge keeps main's README.md.
This branch added a sentence about the developer-mode host check to
that section. The merge puts the sentence in docs/webassembly.md, in
the list of the server's HTTP checks that have no counterpart in
submit(operation, body).
Since #1290, the server gives a request with no Authorization header
the type MissingAuthenticationTokenException and the message "Request
is missing Authentication Token". DynamoDB sends this answer. The tests
test_same_request_without_a_marker_is_not_refused and
test_a_listed_host_is_not_refused compared the body with the earlier
type and message. They failed in the merge queue run of 27 Nov, on
main c175e42.
Main added the console's Content-Security-Policy (#1325) at the place in
crates/server/src/console/mod.rs where this branch adds
host_refused_page. The merge keeps both: the policy constant, then the
page.
@LeeroyHannigan

Copy link
Copy Markdown
Collaborator Author

@demohan I merged main into this branch again (e61bc61), because #1325 put the console's Content-Security-Policy next to host_refused_page in crates/server/src/console/mod.rs. The merge keeps both, and the PR's own changes are the same, file by file. On the merge, the dev-mode wire tests pass (14 of 14), and the dev host guard and console unit tests pass.

This branch has not been deployed

No deployments
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.

2 participants