plugins/sentinel
A local risk engine in front of sign-up, sign-in, password reset and code sends. Signals score each
attempt (velocity, credential stuffing, IP rules, devices, disposable domains and, with a provider,
captcha, impossible travel and breached passwords); a policy allows, challenges or blocks. Observe
mode (the default) records without enforcing, so an instance tunes on its own decisions first. It
requires plugins/admin (its routes are admin routes; the one
plugin-to-plugin import), which in turn requires plugins/audit.
Install
Section titled “Install”import "github.com/univeros/polaris.go/plugins/sentinel"
cfg, err := polaris.FromEnv(db, audit.New(audit.Config{}), admin.New(admin.Config{}), sentinel.New(sentinel.Config{ Mode: sentinel.Enforce, // default sentinel.Observe ("observe") Captcha: sentinel.Turnstile(os.Getenv("TURNSTILE_SECRET")), }))p, err := polaris.New(cfg) // fails without the admin plugin, or a missing DisposableListFile_, err = p.Migrate(ctx) // creates polaris_sentinel_decision, polaris_sentinel_ip_rule, polaris_sentinel_deviceConfig
Section titled “Config”The zero value is the defaults: observe mode, the local signals, the bundled domain list.
| Field | Default | Purpose |
|---|---|---|
Mode | sentinel.Observe | sentinel.Enforce answers blocks and challenges |
Policy | challenge from 40, block from 80 | sentinel.Policy{ChallengeAt, BlockAt} over the summed score (0..100) |
Velocity | sentinel.DefaultVelocity | "ip", "email", "device" => sentinel.Limit{Max, Window}; a dimension left out is not counted |
Captcha | nil | sentinel.Turnstile(secret), sentinel.HCaptcha(secret) or your sentinel.BotVerifier |
Geo | nil (sentinel.NoGeo) | sentinel.GeoResolver for impossible travel; no geo database ships |
Breaches | nil | security.HIBP{} enables the breached-password signal (and core’s port unless Config.Breaches) |
Domains / DisposableDomains / DisposableListFile | bundled list | replace, extend or load the disposable-domain list |
Counters | sentinel.NewCacheCounters on the graph’s cache | sentinel.CounterStore; plug Redis for counts exact across replicas |
Routes | sentinel.DefaultRoutes | guarded manifest paths => attempt kind |
Signals / NoBuiltIn | built-ins | your sentinel.Signals, after (or instead of) the built-ins |
HTTPClient | http.DefaultClient | fetches lists for RefreshDomainList |
Routes
Section titled “Routes”Guarded by default (middleware, before core’s endpoint; all POST): /auth/register, /auth/login,
/auth/password/forgot, /auth/email/verify/resend, /auth/mfa/challenge.
| Method | Path | Purpose |
|---|---|---|
| GET | /admin/sentinel/decisions | decisions, newest first; filters email, ip, action, cursor, limit (admin read) |
| GET | /admin/sentinel/ip-rules | the IP rules, in matching order (admin read) |
| POST | /admin/sentinel/ip-rules | add {cidr, action: allow|block, note?} (admin own) |
| DELETE | /admin/sentinel/ip-rules/{id} | remove a rule (admin own) |
| POST | /admin/sentinel/unblock | clear the counters of {identifier} (an email or an IP; admin support) |
limit is a positive integer in digits only (1.5, 1e1 or 2 answer 422). Times are RFC 3339
in UTC (2026-09-11T10:00:00Z).
Events and permissions
Section titled “Events and permissions”sentinel.evaluated (sentinel.Evaluated, whenever a signal spoke; never the password nor the
captcha token), sentinel.ip_rule_created, sentinel.ip_rule_deleted, sentinel.unblocked; all
in the audit catalog. Admin routes use the admin plugin’s capabilities (admin.Read, admin.Own,
admin.Support).
Problems
Section titled “Problems”Enforce mode only: https://polaris.univeros.io/problems/sentinel/blocked (403) and
…/sentinel/challenge_required (403, "challenge": "captcha", only with Captcha set; the client
retries the same request with captcha_token). Admin routes answer …/admin/unauthorized (401),
…/admin/forbidden (403), …/admin/impersonation_denied (403), …/admin/invalid_input (422),
…/admin/not_found (404). Failing to record a decision answers 500; a failing signal is skipped.
Host integration
Section titled “Host integration”- Erasing a user deletes its known devices inside the erasure’s transaction (
wiring.UserEraser). Past decisions keep the address of the attempt; they are keyed by address, not by user. - Without a
Captchaverifier nothing can answer a challenge: the challenge band is recorded and let through. - The middleware reads the request as the endpoint does (query, JSON and form fields) and sets the
polaris_devicecookie (sentinel.DeviceCookie) when a guarded request has none. The cookie isSecurewhen the request came over TLS or the configured issuer (AUTH_ISSUER) is https, so it is behind a proxy that ends TLS too. sentinel.Of(g).Engine().Evaluate(ctx, sentinel.Attempt{…})judges your own attempts;Engine().Unblock,IPRules()andDecisions()serve the same as the admin routes.Plugin.RefreshDomainList(ctx, url, to)writes a fresh disposable-domain file; it is read at the next start.- With
plugins/messaging, a recipient challenged or blocked in enforce mode in the last hour gets no non-essential email (Plugin.QuietFor). Verifications, resets, codes, invitations and account-change mails (password, factors, recovery codes) are essential.
Example
Section titled “Example”Example in example_test.go — go doc github.com/univeros/polaris.go/plugins/sentinel.