Skip to content

feat(socket): Add CIDR support for ip whitelisting - #30

Merged
Rushaway merged 4 commits into
srcdslab:masterfrom
Dolly132:main-dolly2
Aug 5, 2026
Merged

feat(socket): Add CIDR support for ip whitelisting#30
Rushaway merged 4 commits into
srcdslab:masterfrom
Dolly132:main-dolly2

Conversation

@Dolly132

@Dolly132 Dolly132 commented Aug 5, 2026

Copy link
Copy Markdown
Contributor

No description provided.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR extends SM JSON API’s connection whitelist to support CIDR ranges (in addition to exact IP matches) when deciding whether to accept incoming socket connections.

Changes:

  • Bumps plugin version to 1.2.1.
  • Replaces the inline whitelist check on connect with a new IsIPWhitelisted() helper.
  • Adds CIDR parsing/matching helpers (IsIPInCIDR, IPv4ToInt) to support entries like 172.17.0.0/16.
Suppressed comments (3)

addons/sourcemod/scripting/SMJSONAPI.sp:592

  • Invalid/negative CIDR prefix lengths should not silently widen the whitelist. Currently iPrefixLen <= 0 returns true (which would also allow entries like "/-1" to match all), and values > 32 are clamped. Consider treating out-of-range values as invalid (false), and only treating exactly /0 as match-all.
    if (iPrefixLen <= 0)
    	return true;
    if (iPrefixLen > 32)
    	iPrefixLen = 32;

addons/sourcemod/scripting/SMJSONAPI.sp:610

  • IPv4ToInt() currently doesn't validate octet ranges and uses 0 as an "invalid" sentinel, which makes valid CIDRs like "0.0.0.0/8" impossible to match. Validate each octet is 0..255 and return a distinct invalid value (e.g. -1) on parse failure.
int IPv4ToInt(const char[] ip)
{
    char octets[4][4];
    if (ExplodeString(ip, ".", octets, 4, 4) != 4)
        return 0;

addons/sourcemod/scripting/SMJSONAPI.sp:598

  • If IPv4ToInt() is updated to return -1 on failure, this check should be updated accordingly; otherwise CIDRs involving 0.0.0.0 ranges will continue to be treated as invalid and never match.
    if (iClientIp == 0 || iRangeIp == 0)
        return false;

Comment thread addons/sourcemod/scripting/SMJSONAPI.sp Outdated
Comment thread addons/sourcemod/scripting/SMJSONAPI.sp
Comment thread addons/sourcemod/scripting/SMJSONAPI.sp Outdated
Dolly132 and others added 3 commits August 5, 2026 16:49
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@Rushaway
Rushaway merged commit d5e89c9 into srcdslab:master Aug 5, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants