mirror of
https://github.com/hanzoai/iam.git
synced 2026-11-19 18:37:16 +00:00
- httpx.Caller reads the caller from facts the caller cannot write: the host's stamped X-Client-Ip over its socket, or the nearest proxy's appended hop behind it. CF-Connecting-IP is no longer read, since api.hanzo.ai is not behind a proxy that rewrites it, so a limit keyed on it was a limit the caller set. IPv6 is bucketed by /48 (a site's allocation), not /64, so a caller cannot rotate addresses inside one allocation. - The open-request budgets (number, day, ceiling) are charged only by open requests: a second factor is admitted against its own reserved budget, so a stranger filling the open budgets cannot lock a holder out of their own code. Budgets are scoped by tenant where they are money (day), and counted by counter rows instead of COUNT scans, so a refusal costs O(1) however many rows the ledger holds. - Signup refuses a phone number already registered in the org, closing the squatting that needed no proof to take one.
52 lines
2.2 KiB
Go
52 lines
2.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc.
|
|
// SPDX-License-Identifier: MIT OR Apache-2.0
|
|
|
|
package schema
|
|
|
|
import "github.com/hanzoai/orm"
|
|
|
|
// Text is one request to text a code to a phone number, admitted under the
|
|
// texting budgets (internal/otp). The rows are the ledger those budgets count,
|
|
// and a row asked with the SMS consent ticked is the record of that opt-in: when,
|
|
// for which number, at which application.
|
|
//
|
|
// It stores no number and no client address. Number and Client are keyed
|
|
// digests (internal/otp digest), so the ledger can count a number or a network
|
|
// without being able to name either. A row is written for every admitted
|
|
// request, whether or not a text went out, so the ledger reads the same for a
|
|
// number an account holds and for one nobody holds.
|
|
//
|
|
// Only internal/otp writes it, and no route reads or writes it: it is not
|
|
// customer data and not an audit row a tenant may edit.
|
|
type Text struct {
|
|
orm.Model[Text]
|
|
|
|
// Owner is the organization the code is sent as, which is the account the
|
|
// carrier bills.
|
|
Owner string `json:"owner" orm:"index"`
|
|
// Name is the row's random id.
|
|
Name string `json:"name"`
|
|
// Time is when the request was admitted, in Unix seconds.
|
|
Time int64 `json:"time" orm:"index"`
|
|
// Application is the application the code was asked for ("owner/name"), or
|
|
// "" for a second factor, which no application asks for.
|
|
Application string `json:"application,omitempty" orm:"index"`
|
|
// Client is the keyed digest of the asking client's network: its IPv4
|
|
// address, or its IPv6 /48.
|
|
Client string `json:"client" orm:"index"`
|
|
// Number is the keyed digest of the destination number.
|
|
Number string `json:"number" orm:"index"`
|
|
// The three flags are stored even when false: the budgets filter on them,
|
|
// and a field a row leaves out matches no comparison.
|
|
//
|
|
// Sent says a text went out: an account holds the number, or the signed-in
|
|
// person asking is adding it. It is what the money budgets count.
|
|
Sent bool `json:"sent"`
|
|
// Factor says the code went to an account's own number as its second
|
|
// factor, or to enrol one: asked by somebody who already proved who they
|
|
// are, not by an open request.
|
|
Factor bool `json:"factor"`
|
|
// Consent says the person ticked the SMS consent when they asked.
|
|
Consent bool `json:"consent"`
|
|
}
|