Case study
Suspicious Login Detection
An n8n workflow that enriches each login event, sends a Slack alert with a HIGH, MEDIUM or LOW severity, and emails the user when a new location or device is seen.
The problem
A login from a known malicious IP address, or from a new location or device, should reach the team quickly and with context.
The user should also hear about a login from a place or device they have not used before.
Requirements
What I built
- A webhook receives a login event (a Segment-style track payload).
- The IP address and user agent go in parallel to GreyNoise (threat intelligence), IP-API (geolocation) and UserParser (device and browser).
- The GreyNoise result (malicious, benign, unknown, RIOT trust level) is mapped to a HIGH, MEDIUM or LOW alert severity and posted to Slack.
- If the IP address is not a known threat, the workflow checks the user’s recent login history in Postgres to see whether the location or the device and browser are new.
- For a new location or device, it looks up the user’s email address and sends an HTML notice through Gmail.1
How it works
- Login eventarrives through a webhook
- EnrichGreyNoise, IP-API and UserParser
- Set severityHIGH, MEDIUM or LOW, to Slack
- Check historyrecent login history
- Notify useremail for a new location or device
Security decisions
- No credentials in the workflow file: the Postgres, Slack, Gmail and UserParser credentials are created in n8n and selected in the nodes.1
- The database schema, Slack channel and example values are placeholders.1
- The public repository was cleaned of client data and scanned for secrets with gitleaks before publishing.2
Results
- One workflow covers both sides: an alert with a severity for the team in Slack, and a notice to the user for a new location or device.
- A manual trigger with an example login event is included, so the whole flow can run without a live application.1
- Public on GitHub with setup steps, ready to import into any n8n instance.3
What I’d do next
From the workflow’s README.1
- Use a geolocation provider over HTTPS; the free IP-API endpoint is HTTP only.
- Store each enriched login back in Postgres, to build the login history without a separate tracking pipeline.
- Add impossible-travel detection: the distance and time between consecutive logins.