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-put-actions-from-all-principals.md.
A documentation index is available at /llms.txt.
Bucket policies that allow S3 Put actions from the wildcard principal (*) enable anyone on the internet to upload or overwrite objects in the bucket. This can lead to unauthorized data tampering, malware uploads, or public exposure of sensitive content.
Check AWS::S3::BucketPolicy resources’ Properties.PolicyDocument.Statement entries and flag statements where Effect: "Allow", Principal: "*", and Action includes Put operations such as s3:PutObject (or other s3:Put* actions). Principal should specify explicit principals (AWS account IDs, IAM role/user ARNs, or canonical user IDs). If Principal is *, the statement must include strict conditions (for example, SourceIp or VpcEndpoint) that effectively prevent public uploads. Statements with Principal: "*" and unrestrained Put actions will be flagged.
Secure configuration example allowing Put only to a specific role:
#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:PutObject'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:"PutObject"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:- "PutObject"- "GetObject"Effect:AllowResource:"*"Principal:"*"Condition:StringLike:'aws:Referer':- 'http://www.example.com/*'- 'http://example.net/*'