Skip to content

feat: require a valid license JWT for all telemetry uploads - #87

Merged
minarc merged 1 commit into
mainfrom
feat/require-jwt-for-telemetry
Jul 8, 2026
Merged

minarc merged 1 commit into
mainfrom
feat/require-jwt-for-telemetry

Conversation

@minarc

@minarc minarc commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

The backend no longer accepts unauthenticated telemetry. Both upload paths now require a valid, non-expired license JWT and always send Authorization: Bearer <jwt>.

Changes (lib/transfer.js)

  • transferEventLog and uploadPendingTranscript: if there is no valid (non-expired) token, log no valid license JWT — leaving for retry and skip the POST (file kept on disk). Otherwise POST with the Bearer always attached.
  • Removed the old "attach bearer if present, else POST unauthenticated" logic (the buildHeaders/doPost(token) indirection) — there is now exactly one authed request per upload.
  • Retry story is unchanged: the drain batch calls ensureFreshLicense first, and SessionStart + the monitor retry once a fresh license is available, so a transient missing/expired token just defers the upload.

lib/jwt.js

  • Updated the getEndpointFromTokenAllowExpired doc: the endpoint is still readable from an aged-out token for routing, but callers now enforce a valid bearer separately (no more "collector accepts unauthenticated uploads").

Verification

  • No token → no valid license JWT — leaving for retry, file kept, no POST issued.
  • Valid token → authed POST attempted with Authorization: Bearer (fails only on an unreachable endpoint in the test, file kept for retry).
  • Telemetry-gate golden before/after diff unchanged; node --test skillmeter/test/harness.test.js → 20/20.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • Uploads for event logs and pending transcripts now stop early if the license token is missing or expired, helping avoid failed or unauthorized submissions.
    • Files that can’t be uploaded remain queued for a later retry instead of being sent incomplete.
    • Clarified endpoint lookup behavior so expired tokens can still provide routing information, without affecting authentication handling.

The backend no longer accepts unauthenticated telemetry. Both upload paths
(event logs and transcripts) now require a valid, non-expired license JWT and
always send `Authorization: Bearer <jwt>`. When no valid token is available the
upload is skipped and the file is left on disk for retry (the drain batch calls
ensureFreshLicense first; SessionStart and the monitor retry once a fresh
license is available).

Removes the previous "attach bearer if present, else POST unauthenticated"
behavior (the buildHeaders/doPost(token) indirection) in transferEventLog and
uploadPendingTranscript, and updates the getEndpointFromTokenAllowExpired doc:
the endpoint is still readable from an aged-out token for routing, but callers
now enforce a valid bearer separately.

Verified: no-token → "no valid license JWT — leaving for retry", file kept, no
POST; valid token → authed POST attempted (Bearer attached). Telemetry-gate
golden diff unchanged; harness tests 20/20.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 8, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1774d159-24dc-4ab1-ba1e-5af25bac3ff6

📥 Commits

Reviewing files that changed from the base of the PR and between cbe5f34 and c2956db.

📒 Files selected for processing (2)
  • skillmeter/scripts/lib/jwt.js
  • skillmeter/scripts/lib/transfer.js

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

Enforces a non-expired license JWT requirement before uploading event logs or pending transcripts in transfer.js; requests that previously used conditional/no Authorization headers now always include Authorization: Bearer ${token}. A related comment in jwt.js was reworded for clarity.

Changes

JWT-gated telemetry uploads

Layer / File(s) Summary
Event log upload gating and header wiring
skillmeter/scripts/lib/transfer.js
transferEventLog() fetches an uncached license token, aborts with a retry log if missing/expired, and removes prior fallback logic; POST now always sends Authorization: Bearer ${token} instead of conditional headers.
Pending transcript upload gating and header wiring
skillmeter/scripts/lib/transfer.js
uploadPendingTranscript() applies the same non-expired token gate and early return, always includes the Authorization header, and the call site drops the old initialToken argument.
Endpoint recovery comment clarification
skillmeter/scripts/lib/jwt.js
Comment reworded to clarify the endpoint-recovery helper is not an authentication decision and that the backend rejects unauthenticated uploads.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: jhunlee-dev

Poem

A token expired? No hop, no send,
I check the clock before I append.
Authorization rides along each time,
No naked POST, that was the crime.
Retry tomorrow, files still wait —
This bunny guards the upload gate. 🐰🔐

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/require-jwt-for-telemetry

Comment @coderabbitai help to get the list of available commands.

@minarc
minarc requested a review from TheStarkor July 8, 2026 15:23
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