Skip to content

security: clear CodeQL findings (gmtime thread-safety + path-injection hardening) - #699

Merged
frstrtr merged 1 commit into
masterfrom
sec/codeql-gmtime-pathinj
Jul 14, 2026
Merged

security: clear CodeQL findings (gmtime thread-safety + path-injection hardening)#699
frstrtr merged 1 commit into
masterfrom
sec/codeql-gmtime-pathinj

Conversation

@frstrtr

@frstrtr frstrtr commented Jul 14, 2026

Copy link
Copy Markdown
Owner

Clears the 8 genuine CodeQL security alerts on the repo. The other ~92 open code-scanning alerts are code-quality notes (cpp/loop-variable-changed from the intentional argv[++i] arg-parsing, unused-var, etc.), not security — handled separately by dismiss/query-suite tuning. Dependabot = 0, secret-scanning = 0 (no dependency or secret vulns).

Every finding was triaged, then independently re-reviewed (adversarial second pass) — both passes agree.

Fixed in this PR (3 findings)

# Sev Site Fix
#490 CRITICAL src/core/log.cpp:163 std::gmtime -> gmtime_r/gmtime_s into a local tm (reentrant). Only gmtime/localtime call in src/.
#503 HIGH coin_peer_manager.hpp db_path() alnum-only guard on m_symbol before it enters the filename
#502 HIGH coin_peer_manager.hpp db_path() (same guard closes both)

Rider (latent UB): core::filesystem::config_path() dereferenced getenv() with no null check -> path(nullptr) is UB if HOME/APPDATA is unset. Now falls back to ..

Dismiss as false-positive (5 findings)

#507 node.cpp:2199, #506/#505/#504 payout_manager.cpp:224/261/284, #501 auto_ratchet.hpp:309 - all build a path from config_path() (getenv HOME/APPDATA) + a hardcoded basename literal, never from network/peer/miner input. Canonical CodeQL getenv-as-source FP; an attacker who controls $HOME already owns the process environment. Dismissed via the code-scanning API with that justification once this lands.

Verification notes

  • m_symbol traced through every ctor caller: both production CoinBroadcaster sites pass either a blockchain_to_symbol() enum-switch literal or a --merged spec gated behind an exact-match get_chain_p2p_prefix whitelist -> no ../ can reach db_path(). The guard is pure defense-in-depth for future callers.
  • Legitimate tickers (LTC/DOGE/DGB/DASH/BTC/NMC/PEP/BELLS/...) are all alphanumeric -> no on-disk peers-file rename, no DASH/DGB/DOGE/NMC breakage.
  • HTTP admin chain param, dash broadcaster_full port, and peer-address crawl data all independently ruled out as filename sources.

…n hardening)

Clears the 8 real CodeQL security alerts on frstrtr/c2pool. Triaged +
independently re-reviewed: 1 CRITICAL is a genuine fix, 2 HIGH get
defense-in-depth, 5 HIGH are getenv-rooted false positives (dismissed
separately with justification).

- #490 CRITICAL cpp/potentially-dangerous-function (src/core/log.cpp:163):
  std::gmtime returns a pointer into a shared static tm and is not
  reentrant. Replace with gmtime_r (POSIX) / gmtime_s (MSVC) into a local
  tm. Only gmtime/localtime call in src/.

- #502/#503 HIGH cpp/path-injection (coin_peer_manager.hpp db_path()):
  m_symbol is a hardcoded ticker literal at every production ctor site
  (traced through all callers; no network->filename path exists), but
  add an alphanumeric-only guard so a future caller cannot inject a path
  component. Legitimate tickers (LTC/DOGE/DGB/DASH/BTC/NMC/...) are all
  alnum -> no on-disk filename change.

- Rider: core::filesystem::config_path() dereferenced getenv() without a
  null check -> std::filesystem::path(nullptr) is UB if HOME/APPDATA is
  unset. Fall back to '.'.

The other 5 path-injection alerts (#507 node.cpp:2199, #506/#505/#504
payout_manager.cpp:224/261/284, #501 auto_ratchet.hpp:309) all build a
path from config_path() (getenv HOME/APPDATA) + a hardcoded basename,
never from network/peer/miner input -> dismissed as false positive.
@frstrtr
frstrtr force-pushed the sec/codeql-gmtime-pathinj branch from 5b49c72 to e910523 Compare July 14, 2026 10:44
@frstrtr
frstrtr merged commit 7a7f326 into master Jul 14, 2026
37 of 39 checks passed
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.

1 participant