Guide
Security events from your application
Your login page is a target too. Password guessing and password spraying against your own app's sign-in show up in no firewall, VPN or identity provider log, because the app checks the password itself. The Logthread SDKs for Node.js, Python and .NET can record your app's sign-ins, permission changes and admin actions as security events. Logthread's security detections then read them like any other security source, so they fire on attacks against your app.
A security event is an ordinary log record in Logthread's security fields. It travels through the SDK you already use, with the same key, batching, redaction and per-request correlation id. You can find it in Explore, follow it in Threads and alert on it like any other log.
What you get#
| Detection | Fires when | Reads |
|---|---|---|
| Brute force from one address | more than 10 failed sign-ins from one address in 10 minutes | event.category:authentication event.outcome:failure, by source.address |
| Password spraying | failed sign-ins for 5 or more different users from one address in 15 minutes | the same failures, distinct user.name by source.address |
Both open one incident per attacking address, with Follow it in Threads and Its records in Explore. Your app's sign-ins count together with your servers' SSH sign-ins, Entra ID and the other sources, so the same address is caught wherever it tries. You can also write your own rules over the events, for example event.action:role_granted user.target.roles:admin (an admin role was granted).
To turn the detections on, open Security, SIEM, and choose Use on each one.
Who is behind a sign-in#
Seven more detections look at where a sign-in comes from: the location and network GeoIP adds to every address, and a device id when you send one. They read people's sign-ins: your app's, Entra ID, Okta and Microsoft 365. Server sign-ins (SSH, Windows logons) are left out of the first six, because accounts such as root and deploy are shared by people and CI jobs everywhere. The brute-force detection includes them, because a guessed server password is the classic compromise.
| Detection | Fires when |
|---|---|
| Impossible travel between sign-ins | two successful sign-ins in a row for one account, in different countries, are further apart than anyone can travel in between: over 900 km/h by city location, within 6 hours. Moves inside one country never count, because mobile networks place their addresses in a hub city. |
| One account signing in from many networks | one account signs in from 3 or more networks (ASNs) within an hour. |
| Sign-in from a server, VPN or Tor network | a successful sign-in comes from a cloud or hosting provider (by network, and by the IP ranges AWS, Google Cloud, Oracle and DigitalOcean publish), a commercial VPN exit or Tor. Cloudflare and Microsoft networks are left out, because iCloud Private Relay and Microsoft's own traffic carry ordinary people. |
| Many accounts signed in from one address | 5 or more different accounts sign in successfully from one address within an hour. |
| One device signing in to many accounts | one device tries 5 or more different accounts within an hour, even from different addresses. |
| One device hopping between countries | one device is seen from 3 or more countries within an hour. |
| Brute force on one account that succeeded | 10 or more failed sign-ins in a row for one account, from any number of addresses and devices, then a successful one, within 30 minutes. Only the failures since the account's previous successful sign-in count, so typos and an old phone with a stale password stay quiet. An SSH key sign-in never counts as the success. |
Device ids. The two "one device" detections need device.id on your sign-in events: a per-device id, such as a long-lived device cookie or an app install id. The SDKs set one for you. Their device id middleware gives each browser a random lt_did cookie: 32 hex characters, kept about two years, HttpOnly, SameSite=Lax, and Secure on HTTPS. A valid cookie is reused and a malformed one is replaced. Every security event that you pass the request to then carries the id, from the very first request. To send your own id instead, such as a mobile app's install id, pass it as deviceId (device_id in Python). Behind a proxy or load balancer that ends TLS, tell your framework to trust it, so the cookie is marked Secure: Express app.set('trust proxy', ...), Django SECURE_PROXY_SSL_HEADER, or ASP.NET Core forwarded headers.
// Node.js: Express (Fastify: an onRequest hook; Koa: ensureDeviceId(ctx))
app.use((req, res, next) => { ensureDeviceId(req, res); next() })# Python: Django (FastAPI: app.add_middleware(logthread.DeviceIdMiddleware))
MIDDLEWARE = ["logthread.django.DeviceIdMiddleware", ...]// .NET: AddLogthreadSecurity() and LogthreadSignInManager pick it up
app.UseLogthreadDeviceId();The id is random. It is never derived from the user agent, the address or TLS data. Don't use a TLS or browser fingerprint such as JA4 or JA3: one fingerprint is shared by millions of people on the same browser, so these detections would fire all day.
The other five need only the client address, which the SDK sends, and GeoIP enrichment turned on in Data in → Enrichment. The detection list on Security → SIEM says when a detection still needs either.
Your own VPN or office. A company VPN or jump host in the cloud, or one office address everyone shares, looks like these patterns. Exclude it in the rule, for example -source.address:203.0.113.10.
The fields#
| Call | event.category | event.action | user.name | user.target.name |
|---|---|---|---|---|
| sign-in | authentication | sign_in | the account name that was typed | |
| sign-out | authentication | sign_out | the user | |
| permission change | iam | role_granted or role_revoked | who made the change | whose permissions changed (and user.target.roles) |
| admin action | configuration, or the category you pass | the action you pass, for example user_deleted | who did it | on whom |
| any event | the category you pass | the action you pass |
Every event also has these fields:
event.outcome:success,failureorunknown;source.address: the client address;user_agent.original;- optionally
event.reason(for examplebad_password),auth.method(for examplepasswordoroidc),user.idanddevice.id(see Device ids above).
A failure is logged at warn level, everything else at info.
Node.js#
import { init } from '@logthread/node'
const lt = init()
app.post('/login', async (req, res) => {
const user = await checkPassword(req.body.email, req.body.password)
lt.security.signIn({
user: req.body.email,
outcome: user ? 'success' : 'failure',
reason: user ? undefined : 'bad_password',
method: 'password',
req,
})
// ...
})
lt.security.permissionChanged({ actor: admin.email, target: member.email, role: 'admin', req })
lt.security.adminAction({ actor: admin.email, action: 'api_key_created', target: 'billing-service', req })- Where the address and user agent come from:
reqcan be an Expressreq, a Fastifyrequest, a Koactxor a plainhttprequest. The address is itsip, else the socket address. Behind a load balancer, set Expressapp.set('trust proxy', ...)or FastifytrustProxy, soipis the client and not the proxy. - Without a logger instance: the module-level
securityobject (import { security } from '@logthread/node') uses the default logger. - Correlation: add
app.use(correlation())as for any log (see Correlation ids), and each event carries the request's correlation id.
Python#
import logthread
logthread.install()
# FastAPI / Starlette
@app.post("/login")
async def login(form: LoginForm, request: Request):
user = check_password(form.email, form.password)
logthread.security.sign_in(form.email, outcome=bool(user), method="password",
reason=None if user else "bad_password", request=request)
logthread.security.permission_changed(actor=admin.email, target=member.email, role="admin",
request=request)
logthread.security.admin_action(actor=admin.email, action="user_deleted", target=member.email,
category="iam", request=request)request can be a Starlette or FastAPI Request, a Django HttpRequest, a Flask request or an ASGI scope. The address comes from the framework's own setting: uvicorn --forwarded-allow-ips or Werkzeug ProxyFix behind a proxy. Logthread never reads X-Forwarded-For itself, because a client can set it.
Django: one line records every sign-in that goes through django.contrib.auth: the admin, LoginView, authenticate() and packages built on them, such as django-allauth. It records successes, failures with the user name that was tried, and sign-outs.
# apps.py
class MyAppConfig(AppConfig):
def ready(self):
from logthread.django import connect_security_signals
connect_security_signals().NET#
// Program.cs
builder.Logging.AddLogthread();
builder.Services.AddLogthreadSecurity(); // dotnet add package Logthread.AspNetCore
// ASP.NET Core Identity: every password check, including unknown users
builder.Services.AddDefaultIdentity<AppUser>()
.AddSignInManager<LogthreadSignInManager<AppUser>>()
.AddEntityFrameworkStores<AppDbContext>();AddLogthreadSecurity() records:
- every
HttpContext.SignInAsyncas a successful sign-in, whether from a cookie login, Identity, OpenID Connect or Entra ID, with the scheme asauth.method; - every sign-out.
LogthreadSignInManager records each Identity password check, with one of these reasons:
bad_password;unknown_user, with the name that was typed;locked_out;not_allowed.
Without Identity, record failures where you check the password, with the request's address and user agent:
app.MapPost("/login", async (LoginForm form, HttpContext http, LogthreadSecurity security) =>
{
var ok = await users.CheckPasswordAsync(form.Email, form.Password);
security.SignIn(http, form.Email, ok ? SecurityOutcome.Success : SecurityOutcome.Failure,
method: "password", reason: ok ? null : "bad_password");
// ...
});
security.PermissionChanged(http, admin.Email, member.Email, "admin");
security.AdminAction(http, admin.Email, "api_key_created", target: "billing-service");- The address:
Connection.RemoteIpAddress. Behind a proxy, addapp.UseForwardedHeaders()with your proxies as known proxies. - Without ASP.NET Core:
client.Security.SignIn(user, SecurityOutcome.Failure, sourceAddress: ip)works on anyLogthreadClient.
Rejected tokens: AddLogthreadSecurity(o => o.RecordAuthenticationFailures = true) also records requests whose token or cookie is rejected (an invalid or expired JWT, a tampered cookie). It records them once per request, with the exception type as the reason. It is off by default, because a client that keeps sending an expired token fails on every request, and the brute-force detection would count each failure.
What stays manual#
These are app-specific, so record them with an explicit call where your code decides:
- multi-factor: a failed MFA code, as
signInwithaction: 'mfa_challenge'; - account lockouts;
- API-key authentication;
- sign-ins in frameworks without auth events: Express, Fastify, Koa, FastAPI and Flask.
Privacy#
- Passwords and tokens are never sent. No call has a password parameter. An extra attribute whose name contains
password,pwd,secret,token,authorization,cookie,api_key,credential,private_key,session_id,otp_codeormfa_codeis dropped, also inside nested objects. A value that starts withBearerorBasic, or that looks like a JWT, is written as[REDACTED]in every field. - No message text from an exception. A rejected token records only the exception type, never its message, which can quote the token.
- The rest goes through your settings. The SDK's
redactKeysandbeforeSendapply to security events as to every log, and so do your workspace's redaction pipelines, for example to hashuser.nameor dropuser_agent.original. - What is sent: user names and client addresses are personal data. They are sent because the detections need them. Your retention and data controls apply as to all logs.
Check it works#
- Try a few wrong passwords on your login.
- Search Explore for
event.category:authentication event.outcome:failure. You should see the events with your address and the name you typed. - Security, SIEM now shows matching records for Brute force from one address and Password spraying. Choose Use to turn them on.
The SDK reference pages have the full signatures: Node.js, Python and .NET.