# aws-restricted-ip-admin-access

Rule `sonarjs/aws-restricted-ip-admin-access`. Administration services access should be restricted to specific IP addresses

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1179 by reach, #480 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/aws-restricted-ip-admin-access` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-6321/) |

## Code examples

### Incorrect: the rule reports this

```js
import {aws_ec2 as ec2} from 'aws-cdk-lib'

const instance = new ec2.Instance(this, "default-own-security-group",{
    instanceType: nanoT2,
    machineImage: ec2.MachineImage.latestAmazonLinux(),
    vpc: vpc,
    instanceName: "test-instance"
})

instance.connections.allowFrom(
    ec2.Peer.anyIpv4(), // Noncompliant
    ec2.Port.tcp(22),
    /*description*/ "Allows SSH from all IPv4"
)
```

```js
import {aws_ec2 as ec2} from 'aws-cdk-lib'

const securityGroup = new ec2.SecurityGroup(this, "custom-security-group", {
    vpc: vpc
})

securityGroup.addIngressRule(
    ec2.Peer.anyIpv4(), // Noncompliant
    ec2.Port.tcpRange(1, 1024)
)
```

```js
import {aws_ec2 as ec2} from 'aws-cdk-lib'

new ec2.CfnSecurityGroup(
    this,
    "cfn-based-security-group", {
        groupDescription: "cfn based security group",
        groupName: "cfn-based-security-group",
        vpcId: vpc.vpcId,
        securityGroupIngress: [
            {
                ipProtocol: "6",
                cidrIp: "0.0.0.0/0", // Noncompliant
                fromPort: 22,
                toPort: 22
            }
        ]
    }
)
```

### Correct: the rule accepts this

```js
import {aws_ec2 as ec2} from 'aws-cdk-lib'

const instance = new ec2.Instance(this, "default-own-security-group",{
    instanceType: nanoT2,
    machineImage: ec2.MachineImage.latestAmazonLinux(),
    vpc: vpc,
    instanceName: "test-instance"
})

instance.connections.allowFrom(
    ec2.Peer.ipv4("192.0.2.0/24"),
    ec2.Port.tcp(22),
    /*description*/ "Allows SSH from a trusted range"
)
```

```js
import {aws_ec2 as ec2} from 'aws-cdk-lib'

const securityGroup3 = new ec2.SecurityGroup(this, "custom-security-group", {
    vpc: vpc
})

securityGroup3.addIngressRule(
    ec2.Peer.anyIpv4(),
    ec2.Port.tcpRange(1024, 1048)
)
```

```js
import {aws_ec2 as ec2} from 'aws-cdk-lib'

new ec2.CfnSecurityGroup(
    this,
    "cfn-based-security-group", {
        groupDescription: "cfn based security group",
        groupName: "cfn-based-security-group",
        vpcId: vpc.vpcId,
        securityGroupIngress: [
            {
                ipProtocol: "6",
                cidrIp: "192.0.2.0/24", // Compliant
                fromPort: 22,
                toPort: 22
            }
        ]
    }
)
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/aws-restricted-ip-admin-access": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/aws-rds-unencrypted-databases](https://lintradar.dev/rules/sonarjs/aws-rds-unencrypted-databases.md): Amazon RDS resources should be encrypted at rest
- [sonarjs/aws-s3-bucket-granted-access](https://lintradar.dev/rules/sonarjs/aws-s3-bucket-granted-access.md): S3 buckets should not grant access to all users or authenticated users
- [sonarjs/aws-opensearchservice-domain](https://lintradar.dev/rules/sonarjs/aws-opensearchservice-domain.md): OpenSearch domains should have encryption at rest enabled
- [sonarjs/aws-s3-bucket-insecure-http](https://lintradar.dev/rules/sonarjs/aws-s3-bucket-insecure-http.md): S3 buckets should enforce HTTPS-only access
- [sonarjs/aws-iam-public-access](https://lintradar.dev/rules/sonarjs/aws-iam-public-access.md): AWS resource-based policies should not grant public access
- [sonarjs/aws-s3-bucket-public-access](https://lintradar.dev/rules/sonarjs/aws-s3-bucket-public-access.md): Amazon S3 bucket public access should be fully blocked

---

Web page: https://lintradar.dev/rules/sonarjs/aws-restricted-ip-admin-access. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
