Skip to content

CDK custom resource CustomCDKBucketDeployment: SecurityHub HIGH notification: CWE-117,93 - Log injection #30211

@Rick-Ernsting

Description

@Rick-Ernsting

Describe the bug

In SecurityHub we get a HIGH severity notification CWE-117
,93-Log injection, with message:

User-provided inputs must be sanitized before they are logged. An attacker can use unsanitized input to break a log's integrity, forge log entries, or bypass log monitors.

We get this notification when the CDK custom resource CustomCDKBucketDeployment is deployed by CDK. Can you update the Lambda Python code so we don't get this notification anymore? Inspector notifies about these lines starting at line 103 in the Lambda Python code:

    logger.info("| s3_dest: %s" % s3_dest)
    logger.info("| old_s3_dest: %s" % old_s3_dest)

Inspector suggests this solution:

   logger.info("| s3_dest: %s" % urllib.parse.quote(s3_dest))

Expected Behavior

That we get no SecurityHub notification

Current Behavior

When I specify this:

new s3deploy.BucketDeployment(...)

Then a Custom resource with CustomCDKBucketDeployment Lambda is created. After that Inspector creates a HIGH severity notification: CWE-117,93 - Log injection

Reproduction Steps

const testBucket = new Bucket(this,'TestBucket',{
      bucketName: "test-bucket-test",
      enforceSSL: true,
      removalPolicy: cdk.RemovalPolicy.DESTROY,
      autoDeleteObjects: true
})

new s3deploy.BucketDeployment(this,'CopyFilesFromLocalToBucket', {
      sources: [
         s3deploy.Source.data('tree.json', fs.readFileSync(path.join(__dirname + '/../cdk.out/tree.json'), 'utf-8') )
      ],
      destinationBucket: testBucket
})

Possible Solution

Inspector notifies about these lines starting at line 103 in the Lambda code:

    logger.info("| s3_dest: %s" % s3_dest)
    logger.info("| old_s3_dest: %s" % old_s3_dest)

Inspector suggests this solution:

   logger.info("| s3_dest: %s" % urllib.parse.quote(s3_dest))

It is possible there is a better solution.

Additional Information/Context

No response

CDK CLI Version

2.141.0

Framework Version

No response

Node.js Version

18.19.1

OS

Windows

Language

TypeScript

Language Version

5.2.2

Other information

No response

Metadata

Metadata

Assignees

Labels

@aws-cdk/aws-securityhubRelated to AWS Security HubbugThis issue is a bug.effort/smallSmall work item – less than a day of effortp2

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions