This vulnerability in the Hono framework's Lambda@Edge adapter arises from incorrect handling of repeated HTTP request headers. On AWS Lambda@Edge, CloudFront can pass a single header with multiple values as a series of separate, repeated headers. The vulnerable adapter code iterated through these repeated headers but used headers.set(key, value) for each one. The set method overwrites any existing value for that header key. As a result, only the very last value in the series was preserved and passed to the application, while all preceding values were discarded.
This behavior leads to a loss of information for headers that rely on a complete chain of values, such as X-Forwarded-For, Forwarded, and Via. Security middleware that inspects these headers for tasks like IP-based access control or audit logging would operate on incomplete data. For instance, an IP restriction based on the X-Forwarded-For chain could be bypassed if the client can control the last value in the chain, as the preceding, more trusted values added by proxies would be dropped.
The fix involves changing the logic to use headers.append(key, value) instead of headers.set(key, value). The append method correctly adds the new value to the header, preserving the full list of values for repeated headers. This ensures that the application and any middleware receive the complete and accurate header information, mitigating the risk of security bypasses and data loss.
The vulnerable function, handle, is the entry point for processing incoming requests in the Lambda@Edge adapter. It is responsible for constructing the Request object, including its headers, before passing it to the Hono application for processing. The flaw in this function directly leads to the security vulnerability.