Are you looking to enhance the security of your web applications while optimizing their performance to ensure a smooth user experience and protect against cyber threats? AWS Application Load Balancers (ALBs) offer robust features for modifying request and response headers, which allows you to tailor your application’s behavior in various ways. By reinforcing security with crucial headers like Content Security Policy and HTTP Strict Transport Security, as well as boosting performance through effective caching strategies and resource delivery, ALBs provide a flexible toolkit for developers and system administrators. Whether you aim to meet industry standards, integrate with API gateways, or apply custom logic, mastering header modifications can significantly enhance your application’s resilience and efficiency. In this post, we delve into a few of these functionalities and demonstrate how you can leverage ALB header modifications to elevate your web applications on AWS.
Renaming TLS Headers
One of the most frequently requested features is header renaming. Legacy systems often expect headers in specific formats; for instance, they might require the header to be “Custom-TLS” instead of “X-Amzn-TLS.” By renaming ALB-generated headers like X-Amzn-mTLS and X-Amzn-TLS, users can ensure compatibility with their legacy application code. This flexibility simplifies the use of ALB’s features without complicating workflows. Notably, this capability facilitates seamless integration with existing applications, allowing the ALB to adapt to specific organizational needs without altering application code or backend services. For example:
aws elbv2 modify-listener-attributes
--listener-arn <ARN> --attributes
Key=[Headers From renaming headers section].header_name
Value="desired_header_field_name"
Renaming the ALB-generated mTLS and TLS header fields, rather than the values, empowers users to utilize header names that align with their existing TLS-related application code. This renaming can be accomplished via a listener attribute API call or through the AWS console.
HTTP Strict-Transport-Security and Cross-Origin Resource Sharing
Another commonly requested feature is the ability to insert headers such as HTTP Strict-Transport-Security (HSTS) and Cross-Origin Resource Sharing (CORS) at the ALB level. This functionality allows ALB users to address vital security and compliance requirements. HSTS header insertion enhances security by enforcing HTTPS across all client connections, shielding against man-in-the-middle attacks, and ensuring compliance with industry regulations like PCI DSS and HIPAA. A key advantage of this feature is that ALB users can meet security standards without modifying the underlying application code. Similarly, inserting CORS headers facilitates secure cross-origin resource sharing, enabling controlled access between different domains within modern web applications. This streamlines cross-origin policy management across multiple services, ensuring that only authorized credentials can access sensitive resources.
To insert security or CORS headers for cross-origin compliance, use the following command:
aws elbv2 modify-listener-attributes
--listener-arn <ARN> --attributes
Key=routing.http.response."Headers From insert headers section".header_name
Value="desired_value"
Server Header Management
Another critical security function is the ability to disable the server header, which is essential for organizations with stringent security and privacy policies mandated by PCI DSS. Disabling this header prevents the inadvertent exposure of server information. The ALB’s header modification feature allows users to disable the “Server” header in responses, minimizing the risk of exposing server-specific details that could be exploited by automated scanning tools or attackers. Centralized management at the ALB level enables organizations to consistently apply security standards across applications, thereby streamlining security operations.
This configuration can prevent server info exposure such as “awselb/2.0” in responses, adding an extra layer of security:
aws elbv2 modify-listener-attributes
--listener-arn <ARN> --attributes
Key=routing.http.response.server.enabled
Value="true|false"
ALB only includes the server header information with the value as awselb/2.0 when the target response does not contain a server header. With this feature, users can configure ALB to omit the server header information from the response. If the target response already includes a server header, it will still be proxied to the client.
Solution Overview
To enable these features at scale, you can implement a solution that queries ALBs in a specific AWS Region based on the provided tag, modifying the headers of your choice for all ALBs with that tag. This solution deploys an AWS Lambda function to modify ALB headers efficiently. The solution can be executed multiple times by adjusting the environment variables associated with Lambda.
Solution Deployment
You can deploy this solution into your AWS account using an AWS CloudFormation template.
Prerequisites
Leave a Reply