Commit Graph

26 Commits

Author SHA1 Message Date
Keysat 238689ddcc Persist payment-webhook dedup; declare BTCPay required; scope CORS
Replace the in-memory dedup Sets in the BTCPay and Zaprite webhook
handlers (and the BTCPay rescan path) with a persistent JSON-backed
store (server/webhook-dedup.js). The in-memory sets were cleared on
restart, so a duplicate webhook delivery straddling a relay restart
could double-credit (BTCPay) or double-extend a subscription (Zaprite).
The store atomically writes /data/processed-webhooks.json, namespaces
keys per rail (storeId|invoiceId vs zaprite:orderId), and prunes
entries older than 180 days (safely beyond any retry window).

Also:
- BTCPay is a required running dependency (operator decision). Config
  was already optional:false/kind:'running'; corrected the contradictory
  "optional" comment in the manifest to match.
- Scope cors() to /relay/* only — off /admin/* and the same-origin
  dashboard, which don't need permissive CORS.
- Add money-path unit tests (commitCredit/refundCredit/applyTierPromotion)
  and webhook-dedup tests (incl. the survives-a-restart guarantee).
- Fix two AGENTS.md auth-doc drifts; refresh Current state.

Version 0.2.125 -> 0.2.126.
2026-06-15 18:15:00 -05:00
Keysat 798a698132 Add Users dashboard tab with per-user balances and credit grants
New cookie-gated "Users" tab on the operator dashboard: a sortable view
of every credit-ledger row (typed cloud/license/install) with computed
remaining/total balances, key filter, and a per-row "grant free credits"
action.

Endpoints (routes/admin.js):
- GET /admin/credits — snapshotAll() enriched with a type derived from
  the credit-key prefix and a computed balance (computeRemaining against
  live tier quotas), since the ledger stores consumed counters only.
- POST /admin/credits/grant {credit_key, amount} — adds free top-up via
  addPurchasedCredits. Grants land in the never-expires purchased bucket
  (spent after the tier allowance). Guards: positive integer, <=1,000,000,
  and the row must already exist (a typo can't spawn a ghost row).

Admin-only; no /relay/* client contract change. Tests added in
server/test/admin-credits.test.js (mount the real router over HTTP).
Version bumped 0.2.124 -> 0.2.125.
2026-06-15 16:25:14 -05:00
Keysat 693d72431b Return clean JSON for body-parser/unhandled errors
Malformed JSON request bodies fell through to Express's default error
handler, which renders an HTML page including the local-filesystem stack
trace (info leak). Add a final error-handling middleware: JSON 400 for
entity.parse.failed, 413 for entity.too.large, generic 500 otherwise —
closing the stack-trace leak on every propagated error, not just JSON.
2026-06-13 18:22:00 -05:00
Keysat da1bba2e6b Compare operator key in constant time
resolveIdentity and verifyOperatorKey compared the shared
relay_cloud_operator_key with ===/!==, which short-circuits on the first
differing byte — a timing oracle on a high-value key. Use a
timingSafeEqual-based constantTimeEqual, matching admin-auth.js.
2026-06-13 18:22:00 -05:00
Keysat cbd9748a79 Guard meeting :id against path traversal
saveMeeting/loadMeeting/deleteMeeting built path.join(meetingsDir, id +
'.json') straight from req.params.id, so an admin-authed :id like
'../../etc/passwd' could read/write/delete outside internal-meetings/.
Centralize a meetingPath() helper that strips anything outside
[A-Za-z0-9_-] (mirrors output-store.js) and throws on an empty result;
load/delete catch it as 404/no-op. Add a regression test.
2026-06-13 18:22:00 -05:00
Keysat 3a601e166a Bump multer 1.4.5-lts.1 -> ^2.0.1 (DoS CVEs)
multer 1.x is affected by CVE-2025-47944/47935/48997/7338 (malformed
multipart crashes the process / leaks memory). 2.x raises catchable
errors instead. Usage (diskStorage + .single("file")) is unchanged.
Commit the server lockfile so the Dockerfile's npm-ci path pins the fix.
2026-06-13 16:23:26 -05:00
Keysat d2caa98248 Fix credit-counter reset on early subscription renewal
extendUserTier called setUserTier, which unconditionally zeroed
monthly_consumed and re-anchored the cycle. A user who renewed mid-cycle
(or a webhook double-firing across a restart) got their full monthly
allotment back for free. The monthly cycle already rolls on its own
anniversary via ensureRenewalRollover, so renewal must not reset it. Add
resetCycle to setUserTier (default true, preserving operator-grant
behavior); extendUserTier passes false for an in-force subscription and
true only for a brand-new or lapsed one. Add regression tests.
2026-06-13 16:23:26 -05:00
Keysat 8ad7c54da4 Block SSRF on media_url downloads (transcribe-url/summarize-url)
downloadDirect fetched any caller-supplied media_url with redirect-follow
and no host/scheme validation; the route is reachable via a self-chosen
X-Recap-Install-Id, so a caller could probe the operator's LAN or cloud
metadata (169.254.169.254). Add safe-url.js: assertPublicHttpUrl rejects
non-http(s) schemes and hosts resolving to private/loopback/link-local/
reserved ranges, and safeFetch follows redirects manually, re-validating
each hop. Route downloadDirect through it (covers transcribe-url,
summarize-url, and admin-test-run).
2026-06-13 16:23:26 -05:00
Keysat 318c6c4b81 Wire new routes; identity, summarize-url, dashboard, admin 2026-06-13 13:36:30 -05:00
Keysat 04dcf86fa4 Add TTS backends (ElevenLabs, Kokoro) and /relay/tts 2026-06-13 13:36:05 -05:00
Keysat 0aa648706e Add self-serve billing: tiers, credits, BTCPay and Zaprite 2026-06-13 13:36:05 -05:00
Keysat 84d56c94c9 Add Spark Control hardware backend (diarize, queue, discovery) 2026-06-13 13:36:04 -05:00
Keysat 705807e286 Add internal-meetings pipeline and post-hoc speaker tools 2026-06-13 13:35:53 -05:00
local b7f75904bb v0.2.11 /relay/capabilities + /relay/transcribe-url (yt-dlp in container) 2026-05-12 01:33:34 -05:00
local 0a0fa009ec v0.2.10 hardware backend URL normalization + path fallback 2026-05-12 01:00:48 -05:00
local 8ffc3ffb73 v0.2.9 Gemini model selects + fallback chain 2026-05-12 00:45:41 -05:00
local 05ebeb5d51 v0.2.8 operator dashboard with per-call audit log + cost tracking 2026-05-12 00:26:59 -05:00
local 9af70302b1 v0.2.7 configurable Gemini models + per-pipeline backend preference 2026-05-12 00:15:07 -05:00
local cd377683fb v0.2.6 calendar-anniversary billing 2026-05-11 23:02:57 -05:00
local 45c8462fa2 v0.2.5 grouped actions 2026-05-11 22:12:02 -05:00
local e612e8b8e8 v0.2.4 max-monthly union + /relay/policy 2026-05-11 22:02:38 -05:00
local 6797aae404 v0.2.3 Core tier 10/5/5 split + dynamic health version 2026-05-11 21:53:50 -05:00
local 07fe14010c v0.2.2 balance peek endpoint 2026-05-11 21:34:31 -05:00
local c9f051cd07 v0.2.1 model names config-driven 2026-05-11 20:27:19 -05:00
local cccbee27e4 v0.2 hardware backend 2026-05-11 20:14:50 -05:00
local b9d86fa303 initial relay scaffold 2026-05-11 20:03:27 -05:00