T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/unifi-api.sh:40
- Finding
- TLS Certificate Verification Is Disabled for Authentication and API Requests<![CDATA[ ## Vulnerability Details **File Location**: `scripts/unifi-api.sh:40-44`, `scripts/unifi-api.sh:77` **Vulnerability Type**: Insecure TLS configuration **Risk Level**: High ### Vulnerable Code ```bash curl -sk -c "$cookie_file" \ -H "Content-Type: application/json" \ -X POST \ "$UNIFI_URL/api/auth/login" \ --data "$payload" >/dev/null ``` ```bash curl -sk -b "$UNIFI_COOKIE_FILE" "$full_url" ``` ### Technical Analysis The `-k` option instructs curl to accept an HTTPS server without validating its certificate. It is used for both the login request and every authenticated API request. Although traffic remains encrypted, the client does not verify that it is communicating with the intended UniFi gateway. An attacker with a suitable local network interception position can present an arbitrary certificate and impersonate the gateway. The login request transmits the configured username and password in its JSON body, while subsequent requests transmit the authenticated session cookie. The behavior is documented in `README.md:94-96`, but documentation does not mitigate the underlying loss of server authentication. ### Attack Path 1. The attacker gains a position capable of influencing local traffic, such as control over Wi-Fi, DNS, ARP resolution, routing, or another device on the local network. 2. The attacker redirects traffic intended for the configured UniFi host to a malicious HTTPS server. 3. The malicious server presents an untrusted or attacker-generated certificate. 4. Because curl is invoked with `-k`, the client accepts the certificate without warning. 5. During `/api/auth/login`, the attacker receives the configured username and password. 6. The attacker can attempt to authenticate to the real gateway using the captured credentials or return falsified API responses to the monitoring scripts. 7. Authenticated session cookies may also be captured from subsequent requests. ### Impact Assessment Successful exploitation can disclose t ...[truncated 449 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `-k` from login and API requests so certificate verification is enabled by default. 2. Support a user-configured trusted CA bundle: ```bash curl --fail-with-body --silent --show-error \ --cacert "$UNIFI_CA_FILE" \ -c "$cookie_file" \ -H "Content-Type: application/json" \ -X POST \ "$UNIFI_URL/api/auth/login" \ --data "$payload" ``` 3. Alternatively, support certificate or public-key pinning with curl’s `--pinnedpubkey` option. 4. Provide instructions for exporting and trusting the gateway certificate or the local CA that issued it. 5. If insecure TLS must remain available for legacy deployments, require an explicit setting such as `UNIFI_INSECURE_TLS=true`, keep secure verification as the default, and print a prominent warning. 6. Use `--fail-with-body --silent --show-error` and verify both HTTP status and expected API response fields. 7. Require a dedicated read-only UniFi account so credential compromise cannot grant administrative configuration privileges. ]]>
