Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(sast): Add TS CDK policies 1 #6151

Merged
merged 26 commits into from
Apr 10, 2024
Merged
17 changes: 17 additions & 0 deletions cdk_integration_tests/src/typescript/ALBDropHttpHeaders/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class ALBDropHttpHeadersStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnLoadBalancer(this, { type: 'not_application', loadBalancerAttributes: [{'key': 'routing.http.drop_invalid_header_fields.enabled', 'value': 'true'}] })
new elbv2.CfnLoadBalancer(this, { type: 'application', loadBalancerAttributes: [{'value': 'false', 'key': 'routing.http.drop_invalid_header_fields.enabled'}] })
new elbv2.CfnLoadBalancer(this, { loadBalancerAttributes: [{'key': 'routing.http.drop_invalid_header_fields.disable', 'value': 'true'}], type: 'application' })
new elbv2.CfnLoadBalancer(this, { loadBalancerAttributes: [], type: 'application' })
}
}

const app = new App();
new ALBDropHttpHeadersStack(app, 'ALBDropHttpHeadersStack');
17 changes: 17 additions & 0 deletions cdk_integration_tests/src/typescript/ALBDropHttpHeaders/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class ALBDropHttpHeadersStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnLoadBalancer(this, { type: 'application', loadBalancerAttributes: [{'key': 'routing.http.drop_invalid_header_fields.enabled', 'value': 'true'}] })
new elbv2.CfnLoadBalancer(this, { type: 'application', loadBalancerAttributes: [{'value': 'true', 'key': 'routing.http.drop_invalid_header_fields.enabled'}] })
new elbv2.CfnLoadBalancer(this, { loadBalancerAttributes: [{'key': 'routing.http.drop_invalid_header_fields.enabled', 'value': 'true'}], type: 'application' })
new elbv2.CfnLoadBalancer(this, { loadBalancerAttributes: [{'value': 'true', 'key': 'routing.http.drop_invalid_header_fields.enabled'}], type: 'application' })
}
}

const app = new App();
new ALBDropHttpHeadersStack(app, 'ALBDropHttpHeadersStack');
14 changes: 14 additions & 0 deletions cdk_integration_tests/src/typescript/ALBListenerHTTPS/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class ALBListenerHTTPSStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnLoadBalancer(this, {})
}
}

const app = new App();
new ALBListenerHTTPSStack(app, 'ALBListenerHTTPSStack');
19 changes: 19 additions & 0 deletions cdk_integration_tests/src/typescript/ALBListenerHTTPS/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class ALBListenerHTTPSStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnLoadBalancer(this, {protocol: 'HTTPS'})
new elbv2.CfnLoadBalancer(this, {protocol: 'TLS'})
new elbv2.CfnLoadBalancer(this, {protocol: 'TCP'})
new elbv2.CfnLoadBalancer(this, {protocol: 'UDP'})
new elbv2.CfnLoadBalancer(this, {protocol: 'TCP_UDP'})
new elbv2.CfnLoadBalancer(this, {defaultActions: [{type: 'redirect', redirectConfig:{protocol: 'HTTPS'}}]})
}
}

const app = new App();
new ALBListenerHTTPSStack(app, 'ALBListenerHTTPSStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { apigateway as api } from 'aws-cdk-lib';

class APIGatewayAccessLoggingStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new api.CfnStage(this, {})
}
}

const app = new App();
new APIGatewayAccessLoggingStack(app, 'APIGatewayAccessLoggingStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { apigateway as api } from 'aws-cdk-lib';

class APIGatewayAccessLoggingStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new api.CfnStage(this, { accessLogSetting: { destinationArn: "1" }} )
}
}

const app = new App();
new APIGatewayAccessLoggingStack(app, 'APIGatewayAccessLoggingStack');
14 changes: 14 additions & 0 deletions cdk_integration_tests/src/typescript/APIGatewayCacheEnable/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class APIGatewayCacheEnableStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.Stage(this, {})
}
}

const app = new App();
new APIGatewayCacheEnableStack(app, 'APIGatewayCacheEnableStack');
13 changes: 13 additions & 0 deletions cdk_integration_tests/src/typescript/APIGatewayCacheEnable/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class APIGatewayCacheEnableStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);
new elbv2.Stage(this, { cacheClusterEnabled: true} )
}
}

const app = new App();
new APIGatewayCacheEnableStack(app, 'APIGatewayCacheEnableStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class APIGatewayV2AccessLoggingStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnApi(this, {})
}
}

const app = new App();
new APIGatewayV2AccessLoggingStack(app, 'APIGatewayV2AccessLoggingStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class APIGatewayV2AccessLoggingStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnApi(this, {accessLogSettings: {destinationArn: "1"}})
}
}

const app = new App();
new APIGatewayV2AccessLoggingStack(app, 'APIGatewayV2AccessLoggingStack');
15 changes: 15 additions & 0 deletions cdk_integration_tests/src/typescript/APIGatewayXray/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class APIGatewayXrayStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnStage(this, {})
new elbv2.CfnStage(this, {tracingEnabled: false})
}
}

const app = new App();
new APIGatewayXrayStack(app, 'APIGatewayXrayStack');
14 changes: 14 additions & 0 deletions cdk_integration_tests/src/typescript/APIGatewayXray/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class APIGatewayXrayStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnStage(this, {tracingEnabled: true})
}
}

const app = new App();
new APIGatewayXrayStack(app, 'APIGatewayXrayStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class AmazonMQBrokerPublicAccessStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnBroker(this, {})
new elbv2.CfnBroker(this, {publiclyAccessible: false})
}
}

const app = new App();
new AmazonMQBrokerPublicAccessStack(app, 'AmazonMQBrokerPublicAccessStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class AmazonMQBrokerPublicAccessStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnBroker(this, {publiclyAccessible: true})
}
}

const app = new App();
new AmazonMQBrokerPublicAccessStack(app, 'AmazonMQBrokerPublicAccessStack');
15 changes: 15 additions & 0 deletions cdk_integration_tests/src/typescript/AuroraEncryption/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class AuroraEncryptionStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnDBCluster(this, {})
new elbv2.CfnDBCluster(this, {storageEncrypted: false})
}
}

const app = new App();
new AuroraEncryptionStack(app, 'AuroraEncryptionStack');
14 changes: 14 additions & 0 deletions cdk_integration_tests/src/typescript/AuroraEncryption/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class AuroraEncryptionStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnDBCluster(this, {storageEncrypted: true})
}
}

const app = new App();
new AuroraEncryptionStack(app, 'AuroraEncryptionStack');
15 changes: 15 additions & 0 deletions cdk_integration_tests/src/typescript/BackupVaultEncrypted/fail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class BackupVaultEncryptedStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnBackupVault(this, {})
new elbv2.CfnBackupVault(this, {encryptionKeyArn: false})
}
}

const app = new App();
new BackupVaultEncryptedStack(app, 'BackupVaultEncryptedStack');
14 changes: 14 additions & 0 deletions cdk_integration_tests/src/typescript/BackupVaultEncrypted/pass.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class BackupVaultEncryptedStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnBackupVault(this, {encryptionKeyArn: true})
}
}

const app = new App();
new BackupVaultEncryptedStack(app, 'BackupVaultEncryptedStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class CloudTrailLogValidationStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnTrail(this, {})
new elbv2.CfnTrail(this, {enableLogFileValidation: false})
}
}

const app = new App();
new CloudTrailLogValidationStack(app, 'CloudTrailLogValidationStack');
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { App, Stack, StackProps } from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_elasticloadbalancingv2 as elbv2 } from 'aws-cdk-lib';

class CloudTrailLogValidationStack extends Stack {
constructor(scope: Construct, id: string, props?: StackProps) {
super(scope, id, props);

new elbv2.CfnTrail(this, {enableLogFileValidation: true})
}
}

const app = new App();
new CloudTrailLogValidationStack(app, 'CloudTrailLogValidationStack');