Add IP banning: connection logging, IP bans, and transitive banning - #263
Open
decentraland-bot wants to merge 2 commits into
Open
Add IP banning: connection logging, IP bans, and transitive banning#263decentraland-bot wants to merge 2 commits into
decentraland-bot wants to merge 2 commits into
Conversation
…anning - New migration (1772000000000_ip-banning) adds connection_logs and ip_bans tables. connection_logs records wallet↔IP pairs on every successful token request; a 90-day TTL cleanup cron is a follow-up item. - IP extraction (x-forwarded-for → x-real-ip) runs on every comms-scene request; the (address, ip) pair is logged after credentials are issued. - IP ban check is performed before issuing a token; banned IPs receive 403. - New DB adapter (ip-moderation-db) and logic component (ip-moderation) mirror the existing user-moderation layer: banIp, liftIpBan, getIpBanStatus, logConnection, getIpsByAddress, getAddressesByIp, banAllIpsForAddress, banAllAddressesForIp. - New REST endpoints: POST/GET/DELETE /ips/:ip/bans, GET /users/:address/ips, GET /ips/:ip/users; all protected by the existing moderator middleware. - POST /users/:address/bans gains an optional banAllKnownIps boolean for transitive banning; POST /ips/:ip/bans gains banAllKnownAddresses. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Coverage Report for CI Build 26661766696Coverage decreased (-0.5%) to 84.791%Details
Uncovered Changes
Coverage Regressions2 previously-covered lines in 1 file lost coverage.
Coverage Stats💛 - Coveralls |
Implement GDPR data subject rights (Art. 15, 17, 20) for the IP banning feature since IP addresses are PII under GDPR: - GET /users/:address/personal-data — exports all PII (connection logs, bans, warnings, IP bans) for a wallet address (moderator read access) - DELETE /users/:address/personal-data — purges connection logs for a wallet address while retaining moderation records under legitimate interest basis (moderator write access) - Automated daily retention cleanup purging connection logs older than configurable CONNECTION_LOG_RETENTION_DAYS (default 90 days) - Migration adding index on connection_logs.connected_at for efficient TTL purge queries Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds three related capabilities to the comms-gatekeeper moderation system:
1. Connection logging
POST /get-scene-adapterrequest now logs a(address, ip)pair to a newconnection_logstable.x-forwarded-for(first entry) →x-real-ip→ falls back toundefined(no-op) if neither header is present.2. IP banning
ip_banstable mirrors the shape ofuser_bans(same fields, keyed onbanned_ip).POST /ips/:ip/bans— ban an IP (mod auth required); body:{ reason, duration?, customMessage?, banAllKnownAddresses? }GET /ips/:ip/bans— get IP ban status (public)DELETE /ips/:ip/bans— lift an IP ban (mod auth required)3. Transitive banning
GET /users/:address/ips— list all IPs a wallet has connected from (mod read auth)GET /ips/:ip/users— list all wallets seen from an IP (mod read auth)POST /users/:address/bansnow acceptsbanAllKnownIps?: boolean— if true, also bans all IPs the wallet has connected from.POST /ips/:ip/bansacceptsbanAllKnownAddresses?: boolean— if true, also bans all wallets seen from that IP.IpAlreadyBannedError/PlayerAlreadyBannedError.New files
src/migrations/1772000000000_ip-banning.tsconnection_logsandip_banstablessrc/adapters/ip-moderation-db.tssrc/logic/ip-moderation/types.tssrc/logic/ip-moderation/errors.tsIpAlreadyBannedError,IpBanNotFoundErrorsrc/logic/ip-moderation/component.tssrc/logic/ip-moderation/extract-ip.tssrc/controllers/handlers/ip-moderation/Modified files
src/types.ts— addsipModerationDbandipModerationtoBaseComponentssrc/components.ts— instantiates and wires the new componentssrc/controllers/routes.ts— registers the new routessrc/controllers/handlers/comms-scene-handler.ts— adds IP ban check and connection loggingsrc/controllers/handlers/error-handler.ts— handlesIpAlreadyBannedErrorandIpBanNotFoundErrorsrc/controllers/handlers/user-moderation/ban-player-handler.ts— supportsbanAllKnownIpssrc/controllers/handlers/user-moderation/schemas.ts— addsbanAllKnownIpstoBanPlayerSchemaTest plan
test/unit/ip-moderation/ip-moderation.spec.tscovering all component methodstest/integration/ip-moderation/ban-ip-handler.spec.tscovering all new endpointstsc --noEmit)comms-scene-handlerintegration tests unaffected (IP check is skipped when no IP header is present)🤖 Generated with Claude Code