Skip to content

Harden local secret file handling - #269

Merged
tankyleo merged 8 commits into
lightningdevkit:mainfrom
benthecarman:codex/loupe-secret-files
Sep 3, 2026
Merged

Harden local secret file handling#269
tankyleo merged 8 commits into
lightningdevkit:mainfrom
benthecarman:codex/loupe-secret-files

Conversation

@benthecarman

Copy link
Copy Markdown
Collaborator

2 small issues found by loupe

  • Create log files with 0600 permissions.
  • Reject existing API key files unless they contain exactly 32 bytes.

Create new log files without group or world access so local users cannot
read node activity under the standard process umask.

This commit was created with assistance from Codex.
Require existing API key files to contain the same 32-byte key material
that the daemon generates. Truncated files must not enable weak HMACs.

This commit was created with assistance from Codex.
@ldk-reviews-bot

ldk-reviews-bot commented Sep 1, 2026

Copy link
Copy Markdown

👋 Thanks for assigning @tankyleo as a reviewer!
I'll wait for their review and will help manage the review process.
Once they submit their review, I'll check if a second reviewer would be helpful.

Create ldk_server_data.sqlite with mode 0600 and new storage and
log directories with mode 0700.

With the usual 0022 umask, create_dir_all made directories 0755.
That let other local users list and traverse node storage, inspect
metadata, and reach any file with permissive mode bits. Restricting
new directories to the owner adds defense in depth for node data.

Payment history should likewise not be readable by other users.

This commit was created with assistance from Codex.
Read at most one byte beyond the expected API key length. This avoids
unbounded memory use for oversized or special files while still
rejecting contents that are not exactly 32 bytes.

This commit was created with assistance from Codex.

@tankyleo tankyleo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

vibed with codex and came up with a few potential followups to this work here, i pushed it all on this branch grab what you find is good, no need for attribution :)

main...tankyleo:ldk-server:codex/loupe-secret-files

API keys are exactly 32 bytes. Reading malformed or special files in
full can otherwise consume unbounded memory. Read only enough bytes to
detect an oversized key.

Treat missing files separately from read and format errors. This keeps a
malformed configured key from being silently ignored in favor of a
default key.

Use the same open-first handling in the daemon so only NotFound triggers
key generation and all other open failures are reported.

This commit was created with assistance from Codex.
@benthecarman

Copy link
Copy Markdown
Collaborator Author

ack on your commits

Mnemonic files are small. Limit reads to 1 KiB so an oversized or
special file cannot cause unbounded memory use during startup.

This commit was created with assistance from Codex.
Limit server certificate and key reads to 1 MiB. Apply the same
certificate limit to the CLI and MCP clients so local files cannot cause
unbounded memory use during startup.

This commit was created with assistance from Codex.
Limit server and client configuration reads to 1 MiB so an oversized or
special file cannot cause unbounded memory use during startup.

This commit was created with assistance from Codex.
@tankyleo
tankyleo merged commit 4e30668 into lightningdevkit:main Sep 3, 2026
10 checks passed
@benthecarman
benthecarman deleted the codex/loupe-secret-files branch September 3, 2026 22:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants