T09 · Insecure Skill Coding Practices
- Location
scripts/unifi-api.sh:22- Finding
TLS Certificate Verification Is Disabled for Authenticated UniFi Requests
- Content
View full analysis
Vulnerability Details
File Location:
scripts/unifi-api.sh:22-28
Vulnerability Type: Improper certificate validation
Risk Level: HighVulnerable Code
bash unifi_request() { local path="$1" curl -sk \ -H "X-API-KEY: $UNIFI_TOKEN" \ -H "Accept: application/json" \ "$UNIFI_URL$path" }The same insecure
curl -skpattern also occurs in:scripts/clients.sh:11-19scripts/devices.sh:10-18scripts/health.sh:11-15scripts/sites.sh:10-13
Technical Analysis
The
-koption instructscurlto skip TLS certificate verification. These requests include the sensitive UniFi API key in theX-API-KEYheader. Encryption alone does not establish server identity when certificate validation is disabled.An attacker with a network interception position could present an arbitrary certificate, impersonate the configured UniFi gateway, and receive the API key. The attacker could also forge API responses, causing the Skill to report false device, client, alarm, or health information.
Although self-signed certificates are common on local UniFi gateways, globally disabling verification is not the minimum-risk solution. The gateway certificate or a private certificate authority should instead be explicitly trusted.
Attack Path
- A user configures a legitimate HTTPS UniFi gateway URL and invokes one of the monitoring scripts.
- An attacker obtains a traffic-interception position, such as through a compromised router, malicious wireless network, ARP spoofing, or DNS manipulation.
- The attacker redirects the gateway connection to an attacker-controlled HTTPS service.
- The attacker presents an untrusted certificate.
- Because
curl -ksuppresses certificate verification, the script accepts the certificate. - The script sends
X-API-KEY: $UNIFI_TOKENto the attacker-controlled service. - The attacker captures and reuses the key or returns forged monitoring data.
Impact Assessment
The attacker can obt ...[truncated 487 chars]
- Remediation
View remediation
Remediation Suggestions
- Remove
-kfrom allcurlinvocations and enable normal certificate verification by default. - Support a configured CA or pinned gateway certificate, for example:
bash curl --fail-with-body --silent --show-error \ --cacert "$UNIFI_CA_FILE" \ -H "X-API-KEY: $UNIFI_TOKEN" \ -H "Accept: application/json" \ "$UNIFI_URL$path"- For self-signed gateways, document how to export the gateway certificate and configure
UNIFI_CA_FILE. - If insecure TLS must be supported for compatibility, require an explicit option such as
UNIFI_INSECURE_TLS=1, keep secure verification as the default, and print a prominent warning. - Centralize all requests through
unifi_requestso thatclients.sh,devices.sh,health.sh, andsites.shcannot independently reintroduce unsafe TLS options. - Add
--fail-with-body, connection and total timeouts, and an HTTPS scheme check. - Rotate any API key that may previously have traversed an untrusted network while certificate validation was disabled.
- Remove
