AWS CDK S3 Bucket Enforce SSL
This codemod automatically adds the enforceSSL: true property to AWS CDK S3 Bucket constructor calls to enforce encryption-in-transit. This addresses the security vulnerability CWE-319: Cleartext Transmission of Sensitive Information.
Why Use This Codemod?
AWS S3 buckets without SSL enforcement allow unencrypted HTTP connections, which poses a security risk for sensitive data transmission. This codemod helps you automatically secure your S3 buckets by ensuring all requests must use HTTPS/TLS encryption.
What It Does
The codemod transforms AWS CDK S3 Bucket constructor calls to include the enforceSSL: true property:
Before
typescript
After
typescript
Supported Import Patterns
This codemod works with various AWS CDK import patterns:
typescript
What It Won't Transform
The codemod safely skips:
- Buckets that already have
enforceSSL: true - Buckets with
enforceSSL: false(intentionally disabled) - Non-S3 Bucket constructors (custom classes, other AWS services)
- Files without AWS CDK S3 imports
Installation & Usage
Via Codemod CLI (Recommended)
bash
Via Package Manager
bash
Options
bash
File Extensions Supported
.ts(TypeScript).tsx(TypeScript with JSX).js(JavaScript).jsx(JavaScript with JSX)
Security Impact
This transformation helps address:
- CWE-319: Cleartext Transmission of Sensitive Information
- AWS Security Best Practices for S3 encryption in transit
- Compliance requirements that mandate encrypted data transmission
Limitations & Caveats
-
Manual Review Recommended: While this codemod is designed to be safe, review the changes before committing, especially for buckets used for public static websites where HTTPS enforcement might not be desired.
-
CDK Version Compatibility: Works with both CDK v1 (
@aws-cdk/*) and CDK v2 (aws-cdk-lib) import patterns. -
Complex Prop Objects: The codemod handles standard object literals but may not work correctly with computed property names or complex spread operations.
Development
Building from Source
bash
Running Tests
bash
Contributing
This codemod is part of the Arc Security Codemods collection. Contributions are welcome!
References
- AWS CDK Bucket.enforceSSL Documentation
- AWS S3 Security Best Practices
- CWE-319: Cleartext Transmission of Sensitive Information
- AWS Blog: S3 Bucket Policies and Defense in Depth
License
MIT