Skip to content

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.

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_device

The zero value is the defaults: observe mode, the local signals, the bundled domain list.

FieldDefaultPurpose
Modesentinel.Observesentinel.Enforce answers blocks and challenges
Policychallenge from 40, block from 80sentinel.Policy{ChallengeAt, BlockAt} over the summed score (0..100)
Velocitysentinel.DefaultVelocity"ip", "email", "device" => sentinel.Limit{Max, Window}; a dimension left out is not counted
Captchanilsentinel.Turnstile(secret), sentinel.HCaptcha(secret) or your sentinel.BotVerifier
Geonil (sentinel.NoGeo)sentinel.GeoResolver for impossible travel; no geo database ships
Breachesnilsecurity.HIBP{} enables the breached-password signal (and core’s port unless Config.Breaches)
Domains / DisposableDomains / DisposableListFilebundled listreplace, extend or load the disposable-domain list
Counterssentinel.NewCacheCounters on the graph’s cachesentinel.CounterStore; plug Redis for counts exact across replicas
Routessentinel.DefaultRoutesguarded manifest paths => attempt kind
Signals / NoBuiltInbuilt-insyour sentinel.Signals, after (or instead of) the built-ins
HTTPClienthttp.DefaultClientfetches lists for RefreshDomainList

Guarded by default (middleware, before core’s endpoint; all POST): /auth/register, /auth/login, /auth/password/forgot, /auth/email/verify/resend, /auth/mfa/challenge.

MethodPathPurpose
GET/admin/sentinel/decisionsdecisions, newest first; filters email, ip, action, cursor, limit (admin read)
GET/admin/sentinel/ip-rulesthe IP rules, in matching order (admin read)
POST/admin/sentinel/ip-rulesadd {cidr, action: allow|block, note?} (admin own)
DELETE/admin/sentinel/ip-rules/{id}remove a rule (admin own)
POST/admin/sentinel/unblockclear 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).

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).

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.

  • 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 Captcha verifier 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_device cookie (sentinel.DeviceCookie) when a guarded request has none. The cookie is Secure when 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() and Decisions() 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 in example_test.go — go doc github.com/univeros/polaris.go/plugins/sentinel.