Skip to content
This repository was archived by the owner on Oct 24, 2026. It is now read-only.

Commit d22c5da

Browse files
ostermayerclaude
andcommitted
hardening: close the 2026-08-29/30 audit lows still open on master
- wireguard preset: the lnd REST accept rule now requires `-i wg-nb` and the single peer `/32` instead of the whole /24 by source alone. The 0.0.0.0 bind itself stays deferred (docs/wireguard-rest-bind.md). - lnd macaroon ExecStartPost: cap the lnd-controlled REST body at 64 KiB before it is buffered/written to the /run tmpfs by root, and fail closed (jq -e) when the reply has no `.macaroon` instead of writing garbage. - setup-secrets: the root-only lockdown of unprocessed files now includes dotfiles (dotglob) and feeds `comm` explicitly sorted input. - btcpayserver/nbxplorer: document why MemoryDenyWriteExecute is off (.NET JIT) as an accepted trade-off. Audit runs 2026-08-29-191448 / -215807 / -230439 (audits branch). Co-Authored-By: Claude Fable 5.1 <[email protected]> Claude-Session: https://claude.ai/code/session_016AG4NJ9NXLZjHxJLFUX3dn
1 parent 6853949 commit d22c5da

5 files changed

Lines changed: 26 additions & 11 deletions

File tree

‎docs/wireguard-rest-bind.md‎

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,11 @@ dependency on the interface — remains, and still needs:
7878
- `systemd.services.lnd = { wants = [ "wireguard-wg-nb.service" ]; after = [ "wireguard-wg-nb.service" ]; }`
7979
in the preset (runtime wg restarts are fine: a bound socket survives
8080
interface teardown and resumes when the address returns);
81-
- the existing firewall accept rule for the wg subnet stays (nixos-fw
82-
default-drops; the rule is what admits the peer). While touching it,
83-
scope it to the interface (`-i wg-nb`): today it matches on source
84-
subnet alone (2026-08-29 audit, low) — spoofed-source packets arriving
85-
on the external interface are only kept out by rp_filter/routing, not
86-
by the rule itself.
81+
- the firewall accept rule stays (nixos-fw default-drops; the rule is what
82+
admits the peer). Since 2026-09-09 it is already scoped to the interface
83+
and the single peer (`-i wg-nb -s <peerAddress>/32`), closing the
84+
2026-08-29 low: a spoofed-source packet on the external interface no
85+
longer matches the rule at all, independent of rp_filter/routing.
8786

8887
## Pre-flight checklist before shipping any variant
8988

‎modules/btcpayserver.nix‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,10 @@ in {
183183
Restart = "on-failure";
184184
RestartSec = "10s";
185185
ReadWritePaths = [ cfg.nbxplorer.dataDir ];
186+
# .NET's JIT needs writable+executable pages, so W^X enforcement cannot
187+
# be enabled for NBXplorer or BTCPay. Accepted trade-off (audit
188+
# 2026-08-29, low): the remaining sandbox (nbLib.defaultHardening,
189+
# netns/Tor policy, dedicated users) is unchanged.
186190
MemoryDenyWriteExecute = false;
187191
} // nbLib.allowedIPAddresses cfg.nbxplorer.tor.enforce;
188192
};
@@ -231,7 +235,7 @@ in {
231235
# Restart rate limiting is implemented via the `startLimit*` options below.
232236
Restart = "always";
233237
ReadWritePaths = [ cfg.btcpayserver.dataDir ];
234-
MemoryDenyWriteExecute = false;
238+
MemoryDenyWriteExecute = false; # .NET JIT; see the nbxplorer note above
235239
} // nbLib.allowedIPAddresses cfg.btcpayserver.tor.enforce;
236240
startLimitIntervalSec = 30;
237241
startLimitBurst = 10;

‎modules/lnd.nix‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,12 +286,17 @@ in {
286286
# read — and grants no access lnd does not already have. (The write
287287
# path above is already symlink-hardened; this closes the read.)
288288
adminMacaroonHex=$(${pkgs.util-linux}/bin/runuser -u ${cfg.user} -- ${pkgs.xxd}/bin/xxd -ps -u -c 99999 '${networkDir}/admin.macaroon')
289+
# The response body is lnd-controlled. A macaroon is a few hundred
290+
# bytes, so cap what this root script will buffer and write to the
291+
# /run tmpfs at 64 KiB, and fail (jq -e) rather than write garbage
292+
# when the reply carries no `.macaroon` (audit 2026-08-30, low).
289293
${curl} \
290294
-H @<(printf 'Grpc-Metadata-macaroon: %s\n' "$adminMacaroonHex") \
291295
-X POST \
292296
-d '{"permissions":[${cfg.macaroons.${macaroon}.permissions}]}' \
293297
${restUrl}/macaroon |\
294-
${pkgs.jq}/bin/jq -c '.macaroon' | ${pkgs.xxd}/bin/xxd -p -r > "$macaroonTmp"
298+
${pkgs.coreutils}/bin/head -c 65536 |\
299+
${pkgs.jq}/bin/jq -ce '.macaroon | strings' | ${pkgs.xxd}/bin/xxd -p -r > "$macaroonTmp"
295300
chown ${cfg.macaroons.${macaroon}.user}: "$macaroonTmp"
296301
${pkgs.coreutils}/bin/mv -f "$macaroonTmp" "$RUNTIME_DIRECTORY/${macaroon}.macaroon"
297302
'') (attrNames cfg.macaroons)}

‎modules/presets/wireguard.nix‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ in {
152152

153153
extraCommands =
154154
optionalString lndconnect ''
155-
iptables -w -A nixos-fw -p tcp -s ${wgSubnet}.0/24 --dport ${toString lnd.restPort} -j nixos-fw-accept
155+
# Admit lnd REST only from the single WireGuard peer, and only when the
156+
# packet actually arrived over the wg-nb interface. `-s` alone matches
157+
# a spoofed source on any interface; `-i` pins it to the tunnel (audit
158+
# 2026-08-29, low). This is the interim hardening while the
159+
# 0.0.0.0 bind itself stays deferred (see docs/wireguard-rest-bind.md).
160+
iptables -w -A nixos-fw -i wg-nb -p tcp -s ${peerAddress}/32 --dport ${toString lnd.restPort} -j nixos-fw-accept
156161
''
157162
+ optionalString cfg.restrictPeer ''
158163
iptables -w -A nixos-fw ${restrictPeerRule}

‎modules/secrets/secrets.nix‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,11 @@ in {
224224
'') cfg.secrets)
225225
}
226226
227-
# Make all other files accessible to root only
227+
# Make all other files accessible to root only.
228+
# dotglob: a stray `.something` in the secrets dir must be locked down
229+
# too, not skipped by the glob (audit 2026-08-30, low).
228230
unprocessedFiles=$(
229-
comm -23 <(shopt -s nullglob; printf '%s\n' *) <(printf '%s\n' "''${processedFiles[@]}")
231+
comm -23 <(shopt -s nullglob dotglob; printf '%s\n' * | sort) <(printf '%s\n' "''${processedFiles[@]}" | sort)
230232
)
231233
if [[ $unprocessedFiles ]]; then
232234
IFS=$'\n'

0 commit comments

Comments
 (0)