Skip to main content
MEDIUMEC2Security

VPC Default Security Group Has Rules

vpc-default-security-group-rules-present

What this rule checks

Detects default VPC security groups with ingress or egress rules; defaults should be empty.

How to fix it

  1. 1Remove all rules from the default security group
  2. 2Use purpose-built security groups instead
FlaggedThe check flags a security group named 'default' that carries ingress or egress rules. Default security groups cannot be deleted and should be left empty; adding rules to them is an anti-pattern that widens the blast radius.
import { App, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

// FLAGGED: rules added to the VPC's default security group.
new ec2.CfnSecurityGroup(this, 'DefaultSg', {
  groupName: 'default',
  groupDescription: 'default VPC security group',
  securityGroupIngress: [
    { ipProtocol: 'tcp', fromPort: 443, toPort: 443, cidrIp: '0.0.0.0/0' },
  ],
});
FixedThe default group is left with no rules, and traffic is governed by a dedicated, purpose-built security group instead. The rule only inspects groups named 'default', so the custom group is unaffected.
import { App, Stack } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import * as ec2 from 'aws-cdk-lib/aws-ec2';

// FIXED: default group left empty; a purpose-built SG carries the rules.
new ec2.CfnSecurityGroup(this, 'DefaultSg', {
  groupName: 'default',
  groupDescription: 'default VPC security group',
});
new ec2.CfnSecurityGroup(this, 'WebSg', {
  groupDescription: 'web tier',
  securityGroupIngress: [
    { ipProtocol: 'tcp', fromPort: 443, toPort: 443, cidrIp: '0.0.0.0/0' },
  ],
});

CDK Insights pinpoints the exact file and line in your CDK source for every finding, so you can jump straight to the fix.

Affected resource types

AWS::EC2::SecurityGroup

Compliance frameworks

SOC2HIPAAPCI-DSSCISNIST

AWS documentation

Read the AWS guidance

Intentional? Suppress this finding

Sometimes a flag is deliberate — a genuinely public endpoint, say. You can dismiss vpc-default-security-group-rules-present and the reason is kept in the report, not silently hidden.

In .cdk-insights.json:

{
  "ignoreRules": [
    { "id": "vpc-default-security-group-rules-present", "reason": "Why this is intentional" }
  ]
}

Or inline in your CDK code:

Validations.of(scope).acknowledge({
  id: 'cdk-insights::vpc-default-security-group-rules-present',
  reason: 'Why this is intentional',
});

Use the rule ID vpc-default-security-group-rules-present shown above — not the CDK-* ID from SARIF / GitHub code scanning. To dismiss every finding on one construct instead, use ignorePaths. Suppression docs →

Catch this in your stack

$ npx cdk-insights scan

CDK Insights runs this and 118+ other rules locally against your synthesised CDK app — free, no account, your code never leaves your machine.

More EC2 rules