Create a POST /v1/user/check_status endpoint in a Ruby on Rails API-only application.
This endpoint will perform a series of security checks to determine the ban status of a user.
- Endpoint:
POST /v1/user/check_status - Content-Type:
application/json
{
"idfa": "8264148c-be95-4b2b-b260-6ee98dd53bf6",
"rooted_device": false
}{
"ban_status": "not_banned" // or "banned"
}-
CF-IPCountry Header Whitelisting Ban the user if the
CF-IPCountryheader value is not in the Redis country whitelist.Note: The application is behind a Cloudflare proxy, which passes this header.
-
Rooted Device Check Ban if
rooted_deviceistrue. -
IP Check for Tor/VPN
- Ban if the IP is identified as Tor or VPN.
- Use VPNAPI for this check.
- Cache the VPNAPI responses in Redis for 24 hours.
- If the VPNAPI check fails (rate limit, server error), consider the check as passed.
- Create a new user record if
IDFAdoes not exist. - Update the user record if
IDFAexists. - If an existing user is already banned, skip the check chain and return
"banned"status. - Re-run the checks for returning
"not_banned"users. - Include the following fields in the
Usermodel:idfaban_status(initial values:banned,not_banned)created_atupdated_at
- Create a log record when a new user is created or an existing user’s
ban_statuschanges. - Include the following fields in the
IntegrityLogmodel:idfaban_statusiprooted_devicecountryproxyvpncreated_at
- Implement a service for the integrity logger to allow future re-routing of logs to other data sources.
- Design the
Usermodel to accommodate additionalban_statusvalues in the future.
- Ruby on Rails 7 (API only)
- PostgreSQL
- Redis
- RSpec/FactoryBot for testing
- Provide comprehensive tests using RSpec.