Skip to content

Settings And IP Resolution

Login Audit wraps rappasoft/laravel-authentication-log, stores Capell-owned audit rows, adds settings, and registers a frontend activity middleware alias.

SurfaceCode
ModelCapell\LoginAudit\Models\LoginAudit
ObserverLoginAuditObserver on the vendor authentication log model
Middleware aliasfrontend.activity
Settings grouplogin_audit
Protected tablelogin-audit.table_name, default login_audit
Admin bridgeLoginAuditAdminBridge
User schema extenderLoginAuditUserSchemaExtender
KeyUse
login-audit.table_nameAudit table name.
login-audit.db_connectionOptional database connection for audit rows.
login-audit.eventsAuth events the package listens to.
login-audit.listenersListener classes for those events.
login-audit.notifications.new-device.enabledSends new-device notifications.
login-audit.notifications.failed-login.enabledSends failed-login notifications.
login-audit.device_cookieName and lifetime of the cookie that recognises a browser. Only a hash of its token is stored.
login-audit.admin_alerts.new_devicesSends Capell admin alerts for first-seen devices.
login-audit.admin_alerts.failed_loginsSends Capell admin alerts for failed logins when enabled.
login-audit.admin_alerts.suspicious_loginsSends Capell admin alerts for suspicious login rows.
login-audit.purgeRetention window used by cleanup.
login-audit.hash_secretSecret for the keyed IP, user-agent and identifier hashes (CAPELL_LOGIN_AUDIT_HASH_SECRET, falling back to APP_KEY).
login-audit.previous_hash_secretsSecrets rotated away from (CAPELL_LOGIN_AUDIT_PREVIOUS_HASH_SECRETS, comma-separated). Lookups still match rows written under them.
login-audit.behind_cdnCDN IP header config, or false.
login-audit.unknown_account_rate_limitUnknown-account rows written per client address: max_attempts per decay_seconds (30 per 60).

Login Audit never stores a raw IP address or login identifier. It stores keyed hashes (ip_address_hash, user_agent_hash and identifier_hash) made with login-audit.hash_secret. A keyed hash cannot be reversed, so rows cannot be re-hashed under a new secret. Without the old secret, changing the secret silently breaks every lookup against retained rows:

  • a data subject’s privacy export and erasure miss their unknown-account attempts, which carry only identifier_hash;
  • logout and other-device logout stop finding the open session row when the device fingerprint has changed, and record a new row instead;
  • last-seen activity stops updating sessions that began before the change;
  • the IP fingerprint shown in the access log changes for the same address, so rows before and after the change no longer look alike;
  • the unknown-account rate limit starts a fresh counter (it lasts at most unknown_account_rate_limit.decay_seconds).

Each new row records a non-reversible identifier of the secret that wrote it (hash_key_id), never the secret itself. Rows written before that column existed have no identifier and are treated as written under an earlier secret.

To rotate the secret:

  1. Generate a new secret, for example with php -r 'echo base64_encode(random_bytes(32)), PHP_EOL;'.
  2. Move the current value of CAPELL_LOGIN_AUDIT_HASH_SECRET into CAPELL_LOGIN_AUDIT_PREVIOUS_HASH_SECRETS. Keep any value already there, comma-separated.
  3. Set CAPELL_LOGIN_AUDIT_HASH_SECRET to the new secret.
  4. Rebuild the configuration cache with php artisan config:cache, then restart queue workers so they read the new values.
  5. Run php artisan login-audit:hash-secrets. It reports how many retained rows may still depend on a previous secret and the date the retention purge should remove the last of them. The Diagnostics check Login Audit: hash secret rotation reports the same state.
  6. After that date, run the command again. When it reports that no retained row depends on a previous secret, remove CAPELL_LOGIN_AUDIT_PREVIOUS_HASH_SECRETS and rebuild the configuration cache. Diagnostics warns while a previous secret is configured that no row needs.

New rows always use the current secret. Lookups, logout matching, privacy export and erasure accept the current secret and every previous secret. With the default 90-day retention, plan to keep a previous secret for at least 90 days after rotating, and longer if the scheduled purge has not been running.

If CAPELL_LOGIN_AUDIT_HASH_SECRET is not set, the hash secret is APP_KEY, and rotating APP_KEY rotates this secret too. List the old key in Laravel’s APP_PREVIOUS_KEYS (Login Audit accepts those as previous hash secrets while it falls back to APP_KEY) or in CAPELL_LOGIN_AUDIT_PREVIOUS_HASH_SECRETS. Setting a dedicated CAPELL_LOGIN_AUDIT_HASH_SECRET keeps the two rotations separate; if you introduce one on an installation that used APP_KEY, list the current APP_KEY in CAPELL_LOGIN_AUDIT_PREVIOUS_HASH_SECRETS at the same time.

Never print or paste a secret into a log, ticket or chat. The command and Diagnostics report counts and dates only.

ResolveLoginAuditIpAddressAction returns null when IP tracking is disabled by settings. When login-audit.behind_cdn is configured, it reads the configured server header instead of Request::ip().

config/login-audit.php
'behind_cdn' => [
'http_header_field' => 'HTTP_CF_CONNECTING_IP',
],

Only set this when the application is actually behind a trusted CDN or proxy. A spoofable header is worse than no IP logging.

New audit rows store a coarse summary such as Chrome 131; Windows; desktop: browser family and major version, platform family, and device class. Unknown clients use fixed unknown labels. Minor versions, operating-system versions, device models and arbitrary client tokens are discarded. A keyed hash of the original request user agent remains available for session matching; activity and logout updates preserve that hash.

Existing raw user-agent values are left unchanged. No migration rewrites historical evidence. The existing daily authentication-log:purge retention path removes those rows when they expire (90 days by default, or the configured login_audit.retention_days). Keep Laravel’s scheduler running; shortening retention deletes complete audit rows and cannot be undone.

Location lookup is off by default. Enabling login_audit.enable_geo_location alone does not enable a lookup: the application must also explicitly set geoip.service to a named entry in geoip.services, with an available provider class. Configure that provider’s credentials or local database in the host application before enabling the setting. Login Audit ships no provider credentials or location database. With no configured provider, both successful and failed events keep location lookup disabled.

Location-change detection needs stored locations from a working provider. The package does not infer a location from an IP hash. Provider availability checks do not prove credentials, connectivity or the database are valid.

The settings screen controls the repeated-failure threshold and minute window. Developers configure login-audit.suspicious.failed_device_window_hours (24), location_window_minutes (60), usual_hours (09:00–17:59 inclusive) and timezone (application timezone when null) in application configuration. The unusual-hours check must also be enabled in settings.

Failed attempts are recorded for every existing Eloquent user. Unknown-account attempts are recorded as actorless rows. The submitted identifier is lower-cased, trimmed and stored only as a keyed hash (identifier_hash); the raw address and the password are never retained. These rows follow the same retention as other rows, and a data subject’s export and erasure include rows whose hash matches the subject’s email.

The Approve:TwoFactorReset permission and allow_staff_approved_two_factor_resets setting are host integration points. The host application must implement verification, approval, notifications and auditing; the Capell App consumes both through its two-factor reset policy. Access Gate has no direct bridge in this package; authentication events remain the integration boundary.