Pull request: Fix review findings (CloudDNS errors, failure messages, hardening) #4

Merged
liam merged 4 commits from review-fixes into main 2026-11-17 09:03:33 +01:00
Owner

Changes, one commit each

  1. CloudDNS: treat every answer that is not a clear success as an error.
    Only readable JSON with status "success" is a success. Anything else is a
    911, and the address is not cached, so the next request retries.
    The message text now only decides between good and nochg. A wrong
    guess there changes the answer word, not the record.
  2. ntfy message on failed updates. The first failure is reported right
    away. While a host keeps failing, at most one message per hour. The first
    success afterwards sends one "working again" message. Messages contain the
    host, the requested address, a short error (max. 200 characters) and the
    client, and never contain credentials. netcup credentials are only ever
    sent in request bodies, so they cannot appear in error texts.
  3. Hardening.
    • Lockout: kept as it is, checked before the credentials (see below).
      The start of a lockout is now logged once.
    • MIN_UPDATE_INTERVAL must be at least 5s, and 0 is refused.
    • ntfy errors are logged without the topic URL. NTFY_URL is now parsed
      at startup.
  4. README. Docker bridge warning, ALLOWED_NETS recommendation,
    gen-token requirement, plus the lockout behaviour, the interval minimum
    and the failure messages.

Assumption: netcup's CloudDNS answer format

The format of wsDynDns.php answers has not been verified against the real
service, and this setup uses the legacy API. The code therefore treats every
answer it does not recognise as a failure. If netcup ever answers success in
another form (for example a different status word), updates will fail with a
clear error, and a single test case covers the new form.

Lockout: why neither variant from the review

Both proposed variants have the same effect. One evaluates the lockout only
after the credential check, and the other lets a correct token lift the
lockout. Either way, a locked-out client's tokens are tested again, and the
answer differs between a right and a wrong guess. A guesser could then keep
trying during the lockout and would see when a guess is right, so the lockout
would no longer limit guessing. That would weaken it, which the review rules
out.

The cost of keeping it is small. A lockout needs 5 wrong tokens from an
address in ALLOWED_CLIENTS. After fixing a wrong token in the router, wait
15 minutes or restart dynrelay. The new log line shows when this happened, and
a test asserts that the right and a wrong token get identical answers while
locked out.

Verification

go vet ./... && go test -race ./... pass (Go 1.24.7, linux/amd64). New tests:

  • TestCloudDNSAnswers
  • TestCloudDNSErrorWith200IsNotCached
  • TestFailureNotifications
  • TestMinUpdateInterval
  • TestNtfyErrorsHideURL
  • TestLockoutGivesNoOracle

The CloudDNS and ntfy tests fail against the previous code. The Docker build
(Go 1.27 image) runs the same tests.

Open question: TLS

The token still travels over plain HTTP on the LAN. ALLOWED_CLIENTS and
ALLOWED_NETS limit the damage, but TLS (or keeping the service on a
segment nobody else can sniff) remains open and is not part of this PR.

### Changes, one commit each 1. **CloudDNS: treat every answer that is not a clear success as an error.** Only readable JSON with status "success" is a success. Anything else is a `911`, and the address is not cached, so the next request retries. The message text now only decides between `good` and `nochg`. A wrong guess there changes the answer word, not the record. 2. **ntfy message on failed updates.** The first failure is reported right away. While a host keeps failing, at most one message per hour. The first success afterwards sends one "working again" message. Messages contain the host, the requested address, a short error (max. 200 characters) and the client, and never contain credentials. netcup credentials are only ever sent in request bodies, so they cannot appear in error texts. 3. **Hardening.** - Lockout: kept as it is, checked before the credentials (see below). The start of a lockout is now logged once. - `MIN_UPDATE_INTERVAL` must be at least `5s`, and `0` is refused. - ntfy errors are logged without the topic URL. `NTFY_URL` is now parsed at startup. 4. **README.** Docker bridge warning, `ALLOWED_NETS` recommendation, `gen-token` requirement, plus the lockout behaviour, the interval minimum and the failure messages. ### Assumption: netcup's CloudDNS answer format The format of wsDynDns.php answers has not been verified against the real service, and this setup uses the legacy API. The code therefore treats every answer it does not recognise as a failure. If netcup ever answers success in another form (for example a different status word), updates will fail with a clear error, and a single test case covers the new form. ### Lockout: why neither variant from the review Both proposed variants have the same effect. One evaluates the lockout only after the credential check, and the other lets a correct token lift the lockout. Either way, a locked-out client's tokens are tested again, and the answer differs between a right and a wrong guess. A guesser could then keep trying during the lockout and would see when a guess is right, so the lockout would no longer limit guessing. That would weaken it, which the review rules out. The cost of keeping it is small. A lockout needs 5 wrong tokens from an address in `ALLOWED_CLIENTS`. After fixing a wrong token in the router, wait 15 minutes or restart dynrelay. The new log line shows when this happened, and a test asserts that the right and a wrong token get identical answers while locked out. ### Verification `go vet ./... && go test -race ./...` pass (Go 1.24.7, linux/amd64). New tests: - `TestCloudDNSAnswers` - `TestCloudDNSErrorWith200IsNotCached` - `TestFailureNotifications` - `TestMinUpdateInterval` - `TestNtfyErrorsHideURL` - `TestLockoutGivesNoOracle` The CloudDNS and ntfy tests fail against the previous code. The Docker build (Go 1.27 image) runs the same tests. ### Open question: TLS The token still travels over plain HTTP on the LAN. `ALLOWED_CLIENTS` and `ALLOWED_NETS` limit the damage, but TLS (or keeping the service on a segment nobody else can sniff) remains open and is not part of this PR.
The CloudDNS backend only looked at the HTTP status. An HTTP 200 answer
with an error in the JSON body was reported as "good" and the address
was remembered as set, so the record could stay stale unnoticed.

Now only readable JSON with status "success" counts as success. An
unreadable body, a missing status or any other status is an error
(answer 911), and the address is not cached, so the next request tries
again. The message text only decides between good and nochg.

netcup's answer format for this endpoint is not verified against the
real service, which is why unknown answers are treated as failures.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0111tsfGACUUSdMXBtwUxYfC
A failed update was only logged. With NTFY_URL set, a failure now sends
a message with the host, the requested address, a short error and the
client; no credentials are part of it.

To avoid a flood while netcup is down, a host that keeps failing gets
at most one failure message per hour. The first successful update after
failures sends one "working again" message, which replaces the usual
"record changed" message for that update.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0111tsfGACUUSdMXBtwUxYfC
- Lockout: the check stays before the credential check, so a locked-out
  client's tokens are not tested at all. Letting a correct token through
  or lifting the lock with it would tell a guesser when a guess is right,
  also during the lockout. The start of a lockout is now logged once, and
  a test asserts that the right and a wrong token get identical answers
  while locked out.
- MIN_UPDATE_INTERVAL must be at least 5s; 0 and negative values are
  refused. The interval also keeps a looping client from hammering the
  netcup API.
- ntfy errors are logged without the topic URL (HTTP client errors embed
  it), and NTFY_URL is now parsed at startup instead of only checking its
  prefix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0111tsfGACUUSdMXBtwUxYfC
- Stronger warning: a Docker bridge or gateway address in the log must
  not be added to ALLOWED_CLIENTS, because with a published port every
  LAN request arrives from it. Use network_mode: host instead.
- Recommend ALLOWED_NETS (the provider's range): the token travels over
  plain HTTP, and ALLOWED_NETS limits where a stolen token can point
  the record.
- The token must come from gen-token, because only an unsalted SHA-256
  hash is stored.
- Document the lockout behaviour, the 5s minimum for
  MIN_UPDATE_INTERVAL and the failure messages.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0111tsfGACUUSdMXBtwUxYfC
liam merged commit 16a8482137 into main 2026-11-17 09:03:33 +01:00
liam deleted branch review-fixes 2026-11-17 09:03:33 +01:00
Sign in to join this conversation.
No description provided.