Skip to content

[BUG] Regression: Cannot connect to Azure China IoT Hub (.azure-devices.cn) due to hostname validation #728

@apciala

Description

@apciala

Describe the bug

Azure IoT Explorer v0.15.15+ rejects connection strings for Azure China (21Vianet) IoT Hubs that use the .azure-devices.cn domain
suffix. This is a regression — Azure China IoT Hubs worked in versions prior to v0.15.14 (before PR #720).

Error message:
Failed to retrieve device list: Invalid hostname: must be a valid Azure IoT Hub endpoint (*.azure-devices.net)

Connection string format:
HostName=.azure-devices.cn;SharedAccessKeyName=iothubowner;SharedAccessKey=

Root cause:

PR #720 (Security enhancements: Replace HTTP server with secure IPC) introduced strict hostname validation in
public/handlers/urlValidator.ts. The validation function validateAzureIoTHostname() hardcodes only .azure-devices.net as the
allowed domain suffix:

const ALLOWED_DOMAIN_SUFFIX = '.azure-devices.net';

This blocks all Azure China (21Vianet) IoT Hubs, which use .azure-devices.cn as their domain suffix, as documented here:
https://learn.microsoft.com/en-us/azure/iot-hub/iot-hub-devguide-endpoints

To Reproduce
1. Open Azure IoT Explorer v0.15.15 or v0.15.16
2. Click "Add connection"
3. Paste a connection string with .azure-devices.cn hostname
4. See error: "Invalid hostname: must be a valid Azure IoT Hub endpoint (*.azure-devices.net)"

Expected behavior
Azure IoT Explorer should support both:
- Global Azure: *.azure-devices.net
- Azure China (21Vianet): *.azure-devices.cn

Suggested fix

Update ALLOWED_DOMAIN_SUFFIX in public/handlers/urlValidator.ts to also accept .azure-devices.cn, or refactor to use an array of allowed
suffixes:

const ALLOWED_DOMAIN_SUFFIXES = ['.azure-devices.net', '.azure-devices.cn'];

Desktop:
- OS: Windows 11
- App version: 0.15.15 (also confirmed in 0.15.16)

Additional context
- Related PR that introduced the regression: #720
- Related PR #726 updated EventHub validation but did not address IoT Hub hostname validation
- Issue #453 previously reported Azure China connectivity (2021) but that was a different error  the hostname validation did not exist
at that time

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions