Repository navigation
feat(sms): ledger, hashed single-use codes, learned breaker signals and the admin API - #307
Merged
Merged
Conversation
…nd the admin API Phase 1 of the SMS guard (phase 0 is the guard itself): - sms_sends ledger: every allowed send is reserved and settled with the provider outcome, every refusal is written with its reason, with tenant, purpose, source, address, destination country and the code row it carried. sms:ledger:prune masks numbers after 30 days and deletes rows after 90 (both configurable). - verification_codes gain company_uuid, identity, channel, ip_address, user_agent, sms_send_uuid and consumed_at (identity backfilled from meta for recent rows). generateSmsVerificationFor(['hashed' => true]) stores an HMAC and hands the message callback the plain code; findActiveFor()/findActiveForSubject() find the newest live code (new column or legacy meta), check() verifies, consume() uses it up. Everything degrades to meta-only on a table without the columns. - Two breaker signals read from the data: a burst to a country the company has never texted (armed after 50 ledgered sends), and SMS codes issued with almost none verified in the last hour. - SmsServiceChannel: a notification channel that sends through SmsService, so notification texts are guarded and ledgered too. - Admin API under int/v1/sms-guard: settings (mode, budgets, blocklists, alert recipients, per-company exceptions), reset, pauses, usage per organization and the ledger with filters. The console page follows separately. - The unrouted legacy Twilio-direct SMS login methods are removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Phase 1 of the SMS guard, on top of #305 (phase 0).
sms_sends): every allowed send is reserved and settled with the provider outcome; every refusal is written with its reason. Rows carry tenant, purpose, source, client address, destination country and type, and the verification code they carried.sms:ledger:prunemasks numbers after 30 days and deletes rows after 90 (configurable). Writes are best effort: a missing table never fails a send.company_uuid,identity,channel,ip_address,user_agent,sms_send_uuid,consumed_at(identity backfilled frommetafor recent rows).generateSmsVerificationFor(..., ['hashed' => true])stores an HMAC and gives the message callback the plain code;findActiveFor()/findActiveForSubject()return the newest live code (new column or legacymeta),check()verifies and locks,consume()uses it up. On a table without the columns everything degrades tometa, so extensions can adopt this before their own migrations.SmsServiceChannel: a notification channel that delivers throughSmsService, so notification texts (storefront order alerts) are guarded and ledgered too.int/v1/sms-guard: settings (mode, budgets, blocklists, alert recipients, per-company exceptions), reset, pauses (create and lift), usage per organization against its budget, and the ledger with filters. The console page follows in fleetbase/fleetbase.AuthControllerare removed with their tests.Merge order
This branch is based on
feature/sms-guardso the diff shows only phase 1. Before merging #305, retarget this PR torelease/v1.6.69(gh pr edit --base release/v1.6.69); otherwise GitHub closes it when the base branch is deleted.Tests
Run locally per file and in CI:
SmsLedgerTest,SmsGuardLedgerTest(ledger flow, blocked rows, new-country and conversion trips),VerificationCodeTracingTest(columns, hashed codes, lookups, consume, legacy rows),SmsServiceChannelTest,SmsLedgerPruneTest,SmsGuardControllerTest(payload, validation, pauses, usage, ledger). Existing verification code, 2FA, user and routes tests still pass.Docs
Env vars
SMS_GUARD_LEDGER_RETENTION_DAYS,SMS_GUARD_LEDGER_MASK_AFTER_DAYS; commandsms:ledger:prune(schedule it daily); admin endpoints.needs-docs.