Skip to content

Redact secrets from log output#623

Merged
marionbarker merged 1 commit intodevfrom
fix/log-redaction-secrets
May 4, 2026
Merged

Redact secrets from log output#623
marionbarker merged 1 commit intodevfrom
fix/log-redaction-secrets

Conversation

@bjorkert
Copy link
Copy Markdown
Member

@bjorkert bjorkert commented Apr 27, 2026

Summary

Logs can contain bits of information that some users would rather not share. To make people more comfortable sharing logs when asking for help, this change masks sensitive data before they're written to the file, while keeping the lines readable enough to actually debug from.

How it works

A new LogRedactor helper provides small functions for the common shapes:

  • tail / head — keep last/first 8 chars of an opaque token
  • url — keep scheme + a redacted host hint, drop path and query. Known managed Nightscout hosts (nightscoutpro.com, 10be.de, herokuapp.com) are kept as the suffix; anything else is reduced to the TLD
  • keyId / teamId — reveal last 2 chars of a 10-char Apple ID
  • bundleId — keep TLD + app name, mask middle (so suffixes like .watchkitapp stay visible)
  • username — preserve email-vs-not shape, drop the value
  • fingerprint — short sha256 prefix for opaque blobs (QR contents, settings JSON)
  • sweep — runs on every log line as a safety net, catching PEM PRIVATE KEY blocks, ?token=… query values, and JWTs no matter which call site emits them

The per-call-site helpers are precise; the central sweep in LogManager.log is a net so future log lines also benefit without anyone having to remember.

What changed

Per-call-site redaction at the known sites that previously echoed values verbatim:

  • AppDelegate — APNs device token at registration; userInfo dumps reduced to key lists
  • NightScoutViewControllerNSLog of the full URL routed through LogManager and masked
  • MainViewController — Nightscout URL in the BFU foreground log
  • ImportExportSettingsViewModel, RemoteSettingsViewModel — QR / settings JSON replaced with a fingerprint; nightscoutURL and dexcomUsername masked
  • LoopAPNSServicebundleId masked next to the (already prefix-masked) device token
  • JWTManager — Apple Key ID in the JWT generation log
  • PushNotificationManager, NightscoutUtils, SettingsMigrationManagerprints converted to debug LogManager calls (no raw JSON, no full debugDescription)
  • ObservableUserDefaultsValue, ObservableValue — removed prints that fired on every value change

Adds a LogRedactor helper and applies it across every known leaky log
site so users can share logs without leaking APNs tokens, p8 keys,
Nightscout URLs and tokens, Dexcom usernames, key/team IDs, or bundle
identifiers. LogManager.log also runs a safety-net sweep that catches
PEM PRIVATE KEY blocks, ?token= query values, and JWTs regardless of
the call site.
bjorkert added a commit that referenced this pull request Apr 27, 2026
Copy link
Copy Markdown
Collaborator

@marionbarker marionbarker left a comment

Choose a reason for hiding this comment

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

I think this is pretty important.
I tested it and all new log entries were redacted but older ones were not.
When the log was shared - the older entries were in the clear.

I'm going to merge this and we can decide if filtering needs to be added when sharing the logs. I'm thinking not. The logs have a finite life so unmasked entries will be short-lived.

@marionbarker marionbarker merged commit 2e8607f into dev May 4, 2026
1 check passed
@marionbarker marionbarker deleted the fix/log-redaction-secrets branch May 4, 2026 04:27
MtlPhil pushed a commit to achkars-org/LoopFollow that referenced this pull request May 6, 2026
Brings in all changes from loopandlearn/LoopFollow dev up to 6.1.0.
Resolved conflicts by taking upstream throughout, except LogManager
where both the watch and telemetry log categories are kept.

Key changes from upstream:
- Add iOS 17.2+ push-to-start for Live Activity renewal (loopandlearn#622)
- Fix LA restart classification, foreground race, troubleshooting logs (loopandlearn#615)
- Redact secrets from log output (loopandlearn#623)
- Add anonymous telemetry (loopandlearn#626)
- Add units selection (loopandlearn#558)
- Fix stats inclusive date range (loopandlearn#629)
- Deduplicate Nightscout treatment entries by id (loopandlearn#569)
- Fix alarm sound session activation failures in background (loopandlearn#596)
- Recognize Atlas DASH pod in Omnipod heartbeat scan (loopandlearn#633)
- Default migrationStep to latest on fresh installs (loopandlearn#631)
- Update to fastlane 2.233.1 (loopandlearn#632)

https://claude.ai/code/session_01VK2furpEaEmysQvEd1h77f
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.

2 participants