Skip to content

Commit a9547e6

Browse files
committed
fix(elbv2): boolean ALB attributes not reflected in CloudFormation when set to false
When boolean ALB properties like dropInvalidHeaderFields, preserveHostHeader, xAmznTlsVersionAndCipherSuiteHeaders, preserveXffClientPort, and wafFailOpen were explicitly set to false, they were omitted from the CloudFormation template because the code used truthy checks (if (props.x)) instead of undefined checks (if (props.x !== undefined)). This meant changing these properties from true to false would not update the ALB configuration. Now all boolean ALB attributes use !== undefined checks and emit both 'true' and 'false' values, consistent with how http2Enabled was already handled. Closes #36409
1 parent 08b9280 commit a9547e6

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

packages/aws-cdk-lib/aws-elasticloadbalancingv2/lib/alb/application-load-balancer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -228,13 +228,13 @@ export class ApplicationLoadBalancer extends BaseLoadBalancer implements IApplic
228228

229229
if (props.http2Enabled !== undefined) { this.setAttribute('routing.http2.enabled', props.http2Enabled ? 'true' : 'false'); }
230230
if (props.idleTimeout !== undefined) { this.setAttribute('idle_timeout.timeout_seconds', props.idleTimeout.toSeconds().toString()); }
231-
if (props.dropInvalidHeaderFields) { this.setAttribute('routing.http.drop_invalid_header_fields.enabled', 'true'); }
231+
if (props.dropInvalidHeaderFields !== undefined) { this.setAttribute('routing.http.drop_invalid_header_fields.enabled', props.dropInvalidHeaderFields ? 'true' : 'false'); }
232232
if (props.desyncMitigationMode !== undefined) { this.setAttribute('routing.http.desync_mitigation_mode', props.desyncMitigationMode); }
233-
if (props.preserveHostHeader) { this.setAttribute('routing.http.preserve_host_header.enabled', 'true'); }
234-
if (props.xAmznTlsVersionAndCipherSuiteHeaders) { this.setAttribute('routing.http.x_amzn_tls_version_and_cipher_suite.enabled', 'true'); }
235-
if (props.preserveXffClientPort) { this.setAttribute('routing.http.xff_client_port.enabled', 'true'); }
233+
if (props.preserveHostHeader !== undefined) { this.setAttribute('routing.http.preserve_host_header.enabled', props.preserveHostHeader ? 'true' : 'false'); }
234+
if (props.xAmznTlsVersionAndCipherSuiteHeaders !== undefined) { this.setAttribute('routing.http.x_amzn_tls_version_and_cipher_suite.enabled', props.xAmznTlsVersionAndCipherSuiteHeaders ? 'true' : 'false'); }
235+
if (props.preserveXffClientPort !== undefined) { this.setAttribute('routing.http.xff_client_port.enabled', props.preserveXffClientPort ? 'true' : 'false'); }
236236
if (props.xffHeaderProcessingMode !== undefined) { this.setAttribute('routing.http.xff_header_processing.mode', props.xffHeaderProcessingMode); }
237-
if (props.wafFailOpen) { this.setAttribute('waf.fail_open.enabled', 'true'); }
237+
if (props.wafFailOpen !== undefined) { this.setAttribute('waf.fail_open.enabled', props.wafFailOpen ? 'true' : 'false'); }
238238
if (props.clientKeepAlive !== undefined) {
239239
const clientKeepAliveInMillis = props.clientKeepAlive.toMilliseconds();
240240
if (clientKeepAliveInMillis < 1000) {

packages/aws-cdk-lib/aws-elasticloadbalancingv2/test/alb/load-balancer.test.ts

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,48 @@ describe('tests', () => {
173173
});
174174
});
175175

176+
test('Boolean attributes explicitly set to false are included in CloudFormation', () => {
177+
// GIVEN
178+
const stack = new cdk.Stack();
179+
const vpc = new ec2.Vpc(stack, 'Stack');
180+
181+
// WHEN
182+
new elbv2.ApplicationLoadBalancer(stack, 'LB', {
183+
vpc,
184+
dropInvalidHeaderFields: false,
185+
preserveHostHeader: false,
186+
xAmznTlsVersionAndCipherSuiteHeaders: false,
187+
preserveXffClientPort: false,
188+
wafFailOpen: false,
189+
});
190+
191+
// THEN
192+
Template.fromStack(stack).hasResourceProperties('AWS::ElasticLoadBalancingV2::LoadBalancer', {
193+
LoadBalancerAttributes: Match.arrayWith([
194+
{
195+
Key: 'routing.http.drop_invalid_header_fields.enabled',
196+
Value: 'false',
197+
},
198+
{
199+
Key: 'routing.http.preserve_host_header.enabled',
200+
Value: 'false',
201+
},
202+
{
203+
Key: 'routing.http.x_amzn_tls_version_and_cipher_suite.enabled',
204+
Value: 'false',
205+
},
206+
{
207+
Key: 'routing.http.xff_client_port.enabled',
208+
Value: 'false',
209+
},
210+
{
211+
Key: 'waf.fail_open.enabled',
212+
Value: 'false',
213+
},
214+
]),
215+
});
216+
});
217+
176218
test.each([59, 604801])('throw error for invalid clientKeepAlive in seconds', (duration) => {
177219
// GIVEN
178220
const stack = new cdk.Stack();

0 commit comments

Comments
 (0)