Skip to content

chore(logging): add logging quality audit - #543

Open
suculent wants to merge 2 commits into
thinx-stagingfrom
nightshift/logging-audit
Open

chore(logging): add logging quality audit#543
suculent wants to merge 2 commits into
thinx-stagingfrom
nightshift/logging-audit

Conversation

@suculent

@suculent suculent commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • Added a backend/API logging quality auditor with JSON output and an npm entrypoint.
  • Added regression coverage for high-risk sensitive logging and tracked statistics-event quality gaps.
  • Redacted websocket cookie headers, OAuth/GDPR handoff tokens, OAuth wrapper/hdata logs, and invalid-login username logging.
  • Routed LOGIN_INVALID, BUILD_STARTED, BUILD_FAILED, BUILD_SUCCESS, DEVICE_CHECKIN, and DEVICE_NEW through warn-level logger coverage while preserving metrics calls.

Audit report

  • Files scanned: 80
  • console.* calls: 897
  • logger.* calls: 20
  • Tracked event occurrences: 26
  • Sensitive findings: 21
  • High-risk sensitive findings: 0
  • Severity-string mismatches: 607
  • Tracked event quality gaps: 0

Verification

  • PASS: npm run logging-audit -- --json
  • PASS: npm run --silent logging-audit -- --json
  • PASS: ENVIRONMENT=development MAILGUN_API_KEY=test COUCHDB_USER=test COUCHDB_PASS=test npx jasmine --config=/tmp/thinx-jasmine-nohelpers.json spec/jasmine/LoggingQualityAuditSpec.js spec/jasmine/UtilSpec.js spec/jasmine/LoggerSpec.js spec/jasmine/MetricsCoverageSpec.js (47 specs, 0 failures)
  • BLOCKED: npx jasmine spec/jasmine/LoggingQualityAuditSpec.js spec/jasmine/UtilSpec.js spec/jasmine/LoggerSpec.js spec/jasmine/MetricsCoverageSpec.js using the repo default helper. Bootstrap fails before these specs execute because ENVIRONMENT is unset; with development env it then fails on existing module-load issues (missing local env followed by uuid ESM require from lib/thinx/device.js).

Update: bounded auth-module fix slice (audit.js, router.js, apikey.js)

A second, deliberately narrow remediation slice covers the auth-sensitive
modules the first pass left untouched. Log-only changes, no control-flow
changes.

  • Severity mismatches → correct level
    • lib/thinx/audit.js: _buildRecord missing-message → console.warn;
      log() insertion failure and fetch() failure → console.error.
    • lib/router.js: host-header-mismatch and blacklist-check-failed → console.warn;
      failed API-key authentication → console.warn.
    • lib/thinx/apikey.js: save_apikeys set failure, circuit-breaker OPEN,
      key-generator errors, Redis-unavailable/get errors, revoke/list
      error paths → console.error.
  • Secret/token leakage → redacted or removed
    • apikey.js no longer logs the full json_keys blob (cleartext keys + hashes)
      in create()/revoke(); the "saving first API key" debug line logs only the alias.
    • Attempted invalid API-key values in log_invalid_key() and key_in_keys()
      are redacted via Util.redactToken().

Stats-parser safety: none of these files emit the [OID:...] [EVENT] lines
consumed by statistics.js, so no logger.warn() level was changed or downgraded.

Verification (this slice)

  • PASS: npm run lint — only the 3 pre-existing errors remain, all in files this
    slice never touched (lib/thinx/statistics.js ×2, spec/jasmine/ZZ-WebSocketLifecycleSpec.js).
  • PASS: isolated UtilSpec + LoggingQualityAuditSpec (33 specs, 0 failures).
  • Audit re-scan: severity-string mismatches 607 → 590; two cleartext-key debug logs removed.

suculent added 2 commits July 6, 2026 17:34
Second, deliberately narrow slice of the logging-quality audit targeting the
auth-sensitive modules left untouched by the first pass. Log-only changes, no
control-flow changes.

- audit.js: _buildRecord missing-message -> console.warn; log()/fetch()
  failures -> console.error.
- router.js: host-header-mismatch and blacklist-check-failed -> console.warn;
  failed API-key auth -> console.warn.
- apikey.js: genuine error paths (save_apikeys, circuit-breaker, key generator,
  Redis-unavailable/get, revoke/list) -> console.error; stop logging cleartext
  json_keys blobs; redact attempted API-key values via Util.redactToken in
  log_invalid_key() and key_in_keys().

No stats-parser lines changed: none of these files emit the [OID:...] [EVENT]
lines consumed by statistics.js, so no logger.warn() level was downgraded.

Verified: npm run lint (only 3 pre-existing errors in untouched files remain),
isolated UtilSpec + LoggingQualityAuditSpec (33 specs, 0 failures).

Nightshift-Task: logging-audit
Nightshift-Ref: https://github.com/marcus/nightshift
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