# aws-iam-privilege-escalation

Rule `sonarjs/aws-iam-privilege-escalation`. AWS IAM policies should limit the scope of permissions given

- 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: #1175 by reach, #476 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/aws-iam-privilege-escalation` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-6317/) |

## Code examples

### Incorrect: the rule reports this

```js
import {aws_iam as iam} from 'aws-cdk-lib'

new iam.PolicyDocument({
    statements: [new iam.PolicyStatement({
        effect: iam.Effect.ALLOW,
        actions: ["lambda:UpdateFunctionCode"],
        resources: ["*"], // Noncompliant
    })],
})
```

### Correct: the rule accepts this

```js
import {aws_iam as iam} from 'aws-cdk-lib'

new iam.PolicyDocument({
    statements: [new iam.PolicyStatement({
        effect: iam.Effect.ALLOW,
        actions: ["lambda:UpdateFunctionCode"],
        resources: ["arn:aws:lambda:us-east-2:123456789012:function:my-function:1"], // Noncompliant
    })],
})
```

Examples from the ESLint documentation.

## Enable it

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

```js
export default [
  {
    rules: {
      "sonarjs/aws-iam-privilege-escalation": "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-iam-all-privileges](https://lintradar.dev/rules/sonarjs/aws-iam-all-privileges.md): Policies should not grant all privileges
- [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-efs-unencrypted](https://lintradar.dev/rules/sonarjs/aws-efs-unencrypted.md): Amazon EFS file systems should be encrypted
- [sonarjs/aws-opensearchservice-domain](https://lintradar.dev/rules/sonarjs/aws-opensearchservice-domain.md): OpenSearch domains should have encryption at rest enabled
- [sonarjs/aws-ec2-unencrypted-ebs-volume](https://lintradar.dev/rules/sonarjs/aws-ec2-unencrypted-ebs-volume.md): EBS volumes should be encrypted
- [sonarjs/aws-rds-unencrypted-databases](https://lintradar.dev/rules/sonarjs/aws-rds-unencrypted-databases.md): Amazon RDS resources should be encrypted at rest

---

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