rest: Validate the region before building the endpoint host name
When no explicit host name is configured, the endpoint is assembled as “service.region.$suffix” into a fixed 256-byte buffer and then used as the TLS server name for certificate validation and as the HTTP host header. In the enclave the region comes from the untrusted parent (the “AwsRegion” field of the SetupClient message) and s_read_region() only checks that it is a JSON string, imposing no length or character limit.
Dots on their own are not enough to matter: a region of “evil.com” yields “kms.evil.com.amazonaws.com”, which is still under a suffix only AWS can answer for. Length is what turns this into a takeover. A 251-character region needs 269 bytes, so the assembled name is truncated to 255 and the “.amazonaws.com” tail is dropped completely, leaving a name that ends in a domain the parent owns and can present a valid certificate for.
Reject the region unless it matches the AWS region grammar ([a-z0-9-], 1..32 chars). The charset already excludes dots, uppercase and any other delimiter, so length is the only remaining lever; capping it removes the truncation primitive at the source.
Why 32: “service” is the fixed literal “kms” (3 chars) and the longest DNS suffix is “amazonaws.com.cn” (16). The longest region in any partition today is “us-isof-south-1” (15), so 32 accepts every real region with room for longer future ones without another code change. It is also, on its own, provably far from the buffer limit: worst case is 3 + 1 + 32 + 1 + 16 = 53 characters plus a NUL = 54, against a 256-byte buffer (202 bytes of headroom). A 32-character region therefore cannot truncate regardless of the snprintf guard below.
Keep a check on the snprintf result as well: with the length cap in place this guard is unreachable, but the limit (here) and the buffer size (a separate declaration) could drift apart in a later change, so treat snprintf returning >= sizeof(host_name_str) as a hard error rather than relying on the two staying in agreement. Defense in depth, not the primary control.
Signed-off-by: Marius Knaust mknaust@amazon.com
版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9
京公网安备 11010802047560号
AWS Nitro Enclaves SDK for C
License
This project is licensed under the Apache-2.0 License.
Dependencies
Building
Linux - Using containers:
The simplest way to use this SDK is by using one of the available containers as a base:
Windows
Note that this SDK is currently not supported on Windows. Only the client side sample application (kmstool_instance) is supported on Windows.
Samples
Security issue notifications
If you discover a potential security issue in the Nitro Enclaves SDK for C, we ask that you notify AWS Security via our vulnerability reporting page. Please do not create a public GitHub issue.