logo

Use of an insecure channel - HTTP - Cloudformation


Need

Secure transmission of client information


Context

  1. Usage of CloudFormation for Infrastructure as Code (IaC)
  2. Usage of AWS SDK for interacting with Amazon Web Services

Description

Insecure Code Example

Resources:
  WebSecurityGroup:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow HTTP inbound traffic
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 80
          ToPort: 80
          CidrIp: 0.0.0.0/0

  WebInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0c94855ba95c574c8
      InstanceType: t2.micro
      SecurityGroupIds:
        - !Ref WebSecurityGroup
      Tags:
        - Key: Name
          Value: HelloWorld

The above CloudFormation code creates an EC2 instance and a security group that allows inbound HTTP traffic (port 80) from any source (0.0.0.0/0). This configuration is vulnerable because HTTP transmits data in plain text without encryption, allowing sensitive information to be easily intercepted by attackers.

Steps

  1. Update the security group to allow HTTPS traffic (port 443) instead of HTTP (port 80).
  2. Configure the application and web server to use TLS for secure communication.
  3. Obtain and install a valid SSL/TLS certificate.
  4. Redirect any HTTP traffic to HTTPS at the application or load balancer level.
  5. Deploy the updated CloudFormation stack in AWS.

Secure Code Example

Resources:
  WebSecurityGroupHTTPS:
    Type: AWS::EC2::SecurityGroup
    Properties:
      GroupDescription: Allow HTTPS inbound traffic
      SecurityGroupIngress:
        - IpProtocol: tcp
          FromPort: 443
          ToPort: 443
          CidrIp: 0.0.0.0/0

  WebInstance:
    Type: AWS::EC2::Instance
    Properties:
      ImageId: ami-0c94855ba95c574c8
      InstanceType: t2.micro
      SecurityGroupIds:
        - !Ref WebSecurityGroupHTTPS
      Tags:
        - Key: Name
          Value: HelloWorld

The updated code replaces HTTP with HTTPS by only allowing inbound traffic on port 443 (HTTPS). This ensures data transmission is encrypted using TLS. Make sure the application and web server are properly configured with a valid SSL/TLS certificate to support secure HTTPS connections.


References

  • 372 - Use of an insecure channel - HTTP

  • Last updated

    2025/04/04