Repository navigation
fix(dev-mode): refuse browser and admin requests for a foreign host - #635
LeeroyHannigan wants to merge 19 commits into
Conversation
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.
|
#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 Both branches also add a block after |
demohan
left a comment
There was a problem hiding this comment.
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,
.localhostnames, and IP addresses pass. Foreign and malformed hosts, a missing Host with a marker, and Host against absolute-form or:authoritymismatches in both orders are refused. Duplicate Host still gets the existing 400. //metrics,/%6detrics,/METRICS,/./metricsand/x/../metricsanswer 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
fetchandnode:httpare served as on the merge-base, including under a Compose-style Host andhost.docker.internal, and the console works in a browser atlocalhost,127.0.0.1andapp.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 manageagainst::1works through--configand--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); |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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(':') { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
"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.
There was a problem hiding this comment.
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.
| 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. |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| /// `/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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
| &dev_creds, | ||
| dev_credentials::ignored_aws_env_key(&dev_creds).as_deref(), | ||
| ); | ||
| // The host rule the server enforces, so the operator sees it without |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
|
||
| 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 |
There was a problem hiding this comment.
!= 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.
There was a problem hiding this comment.
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.
| 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
|
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 |
demohan
left a comment
There was a problem hiding this comment.
The items from the earlier review are resolved at 57e5261.
server.dev_allowed_hostsreaches the guard. WithEXTENDDB__SERVER__DEV_ALLOWED_HOSTS=app.test, a browser POST underapp.test,app.test:P,APP.TESTandapp.test.answers 400MissingAuthenticationToken, 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.testandapp.test.evilstill answer 403, and the banner lists what the guard uses.test_a_listed_host_is_not_refusedfails withNonepassed atserve.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 dolocalhost:x@evil.com,127.0.0.1:abc,[::1]:abcand other junk-port and userinfo forms, through Host, h2c:authorityand 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/logingets 303 and a session cookie, the API preflight gets 405, thedocker exec -eexample works, and the wire tests at:342and:360fail against stub servers answering 500, 401 or 400. fmt, clippy with and withoutsqlite-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 buildingcrates/core, which this PR does not touch; it fails on main since #398.
| /// 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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
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.
|
@demohan I merged main into this branch again (e61bc61), because #1325 put the console's Content-Security-Policy next to |
Changes since the last review
662ef9381corrects the startup sentence fordev_allowed_hostsin the admin guide and in the doc comment ofServerConfig(your note oncrates/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
Hostis an IP address,localhost, a.localhostname, or a name in the newserver.dev_allowed_hostssetting. The check covers every request to/managementand/metricsin the same way, whether or not it looks like a browser request. Any otherHostgets 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 inHost, 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
OriginorSec-Fetch-Siteheader. The DynamoDB API serves them as before, also under a Docker Compose service name orhost.docker.internal. A developer using the server from127.0.0.1orlocalhost, in a browser or an SDK, needs no configuration, and the console atlocalhostworks unchanged.How it decides
A request counts as a browser request when it carries an
Originor aSec-Fetch-Siteheader. A browser sendsOriginon every request whose method is not GET or HEAD, and on every cross-origin CORS request. It sendsSec-Fetch-*headers to loopback andhttpsorigins. SDK and CLI clients send neither, so outside the management routes and/metricsthe check serves them on any host. A same-origin GET from a page carries no marker, so the check decides the management routes and/metricson theHostalone.The host comes from the
Hostheader, or from the request target when there is noHost. 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 managenow puts an IPv6 bind address in brackets in its endpoint and itsHostheader (crates/app/src/manage_http.rs). A dev server bound to::1then receives a validHost.server.dev_allowed_hostsand 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
a417b2f82merged in, andgit merge-treeagainst main is clean.crates/server/src/lib.rs. Both sides add a module declaration and apub useblock at the same place: theirextensions, and this branch'sdev_host_guard. The resolution keeps both. Their four other conflicts are with main.crates/server/src/console/mod.rs, where both branches add a block afteruse session::SessionStore;. The resolution keeps both. The HTML 403 thatreject_responsesends for a/consolepath then needs the policy header that fix(console): serve the pages under a Content-Security-Policy that runs no inline script #1325 adds, fromconsole::html_policyorCONTENT_SECURITY_POLICY.crates/server/src/response.rs. fix(server): answer by media type, method and path as DynamoDB does #1079 builds the success and error answers with a newwire_response, and this branch splitserror_responseso that the guard can set the status. The resolution keepserror_response_with_statusand builds its answer withwire_response.crates/server/src/response.rs, and fix(server): parse request bodies nested to the depth the service validates #807, fix(server): send no message for a body with a JSON syntax fault #1261, fix(server): authenticate a request with an empty body first #1265, fix(server): read a number written with leading zeros in a request body #1344 and fix(server): read a trailing point and a lone minus sign in a request number #1372 incrates/server/src/lib.rs. docs: configuration reference generated from the sample file, pinned to the structs #537 conflicts indocs/manuals/05-admin-guide.mdandextenddb.sample.toml, and feat(migrations): the startup policy, serve --migrate and [server] catalog_upgrade #741 in those two files and incrates/config/src/display.rsandcrates/config/src/lib.rs. feat: add StartBulkPutItems and the bulk operation APIs #874 conflicts incrates/app/src/cmd_serve.rs, where it moves the tests tocmd_serve_tests.rs, so the banner tests of this branch move with them. feat(auth): add EXTENDDB_DEV_IGNORE_CLOCK_SKEW for dev-mode builds #1125 conflicts indocs/dev-image.md. docs: configuration reference generated from the sample file, pinned to the structs #537, feat(migrations): the startup policy, serve --migrate and [server] catalog_upgrade #741 and feat: add StartBulkPutItems and the bulk operation APIs #874 also conflict with main in other files.Testing done
crates/server/src/dev_host_guard/tests.rshas 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.rschecks the banner's host lines, andmanage_http.rschecks the IPv6 brackets.cargo test -p extenddb-server -p extenddb-config -p extenddb-app --libat this head: 107 app, 25 config and 544 server tests pass. Fivebackup_storetests 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 touchbackup_store.rs.TestDevModeHostGuardintests/test_dev_mode_authorization.py, which therun-integration-dev-modejob runs. Against a dev-mode server built from this head, withEXTENDDB__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.app.testfrom a server whoseservepassesNoneto the guard'sallowed_hosts. The two exact-answer tests fail on a stub that answers 401, another 400 or 500, where the old!= 403asserts pass.127.0.0.1:1@evil.comgets 403 over HTTP/1.1, over h2c and as an absolute-form target with noHost.cargo fmt --check, clippy with-D warningsand the 1.91.1 check pass on the three crates. Clippy with-W clippy::pedanticreports no warning on the lines this branch adds.actionlintreports the same findings forintegration.ymlas on main.fetchandnode:httpunder127.0.0.1,localhostand a Compose service name. A rebinding browser request to the API, to the console login, and to the management routes and/metricsgets a 403. The login POST sets no session cookie. The console login and SDK access atlocalhostwere exercised in Chromium and Firefox.Checklist
cargo test --workspace)cargo fmt --check)cargo clippy -- -W clippy::pedantic)Storagetrait, auth model, on-diskformat, 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
localhostor a.localhostname, andserver.dev_allowed_hostsdoes not list it. A browser request is one with anOriginorSec-Fetch-Siteheader. Examples are a development proxy that forwards the browser'sHost, 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
/managementor/metricsgets 403 under the same condition, with or without those headers. Examples are a metrics poller orextenddb manage --endpoint http://extenddb-dev:18080in another container that uses the Compose service name. Such a client can use the dev container's IP address, which always passes, runextenddb managein the dev container withdocker 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.