Skip to content

fix: batch of six quick-win MEDIUM bug fixes (#841 #842 #843 #861 #862 #863) - #865

Merged
thiras merged 6 commits into
mainfrom
fix/quick-win-medium-batch
Jun 10, 2026
Merged

thiras merged 6 commits into
mainfrom
fix/quick-win-medium-batch

Conversation

@thiras

@thiras thiras commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Batch of six small, independent MEDIUM bug fixes surfaced by the 2026-06-09/2026-06-10 full-repository reviews. Each is a localized, Rust-only fix (no Solidity/CI-gated surface) with test coverage; one conventional commit per issue.

Fixes

Verification

  • cargo fmt -- --check — clean
  • cargo clippy --all-targets — clean (-D warnings)
  • cargo nextest run — 1665/1665 pass

Each fix adds or updates targeted tests (config load failures, env-expansion, relay redaction, IPv6 /64 bucketing + trusted-IPv6 exemption, self-report rejection + label stability).

Closes #841
Closes #842
Closes #843
Closes #861
Closes #862
Closes #863

🤖 Generated with Claude Code

thiras and others added 2 commits June 10, 2026 03:56
The schema's stated policy is that operator typos fail at load, and the
cache/origin/DHT/receipts structs already set `deny_unknown_fields`. But
`FileConfig` and seven section structs did not, so a typo'd whole-section
header like `[netork]` or a key like `slash_judge_addres` was silently
dropped — the node then ran with wrong defaults for security-relevant
knobs or failed later with a confusing "missing required" error.

Add `#[serde(deny_unknown_fields)]` to `FileConfig` and the `Network`,
`Identity`, `Blockchain`, `Payment`, `Gossip`, `Security`, and
`Observability` section structs, plus `RetryPolicy` (composes with the
existing `#[serde(default)]`). No struct uses `#[serde(flatten)]`, so the
attribute is compatible everywhere. Adds load-failure tests for both a
typo'd key and a typo'd whole-section header.

Closes #842

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
clap folds `DECDN_RELAY_URL` into `cli.relay_url`, which `resolve_network_into`
treats as highest precedence over the file's `network.relay_urls`. An operator
who configures a multi-entry failover list (#795/#817) in TOML but has a stale
exported `DECDN_RELAY_URL` gets the whole list silently replaced by the single
env value — quietly defeating the redundancy feature.

Emit an `eprintln!` warning (tracing is not initialized at resolve time)
naming the overridden list length when `--relay-url`/env is set and a non-empty
`relay_urls` exists. The override behavior is already pinned by
`resolve_network_cli_relay_url_overrides_file_list`, which now also documents
that it exercises this warning trigger.

Closes #843

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Copilot AI review requested due to automatic review settings June 10, 2026 01:11
@thiras thiras self-assigned this Jun 10, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Code Review

This pull request introduces several security, validation, and robustness improvements. Key changes include enforcing deny_unknown_fields on configuration structs to catch typos, redacting credentials from relay URLs in summaries, warning when a CLI override disables relay redundancy, expanding environment variables in discovery fields, rejecting self-reports in reputation validation, and masking IPv6 addresses to /64 prefixes in the DHT rate limiter to prevent bypasses. The feedback recommends sorting peer keys deterministically during environment variable expansion to ensure stable and predictable error reporting instead of relying on non-deterministic HashMap iteration.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment on lines +2461 to 2474
if let Some(peers) = d.peers.as_mut() {
for (id, peer) in peers.iter_mut() {
expand_str(
&mut peer.relay_url,
&format!("network.discovery.peers[{id}].relay_url"),
)?;
for (idx, addr) in peer.addrs.iter_mut().enumerate() {
*addr = expand_value(
addr,
&format!("network.discovery.peers[{id}].addrs[{idx}]"),
)?;
}
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

medium

Iterating directly over peers (which is a HashMap) is non-deterministic. If multiple environment variable expansion errors occur across different peers, the error returned by expand_env will be non-deterministic, making config validation output unstable across runs. Sorting the peer keys deterministically before expansion ensures consistent and predictable error reporting.

            if let Some(peers) = d.peers.as_mut() {
                let mut keys: Vec<_> = peers.keys().cloned().collect();
                keys.sort_unstable();
                for id in keys {
                    if let Some(peer) = peers.get_mut(&id) {
                        expand_str(
                            &mut peer.relay_url,
                            &format!("network.discovery.peers[{id}].relay_url"),
                        )?;
                        for (idx, addr) in peer.addrs.iter_mut().enumerate() {
                            *addr = expand_value(
                                addr,
                                &format!("network.discovery.peers[{id}].addrs[{idx}]"),
                            )?;
                        }
                    }
                }
            }
References
  1. Use unstable sorting (sort_unstable or sort_unstable_by) instead of stable sorting (sort or sort_by) when sorting elements with unique keys (such as keys retrieved from a HashMap), as stable ordering is unnecessary, and unstable sorting is faster and avoids auxiliary memory allocation.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in 3223fc1. Sorting the peer keys before expansion (iter_mut().collect() + sort_unstable_by on the id) so the first surfaced ? error is stable across runs. This also matches the existing convention in resolve_discovery_into, which sorts peers by node_id for the same nondeterminism reason. Added expand_env_discovery_peer_error_order_is_deterministic pinning that two malformed peers always report the lexicographically-smallest id.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

This PR batches six localized Rust bug fixes across config parsing/expansion, CLI validation output, node DHT/dispatch rate limiting, and gossip reputation validation—tightening operator safety (fail-fast on typos, env-expansion correctness, credential redaction) and closing two security/abuse gaps (IPv6 /64 limiter bypass; reputation self-reports).

Changes:

  • Enforce stricter config schema handling: reject unknown TOML keys/sections, expand ${VAR} for [network.discovery], and warn when CLI/env --relay-url overrides a non-empty network.relay_urls list.
  • Prevent sensitive credential leakage in decdn config validate by redacting relay URL userinfo.
  • Harden node behavior: mask IPv6 to /64 for DHT per-IP rate limiting and reject reputation self-reports (reporter == provider), with targeted tests.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.

Show a summary per file
File Description
crates/node/src/dispatch.rs Exposes source_key for reuse so IPv6 /64 masking is consistent across limiters.
crates/node/src/dht/rate_limit.rs Applies /64 IPv6 masking to DHT per-IP limiter keys and trusted IP handling; adds regression tests.
crates/gossip/src/reputation.rs Rejects reputation self-reports and adds a stable reject label + unit test.
crates/config-types/src/retry.rs Adds deny_unknown_fields to RetryPolicy to fail-fast on typos.
crates/common/src/config/types.rs Adds deny_unknown_fields to top-level + section structs to reject unknown keys/sections.
crates/common/src/config/mod.rs Warns on relay-url override of relay list and expands ${VAR} in [network.discovery] (including indexed ctx labels).
crates/cli/tests/config_validate.rs Adds tests for unknown-field/unknown-section failures and relay URL credential redaction.
crates/cli/src/commands/config.rs Redacts relay URL userinfo in validate summary output.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions

github-actions Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Coverage report

Total: 85.85% (was 85.77%, ▲ +0.08%) — 33491/39009 lines

File Coverage Lines Δ
crates/cli/src/commands/config.rs 65.88% 112/170 ▲ +0.01%
crates/common/src/config/mod.rs 96.83% 6009/6206 ▼ 0.02%
crates/config-types/src/retry.rs 100.00% 49/49 ● 0.00%
crates/gossip/src/reputation.rs 100.00% 335/335 ● 0.00%
crates/node/src/dht/rate_limit.rs 99.69% 646/648 ▲ +0.02%
crates/node/src/dispatch.rs 93.15% 598/642 ● 0.00%
History
Commit Total Δ vs base
58d5d2a 85.81% ▲ +0.04%
403c6f8 (HEAD) 85.85% ▲ +0.08%

thiras and others added 4 commits June 10, 2026 04:17
`expand_env` expanded `network.relay_url`/`relay_urls` but had no leg for the
`[network.discovery]` knobs added in #818/#829. An operator reusing the
documented single-TOML-template-across-deployments pattern with
`dns_origin = "${DNS_ORIGIN}"` got the literal string through resolution (only
checked non-empty) and into bring-up, silently breaking peer resolution;
`pkarr_url = "${PKARR_URL}"` failed with a confusing URL-parse error.

Add a discovery block to `expand_env` mirroring the relay loop — `pkarr_url`,
`dns_origin`, and each peer's `relay_url` + `addrs` — with indexed ctx labels
`network.discovery.peers[<id>].{relay_url,addrs[idx]}`. While here, thread the
entry index into the `relay_urls` ctx label (`network.relay_urls[idx]`),
matching the `cache.origins[i]` convention (the #843 diagnosability nit).

Closes #863

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`decdn config validate` printed each `relay_urls` entry verbatim while
redacting `pkarr_url` (and fully hiding `rpc_url`/`otlp_endpoint`) two lines
down in the same summary. An operator with `user:pass@` userinfo in a relay URL
who pastes the summary into a GitHub issue or support channel — the exact
share-the-summary use case the redaction exists for — leaks the credentials.

Run each relay line through `decdn_common::redact::redact_userinfo` (host stays
visible for diagnostics), matching the pkarr_url treatment, and correct the
adjacent comment that claimed relays print unredacted. Adds a redaction test
with a credentialed relay.

Closes #862

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
The DHT per-IP layer keyed buckets on the full `IpAddr`, so an attacker with a
customer-grade IPv6 /64 (2^64 addresses) defeated the tier entirely by rotating
source addresses — each request landed in a fresh bucket. The keyspace cap
(#645) bounds memory but not the rate-limit bypass. The dispatch limiter
already solved this with a /64 mask in `source_key`.

Expose `dispatch::source_key` as `pub(crate)` and apply it in
`DhtRateLimiter::try_admit_one` before both the `trusted_ips` membership test
and `check_key`; mask trusted entries at construction so a configured IPv6
trusted address still matches a masked inbound key. Adds tests that two hosts in
one /64 share a bucket (and a different /64 does not), and that a trusted IPv6
exempts its whole /64.

Closes #841

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
`validate_reputation_envelope` did not check `reporter == provider`, so a
staked node could sign and gossip a report about itself: the self-report folded
into the node's own network_score (weighted by its own settlement value, up to
the 3x cap) AND counted as one of the three distinct reporters its score needs
— dropping ADR 008's eclipse/Sybil external-identity cost from 3 to 2.

Add a `SelfReport` variant (stable label `reputation_self_report`) and reject
self-reports in the pure validation gate with a cheap 32-byte comparison, ahead
of the recency and signature checks, so `record()` and the node sink never see
one. Adds a `self_report_rejected` test and the variant to the label-stability
test.

Closes #861

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@thiras
thiras force-pushed the fix/quick-win-medium-batch branch from 58d5d2a to 403c6f8 Compare June 10, 2026 01:18
@thiras
thiras merged commit d10f9ae into main Jun 10, 2026
19 checks passed
@thiras
thiras deleted the fix/quick-win-medium-batch branch June 10, 2026 01:23
thiras added a commit that referenced this pull request Jun 10, 2026
Localized, Rust-only fixes surfaced by the 2026-06 full-repository reviews:

- fix(config): deny unknown fields on FileConfig + section structs (#842)
- fix(config): warn when DECDN_RELAY_URL overrides relay_urls list (#843)
- fix(config): expand ${VAR} in [network.discovery] fields (#863)
- fix(cli): redact relay credentials in config validate summary (#862)
- fix(node): mask IPv6 /64 in DHT per-IP rate limiter (#841)
- fix(reputation): reject reporter == provider self-reports (#861)

Closes #841
Closes #842
Closes #843
Closes #861
Closes #862
Closes #863

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants