Skip to content

Security hardening: glucose ingestion, sensor isolation, outbound broadcasts - #89

Open
JetFoxy wants to merge 5 commits into
ctqvva:mainfrom
JetFoxy:main
Open

Security hardening: glucose ingestion, sensor isolation, outbound broadcasts#89
JetFoxy wants to merge 5 commits into
ctqvva:mainfrom
JetFoxy:main

Conversation

@JetFoxy

@JetFoxy JetFoxy commented Jul 12, 2026

Copy link
Copy Markdown

Summary

Security hardening for the glucose data-ingestion, sensor-isolation, and
outbound-broadcast paths, following an internal security edge-case review
and a subsequent correctness re-check of that review's own fixes.

  • Bounds-check glucose rate/value/timestamp before it reaches native storage
    (VirtualGlucoseSensorBridge, NightscoutFollowerManager, g.cpp).
  • Fix a reference-counting bug in ManagedSensorIdentityRegistry that could
    wipe a sensor's view-mode/identity cache while another adapter still
    legitimately held it.
  • Require HTTPS for user-configured API/Nightscout sources, with a clear
    in-app message instead of a silent scheme rewrite.
  • Restore JSON field aliases in the generic API glucose source parser that
    an earlier pass of this review had accidentally dropped (would have
    silently stopped ingesting readings for sources using those key names).
  • Verify target package installation before sending glucose broadcasts
    (Wear, Gadgetbridge, XInfuus/LibreLink, xDrip-compatible, EverSense).
  • Group glucose smoothing by sensorSerial and filter expired sensors from
    candidate resolution, closing two items the original review had to defer.
  • Add the Ottai CGM driver (BLE manager, crypto, cloud client, parser,
    registry, setup wizard) that was in flight alongside this hardening work.

Full review notes and the prioritized follow-up plan (including one item,
signature-based package verification for broadcasts, that remains
intentionally open) are included at .omo/reviews/security-edge-case-review.md
and .omo/plans/juggluco-security-edge-review-followup.md.

Known follow-up (not in this PR)

  • Broadcast package checks confirm a target package is installed, not
    that it's the genuine signed app — package-name squatting is not fully
    closed. Tracked as open in the review doc; needs signing-certificate
    pinning as separate follow-up work.

Test plan

  • Added ApiGlucoseSourceSecurityTests covering all JSON field aliases
    (positive) and out-of-range/garbage values (negative).
  • Extended DataSmoothingTests, NightscoutFollowerIntegrationTests,
    NightscoutFollowerRegistryTests for the new bounds/grouping logic.
  • Full ./gradlew unit test run (could not be executed in this
    environment — only JDK 16 available, project requires JDK 17).
  • Manual QA: two-sensor overlap (no cross-sensor smoothing), HTTP URL
    entry shows the new in-app warning, broadcast targets only fire to
    installed companion apps.

Владимир Яшин and others added 5 commits June 18, 2026 17:36
RE of BLE protocol from AndroidAPS medtrum module + APK analysis.
Documents BLE UUIDs, packet framing, auth flow, CGM notification
format (MASK 0x1000, 5 bytes), and JugglucoNG driver architecture.

CGM field byte layout marked as hypothesis pending BLE HCI validation.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Add libmdkjnidemo.so wrapper (JniUtil JNI stub + MedtrumNativeLoader)
following BlecommLoader pattern. Used for glucose prediction to match
official app output. Both arm64-v8a and armeabi-v7a variants listed.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
M4 (P1): Document broadcast package-squatting finding as OPEN in review doc.
The getPackageInfo() checks reduce unnecessary broadcasts but do not
authenticate the receiving app. Full signature pinning deferred until
known-good certificate fingerprints are available for companion apps.

M5 (P1): Native bounds guard in addGlucoseInjection already present (g.cpp:1222).
Consistent with addGlucoseStreamInternal — rejects NaN/Inf/negative/>1200.

M6 (P2): Group-by-sensor smoothing already implemented.
GlucosePoint.sensorSerial + DataSmoothing.smoothSensorGroups() prevent
cross-sensor averaging contamination.

M7 (P2): Expired sensor filtering already implemented.
ManagedSensorIdentityAdapter.isExpired() + SensorBluetooth candidate
filtering before sort in resolvePreferredCurrentSensor.

M8 (P3): Add 35 comprehensive tests pinning all JSON field aliases
(primary/auto/raw mg/dL and mmol variants), negative tests for
zero/negative/NaN/Inf/garbage/missing-timestamp values, and rate
bounds verification. All security-related tests pass (138 total,
4 pre-existing failures in unrelated classes).
Broadcasts.updateall() queried packages listening for glucodata.Minute
(GlucoDataHandler) but stored the result via seteverSenseRecepters
instead of setglucodataRecepters. Users migrating from initVersion<13
with GDH broadcast already enabled silently stopped receiving glucose
data in GDH after upgrading, while EverSense's receiver list got
overwritten with the wrong packages.
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