Skip to content

[BE] Implement IP-based Geo-restriction for Regulated Markets #655

Description

@Hahfyeex

Type: BE
Component: backend/src/routes/bets.js

Context

Certain prediction market categories (political elections, sports betting) are regulated or illegal in specific jurisdictions. The platform needs the ability to restrict access to specific markets based on the user's IP geolocation to comply with local regulations and reduce legal risk.

Implementation Guide

  1. Add a restricted_countries column to the markets table: an array of ISO 3166-1 alpha-2 country codes (e.g. ['US', 'GB']).
  2. Add the geoip-lite package to package.json for IP-to-country lookup.
  3. In POST /api/bets, look up the requester's country from their IP address using geoip-lite.
  4. If the market has restricted_countries and the requester's country is in the list, return 403 with error: This market is not available in your region.
  5. Log all geo-restriction blocks with market_id, country_code, and IP hash (not full IP) for compliance reporting.

Guidelines

  • Security: log IP hash only, never the full IP address, for privacy compliance.
  • Key requirement: geoip-lite / restricted_countries Column / 403 on Block / Compliance Log / IP Hash.

Definition of Done

  • Bets from restricted countries return 403 with a clear error message.
  • Markets without restricted_countries are accessible from all countries.
  • Geo-restriction blocks are logged with IP hash and country code.
  • Unit tests cover restricted country, unrestricted country, and no restriction scenarios.
  • Test coverage > 95%.

PR and Checkout

git checkout -b feat/geo-restriction
git add .
git commit -m "feat: implement IP-based geo-restriction for regulated market categories"
git push origin feat/geo-restriction

Open a PR against main and include the issue number in the PR description.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions