# CVE-2021-40829: TLS hostname validation issues within AWS IoT Device SDKs on macOS

> AWS IoT Device SDKs on macOS fail to validate TLS hostnames when custom CAs are used, allowing man-in-the-middle attacks.

- **Severity:** Medium 6.3 (`CVSS:3.1/AV:A/AC:H/PR:H/UI:R/S:U/C:H/I:H/A:H`)
- **Exploited in the wild:** Not known
- **Login needed:** An administrator
- **Attackable:** Local or same network only
- **Victim action needed:** A user has to click or open something
- **Fix available:** Yes
- **Published:** 22 Nov 2021
- **Updated:** 4 Aug 2024
- **Also known as:** GHSA-743r-5g92-5vgf, PYSEC-2021-862

## What is CVE-2021-40829?

CVE-2021-40829 is a medium-severity vulnerability in Amazon Web Services AWS IoT Device SDK v2 for C++, published on 22 Nov 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.

### Official description

Connections initialized by the AWS IoT Device SDK v2 for Java (versions prior to 1.4.2), Python (versions prior to 1.6.1), C++ (versions prior to 1.12.7) and Node.js (versions prior to 1.5.3) did not verify server certificate hostname during TLS handshake when overriding Certificate Authorities (CA) in their trust stores on MacOS. This issue has been addressed in aws-c-io submodule versions 0.10.5 onward. This issue affects: Amazon Web Services AWS IoT Device SDK v2 for Java versions prior to 1.4.2 on macOS. Amazon Web Services AWS IoT Device SDK v2 for Python versions prior to 1.6.1 on macOS. Amazon Web Services AWS IoT Device SDK v2 for C++ versions prior to 1.12.7 on macOS. Amazon Web Services AWS IoT Device SDK v2 for Node.js versions prior to 1.5.3 on macOS. Amazon Web Services AWS-C-IO 0.10.4 on macOS.

Weakness: CWE-295 (Improper Certificate Validation)

## Which versions are affected by CVE-2021-40829?

7 open source packages ship an affected version, including software.amazon.awssdk.iotdevicesdk:aws-iot-device-sdk, awsiotsdk and aws-iot-device-sdk-v2. It affects 1 product.


| Package | Ecosystem | Affected | Fixed in |
| --- | --- | --- | --- |
| `software.amazon.awssdk.iotdevicesdk:aws-iot-device-sdk` | Maven | All versions | 1.4.2 |
| `software.amazon.awssdk.iotdevicesdk:aws-iot-device-sdk` | Maven | All versions | 1.4.2 |
| `awsiotsdk` | PyPI | All versions | 1.6.1 |
| `awsiotsdk` | PyPI | All versions | 1.6.1 |
| `awsiotsdk` | PyPI | All versions | 1.6.1 |
| `aws-iot-device-sdk-v2` | npm | All versions | 1.5.3 |
| `aws-iot-device-sdk-v2` | npm | All versions | 1.5.3 |

Products: Amazon Amazon Web Services Internet of Things Device Software Development Kit V2.

## How do I fix CVE-2021-40829?

Upgrade software.amazon.awssdk.iotdevicesdk:aws-iot-device-sdk to 1.4.2 or later.

## Is CVE-2021-40829 being exploited?

There is no known exploitation of CVE-2021-40829 in the wild and no public exploit code.

## Fix prompt for AI coding agents

```text
Check this codebase for CVE-2021-40829 and fix it if it is affected.

What it is: CVE-2021-40829 is a medium-severity vulnerability in Amazon Web Services AWS IoT Device SDK v2 for C++, published on 22 Nov 2021. It can only be exploited from the same machine or local network, and only if a user opens a file or follows a link.
Exploitation: There is no known exploitation of CVE-2021-40829 in the wild and no public exploit code.

Affected packages and fixed versions:
- software.amazon.awssdk.iotdevicesdk:aws-iot-device-sdk (Maven): affected all versions; fixed in 1.4.2
- software.amazon.awssdk.iotdevicesdk:aws-iot-device-sdk (Maven): affected all versions; fixed in 1.4.2
- awsiotsdk (PyPI): affected all versions; fixed in 1.6.1
- awsiotsdk (PyPI): affected all versions; fixed in 1.6.1
- awsiotsdk (PyPI): affected all versions; fixed in 1.6.1
- aws-iot-device-sdk-v2 (npm): affected all versions; fixed in 1.5.3
- aws-iot-device-sdk-v2 (npm): affected all versions; fixed in 1.5.3

Task:
1. Search the dependency manifests and lockfiles (for example package.json, package-lock.json, requirements.txt, poetry.lock, uv.lock, pom.xml, build.gradle, go.mod, Cargo.lock, Gemfile.lock) and any Dockerfiles for the affected packages, including transitive dependencies.
2. If an affected version is in use, upgrade it to the fixed version for its release line with the project's package manager, so the lockfile is regenerated. Prefer the smallest upgrade that fixes it.
3. If there is no fix, or the upgrade would break the build, do not guess: explain the risk and the safest workaround instead.
4. Run the tests and summarise what changed and why.
5. If nothing in the project is affected, say so and change nothing.

Reference: https://insights.sbomify.com/CVE-2021-40829/ (Markdown: https://insights.sbomify.com/CVE-2021-40829/index.md)
```

## Sources

- CVE record: https://www.cve.org/CVERecord?id=CVE-2021-40829
- NVD: https://nvd.nist.gov/vuln/detail/CVE-2021-40829
- OSV: https://osv.dev/vulnerability/CVE-2021-40829

---
From sbomify Insights: https://insights.sbomify.com/CVE-2021-40829/
Summaries are generated and may contain mistakes; the official description above is the record.
