Kozou is an open-source tool that exposes structured context from your PostgreSQL database to AI agents, over MCP and a REST API.
In the previous post, I wrote about why Kozou's remote MCP is built as an OAuth resource server, and closed on server.mcp.http.advertisedUrl (v1.18.0). The resource URI is declared in configuration, not derived from the Host header — and that discipline from the OAuth side, I wrote, had carried over to deployments that use no OAuth. I ended that part with the line "An unplanned dividend on a rule drawn for strictness."
That dividend was only half paid.
The address you wrote in advertisedUrl did reach the connection page — the screen that produces the connection settings for an AI agent. That is as far as the previous post went, and what it said still holds. But the DNS-rebinding guard was not reading the same value. And the startup warning about running with no authentication was looking at something else: the bind address. In the words of the v1.20.0 release commit, advertisedUrl reached the connection page and "nothing else".
This post is a record of how Kozou v1.20.0 through v1.21.0 (2026-10-18 to 10-19) fixed that. Three kinds of things were fixed. The declaration had too few readers. Refusal messages read values aloud more than they should. And the reason for a refusal wasn't told to the one who needed it. There is one thing I want to say through all of it: a declared value becomes a declaration only when every reader that should read it actually does.
Everything below is as of Kozou v1.21.0 (2026-10-19). The output shown was captured by running kozou@1.21.0, as published on npm, on my own machine. Before publishing, I reran the same procedure against kozou@1.21.2 and confirmed that the output shown here is unchanged, character for character. No database was connected (for this procedure, capturing the output of startup and of the authentication stage didn't need one). All hostnames and credentials are fictitious.
The declaration only reached the page
Start with the symptom. Run Kozou's MCP endpoint without OAuth, put a tunnel or a reverse proxy in front of it, and write the externally reachable address, https://mcp.example.com/mcp, into advertisedUrl. If the tunnel forwards requests with the original Host header intact, then through v1.19.0 this is where things stopped. In the v1.20.0 release commit's words, "every request through such a tunnel or proxy was refused with 403". Nor is this an unusual shape. According to the fix commit, cloudflared and ngrok both forward the original Host as-is unless told to rewrite it.
What refused those requests was the DNS-rebinding guard. A malicious page repoints its own domain name at a loopback address and uses your browser to hit an unauthenticated endpoint on your machine. The browser sets Host honestly from the page's URL, so refusing any hostname you haven't allowed stops this. But as the implementation's comment says, "it is not network access control". A non-browser client can put whatever it likes in Host, so who can reach an unauthenticated endpoint is something only the network — what you bind and publish — can narrow.
So what did that guard allow? Here is the v1.19.0 source:
const guard = buildRebindingGuard(host, { allowedHosts: [ ...(opts.allowedHosts ?? []), ...(auth === undefined ? [] : [auth.resource.hostname]), ], The only declared value that went into the guard was the hostname of auth.resource, in OAuth mode. (Besides that, it took the loopback names; the bind address, when bound to a specific non-loopback address; and any allowedHosts passed in by a library consumer. Binding to 0.0.0.0 or :: adds nothing.) In v1.19.0's MCP server package (packages/mcp/src), the word advertisedUrl does not appear even once.
OAuth mode's declared value had been in the guard since v1.13.0, when OAuth mode arrived. So in the OAuth mode the previous post covered, a request arriving under the declared hostname doesn't run into this 403. advertisedUrl carried the OAuth side's answer — "declare it" — over to deployments without OAuth. But only the wiring to the connection page came along. The wiring to the guard didn't.
In v1.20.0, the hostname of advertisedUrl went into the guard too. The comment puts it this way: the declared value is "config-declared (never derived from a header), and it is exactly the name a tunnel / reverse proxy forwards". Because it isn't derived from a header, there's no spoofing concern — and the name a tunnel or proxy carries in is exactly that one.
Start v1.21.0 with only advertisedUrl set, and the declared hostname shows up in the guard's startup line:
[kozou mcp] DNS-rebinding guard: accepting Host names 127.0.0.1, localhost, ::1, mcp.example.com (add more with server.mcp.http.allowedHosts) The bind stays at the default 127.0.0.1:3334. I sent it requests with only the Host header replaced (the same shape as a tunnel forwarding the original Host). The declared mcp.example.com got a 200, and the undeclared other.example.com got a 403 (Host header is not allowed for this server.).
For names you can't derive from the declaration — a second external route, or a name used on an internal network — server.mcp.http.allowedHosts was added (KOZOU_MCP_HTTP_ALLOWED_HOSTS as an environment variable). The v1.19.0 kozou CLI had no config key for adding names to the guard at all. And kozou-mcp, the standalone launcher that reads no config file, ignored even KOZOU_MCP_HTTP_ADVERTISED_URL, according to the release commit. Here, too, was a reader that wasn't reading the declaration.
You only need to write a declaration in one place. But if only one party reads it, it isn't so much a declaration as a setting addressed to that one reader.
The most exposed deployment was the quietest
The guard wasn't the only thing not reading the declaration.
Kozou's MCP endpoint already had a startup warning. Bind to a non-loopback address without configuring authentication, and it tells you that this MCP HTTP server has no authentication. What it judged by was the bind address.
But in the standard shape — behind a tunnel or a reverse proxy — Kozou binds to loopback, because getting out to the world is the tunnel's or the proxy's job. That deployment doesn't meet the warning's condition. An endpoint reachable from the internet without authentication gave no warning at startup. The comment on the function added in v1.20.0 says it in one sentence:
the standard tunnel and reverse-proxy shape binds loopback, so the loudest deployment is the quietest one.
v1.20.0 kept the existing bind-address warning and added a second one, judged on a different input. If the declared reachable address faces outward and no authentication is configured, it prints a WARNING at startup. What this one looks at isn't "where am I listening" but "where did you declare I'm reached". Here the declaration gained its third reader.
Start it with the same configuration as before — only advertisedUrl: https://mcp.example.com/mcp, and no authentication — and you get this:
[kozou mcp] WARNING: this endpoint is declared reachable at "https://mcp.example.com/mcp", [kozou mcp] which is not a local address, and it runs no authentication of its own. [kozou mcp] Anyone who can reach it can read this database's schema metadata [kozou mcp] and force a schema re-read (POST /admin/refresh is open in this mode). [kozou mcp] To authenticate each caller: move this address to auth.resource, drop [kozou mcp] advertisedUrl (the two are refused together) and configure [kozou mcp] server.mcp.http.auth. Otherwise keep the address private, or front it [kozou mcp] with a layer that authenticates before kozou sees the request — over [kozou mcp] https, since credentials would then cross this address too. [kozou mcp] MCP HTTP listening on http://127.0.0.1:3334 (MCP: /mcp, refresh: POST /admin/refresh) As the last line shows, the bind is 127.0.0.1. The warning through v1.19.0 would have stayed silent in this configuration, and now something speaks up. In this configuration (no call tool), the warning names what a caller can reach: schema metadata, and a schema re-read (POST /admin/refresh). It says "of its own" because Kozou can't see whether there is an authenticating layer in front of it. Even with an authenticating layer in front, as long as you declare an outward-facing advertisedUrl, this warning prints on every startup — Kozou can't see the layer, and there is no setting to silence it. The new warning stays quiet when the declared address is loopback, when there is no declaration, and in OAuth mode.
The remedy is worded the way it is for a reason, too. The warning doesn't say "configure authentication". It says to move the address to auth.resource, drop advertisedUrl, and configure server.mcp.http.auth. That's because advertisedUrl and auth can't be written together. (The previous post touched on this as well. Make people write the same address in two places, and when the two disagree, you have to decide which one to believe.) Say only "add auth", and someone who follows it faithfully adds auth while keeping advertisedUrl — and runs into a startup error. The function's comment says:
The remedy has to be the one that actually boots:
advertisedUrlis refused alongsideauth, so "add auth" alone would send the operator into a startup error. The address has to move, not be duplicated.
You can't decide whether to warn from the bind address alone. A bind says where you wait; the danger lies in where you can be reached from. And the remedy a warning recommends has to be one that actually boots when followed.
A warning that fires every time stops being read
There was silence in the other direction, too: OAuth mode, bound to a non-loopback address.
Here the existing warning was suppressed, and suppressing it was right. The warning's second line says there is no authentication, and OAuth mode has authentication. Printing it would be, in the fix commit's words, "the server lying about its own posture".
But along with that suppression, a risk that OAuth mode adds rather than removes went quiet as well. Kozou's MCP listener speaks plaintext http and doesn't terminate TLS itself. A bearer token sent straight to the port crosses the network unencrypted. The advertised values, meanwhile, are checked strictly: a plaintext http auth.resource pointing at a non-loopback address is a startup error unless you explicitly set allowInsecureHttp, which exists for isolated test networks (covered in the previous post). Yet the socket itself said nothing.
This gap turned up in the course of fact-checking the previous post, and I filed it as kozou#278. The fix is in v1.20.0.
What v1.20.0 added was not a WARNING but a NOTE. The commit gives its reason:
a warning would fire on the sanctioned deployment every single time
Both Compose stacks that Kozou ships bind to 0.0.0.0 inside the container. That is the intended, sanctioned deployment. Make it a WARNING, and it fires on that deployment every time. People get used to a warning that fires every time; the commit calls this desensitization.
Like a declaration, a warning is a warning only if someone reads it. To avoid a way of firing that loses its readers, a NOTE — one step weaker — was chosen here.
What a refusal must not read aloud
From here the direction reverses. So far it has been about too few readers of the declaration; now it's about a side that read out too much.
v1.19.0's CLI sometimes quoted a config value whole when it refused it: when advertisedUrl carried a query or a fragment, and when it couldn't be parsed as a URL. A URL can contain credentials (the alice:example-password in https://alice:example-password@mcp.example.com/mcp — the userinfo part). Quote the value, and that goes into the log along with the refusal. An unparseable value isn't safe either. According to the v1.20.0 release commit, in https://user:pw with the host left out, the password is read as a port number, and the URL parser doesn't treat it as a credential.
v1.20.0's CLI refuses a value containing userinfo — on the grounds of the userinfo — ahead of any refusal that would quote the whole value. An unparseable value is refused without being quoted. The query and fragment refusals stopped quoting the value in the next release, v1.20.1; its release commit describes the query and fragment as "where a token usually goes". Write a value with userinfo in v1.21.0 and you get this (I've left out the last line, which shows where the config file is):
Invalid kozou config: 1 issue(s) server.mcp.http.advertisedUrl — server.mcp.http.advertisedUrl is not usable: it carries userinfo (credentials), which is not part of an endpoint address. It tells you which config key is wrong, but not the value.
v1.20.1 carries another, weightier fix. In OAuth mode, auth.resource and auth.authorizationServers had not been checked for userinfo since v1.13.0. Once accepted, the credentials showed up in the startup line. And that's not all. These two are served as RFC 9728 protected-resource metadata — the metadata the previous post said you "hand … to a client you don't run". By design, that metadata is served without authentication: clients learn how to authenticate from it, so they have to be able to read it before they authenticate.
Write userinfo into auth.resource in v1.21.0, and the refusal itself states the reason:
@kozou/mcp auth: auth.resource must not carry userinfo (credentials): this URI is served unauthenticated in the protected-resource metadata. The same v1.20.1 also started refusing authorizationServers entries that carry a non-empty query or fragment (an RFC 8414 issuer identifier has neither). These refusals name an entry by its position, not its value — auth.authorizationServers[1], allowedHosts[1].
The refusals fixed in these two releases name the place to fix, not the refused value. What an operator needs to know is where to make the fix; the value itself is right there in their config file. That's not to say refusals that quote values are gone. The refusal of a plaintext http URL pointing at a non-loopback address still quotes the URL (though only a value that has already passed the userinfo, query, and fragment checks). The refusal when the path of advertisedUrl isn't /mcp quotes the path, too — and that one, as I'll come to, remains open.
Not telling isn't the same as not recording
The previous post contains this passage:
when it is the token itself that failed, the body never says which check it failed — signature, expiry, audience, issuer all collapse into one generic message.
Return only what the client can act on next, and don't tell it where token verification failed. Last time I endorsed that line, and I still do.
But that line came at a cost. According to the v1.21.0 release commit, a client like Claude Code shows nothing more than "needs authentication". And a rejected token left no record on the server either. So the operator couldn't tell whether the issuer didn't match, the token had expired, the role claim was missing, or the role wasn't in allowedRoles. The line of not telling the client had become, in effect, a line of telling no one.
v1.21.0 added the other side without moving the line. The body returned to the client when token verification fails is unchanged (the only body that changed is the 403 for a missing role claim, which I'll come back to). Instead, the server writes one line to stderr, in the form <prefix> auth <status> <code>: <explanation>.
Here they are side by side. I started Kozou in OAuth resource-server mode (allowed role kozou_reader, required scope mcp:describe) and sent, in turn: no token, a string that isn't a JWT, and variations on a valid token with its signature or claims changed. The tokens were signed with keys I generated locally, and the public key for verification was written directly into the config, so no external authorization server was contacted at any point. (That is why the token signed with a different key comes out as bad_signature. In a setup that fetches keys from a JWKS, its kid wouldn't be in the key set, so it would usually come out as unknown_key.)
| What was sent | Body the client receives | Server stderr |
|---|---|---|
| No token | 401 Missing or malformed Authorization header. | auth 401 no_token |
| A string that isn't a JWT | 401 Invalid or expired token. | auth 401 malformed_token |
| Signed with a different key | 401 Invalid or expired token. | auth 401 bad_signature |
| Wrong issuer | 401 Invalid or expired token. | auth 401 issuer_mismatch |
| Expired | 401 Invalid or expired token. | auth 401 expired |
| Wrong audience | 401 Invalid or expired token. | auth 401 audience_mismatch |
| No role claim | 403 Token does not specify a role (no "role" claim). | auth 403 role_missing |
A role not in allowedRoles | 403 Role "postgres" is not permitted. | auth 403 role_not_allowed |
| Insufficient scope | 403 This operation requires the "mcp:describe" scope. | auth 403 insufficient_scope |
Of the rows in the table, the five 401s other than "no token" come back to the client with exactly the same body, character for character. The WWW-Authenticate header is the same for all five as well (error="invalid_token"). The only place they differ is the server's stderr, where five separate reasons appear.
The stderr lines don't stop at the name of the reason. Here are three of them in full:
[kozou mcp] auth 401 issuer_mismatch: the token's "iss" is not an accepted issuer: jwt.issuer in the MCP auth settings (server.mcp.http.auth for the kozou CLI), or their authorizationServers when it is unset. [kozou mcp] auth 403 role_missing: the token carries no "role" claim. This endpoint has no default role: the role must come from the token, so assign it in the authorization server. [kozou mcp] auth 403 role_not_allowed: the role the token names is not in allowedRoles in the MCP auth settings (server.mcp.http.auth for the kozou CLI). They point to the names of the settings to check (jwt.issuer, allowedRoles), and even to where the fix goes (assigning the role in the authorization server).
What stays out of the line is settled, too. A line is assembled only from fixed text, the reason code, and setting names. Tokens, claim values, headers, addresses, and request paths don't go in. The release commit and the comment at the top of the implementation say so, and you can confirm it in the output: neither the issuer value of the token sent above (https://other-idp.example.com/) nor the role value (postgres) appears in the stderr lines.
With that, who gets told what splits three ways:
- When token verification fails, the client isn't told the reason; the operator is.
- When the refusal is by scope or role, the client is told the reason too (the 403 bodies in the table above), and the operator also gets a line.
- When the DNS-rebinding guard refuses, not even the operator gets a line — because, as the release commit puts it, it isn't a token refusal. When I sent a valid token with
Host: evil.example.com, I got a 403 (Host header is not allowed for this server.), and nothing appeared on stderr.
A 401 with no token isn't abnormal in itself. The line's own wording says so: "A client sends one of these first, before it signs in". A client first comes without a token, before signing in.
The number of lines is capped: five per reason in a 60-second window. The rest are counted, and when the window closes, a single line gives the count. Sending seven no-token requests within the same window wrote five lines, and when the window closed, this appeared:
[kozou mcp] auth 401 no_token: 2 more in the same 60s, not logged one by one. The cap is there so that a flood of junk tokens can't bury the one line the operator is looking for (per the implementation's comment).
The same release also changed the body of the 403 for a missing role claim. The old wording, "no default role is configured", pointed to a remedy that doesn't exist in Kozou's MCP OAuth mode, which deliberately has no default role (as the previous post described). The remedy you recommend has to exist — the same point as with the startup warning.
Not telling isn't the same as not recording. What the previous post endorsed was a line of not telling the client — surely not a line of telling no one. With v1.21.0, that is finally all it is: a line of not telling the client.
What remains open
Finally, here is what remains open. Kozou itself lists the first four as "Not covered" in its release commits.
A numeric-only password with no @ after it still gets through. https://user:4321/mcp can't be told apart from a host-and-port pair, so it's accepted as host and port (v1.20.1). Write https://alice:4321/mcp into advertisedUrl, and Kozou starts, the URL appears as-is in the warning line, and the username alice is listed in the guard line as a hostname.
[kozou mcp] WARNING: this endpoint is declared reachable at "https://alice:4321/mcp", (lines omitted) [kozou mcp] DNS-rebinding guard: accepting Host names 127.0.0.1, localhost, ::1, alice (add more with server.mcp.http.allowedHosts) kozou mcp --http doesn't close the server on SIGTERM or SIGINT. So a count line not yet written when the process is stopped is never written. Lines already written remain (v1.21.0).
When the JWKS can't be reached at all (connection refused, DNS, TLS), the result is a 500 and a request failed: line, as before (v1.21.0).
The REST surface still doesn't record refusals (v1.21.0).
The other two can be read from the implementation's comments.
The guard is not a mechanism for narrowing who can reach the endpoint. What decides who reaches an unauthenticated endpoint is the network, not a Host check.
The warning can't see authentication in front of it. So all it says is that there is no authentication "of its own". Checking what the layer in front actually does remains the operator's job.
Beyond those, two more remain in Kozou's public issues.
The refusal when the path of advertisedUrl isn't /mcp quotes the path. For an address with a token in its path, like https://tunnel.example.com/<token>/mcp, that token appears in the refusal (kozou#307, v1.21.0).
OAuth mode's startup warning quotes auth.jwt.issuer and auth.jwt.audience as they are. This warning appears when the accepted issuer or audience differs from what is advertised, and neither value is checked for userinfo or a query. Because it's a warning and not a refusal, the server starts, and the values go to stderr on every startup (kozou#306, v1.21.0).
Where the project writes down its own weak spots, I've listed them as they are.
In summary
- In v1.20.0, the DNS-rebinding guard and the startup warning's check started reading the declared reachable address too. The guard no longer refuses requests forwarded under the declared hostname with a 403, and the most exposed deployment now speaks up at startup.
- In v1.20.0 through v1.20.1, the refusals around the reachable address stopped reading aloud values that can carry credentials or tokens (userinfo, unparseable values, queries and fragments). What they name is the config key and the position. A refusal that quotes the path, and a startup warning that quotes the issuer and the audience, are still there.
- In v1.21.0, the reason a token was refused started reaching the operator. The body sent to the client when token verification fails is unchanged.
A declared value becomes a declaration only when every reader that should read it actually does. And a refusal says different things to each reader.
If your own server's configuration has a value you could call a declaration, who is reading it? I think it's worth counting once.
The change records for each release (the release commit bodies) are on GitHub (v1.20.0, v1.20.1, v1.21.0).
This post was written with the help of basou, a harness I'm building for steering AI coding agents.
