For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/cloudformation-aws-s3-bucket-allows-list-actions-from-all-principals.md.
A documentation index is available at /llms.txt.
Bucket policies that grant list actions to all principals (*) allow anyone to enumerate a bucket’s contents and metadata. This can expose sensitive filenames and enable targeted data discovery or exfiltration. For CloudFormation, inspect AWS::S3::BucketPolicy resources’ Properties.PolicyDocument.Statement entries. Ensure no statement has Effect: "Allow" with Principal: "*" (or including *) while Action includes list operations such as s3:ListBucket. Resources missing the policy document, or containing statements that allow list actions to wildcard principals, will be flagged. Restrict listing permissions to specific AWS account IDs, IAM roles, or ARNs, or remove list permissions for public principals.
Secure example restricting list actions to a specific principal:
#this code is a correct code for which the query should not find any resultResources:SampleBucketPolicy1:Type:'AWS::S3::BucketPolicy'Properties:Bucket:!Ref DOC-EXAMPLE-BUCKETPolicyDocument:Statement:- Action:- 's3:ListObject'Effect:DenyResource:'*'Principal:'*'Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'
#this is a problematic code where the query should report a result(s)Resources:SampleBucketPolicy3:Type:'AWS::S3::BucketPolicy'Properties:Bucket:!Ref DOC-EXAMPLE-BUCKETPolicyDocument:Statement:- Action:"ListObject"Effect:AllowResource:"*"Principal:"*"Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'SampleBucketPolicy4:Type:'AWS::S3::BucketPolicy'Properties:Bucket:!Ref DOC-EXAMPLE-BUCKETPolicyDocument:Statement:- Action:- "ListObject"- "GetObject"Effect:AllowResource:"*"Principal:"*"Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'