All Products
Search
Document Center

HTTPDNS:Implement authenticated access

Last Updated:Dec 16, 2025

1. Background

To protect your billing against potential fraudulent activities, we have designed an authentication mechanism. Follow the instructions in this document to implement this mechanism.

2. Authentication solution

Some existing users have products that access HTTPDNS without authentication. These products must continue to use the non-authenticated API operations.

To accommodate this, we provide a new authenticated API operation. You can gradually migrate new product versions to this new API operation. When the number of users on the old app version decreases to a certain level, you can turn on the signed access switch to prevent adverse impacts on your billing. The following figures illustrate this process.

image

2.1 Migration plan for existing users

  • If you turn on the signed access switch, users of older product versions cannot access the HTTPDNS service.

  • You can guide existing users to update their product versions and gradually migrate to the authenticated API operation.

  • When the number of users for products that use the non-authenticated API operation drops to an acceptable level, you can manually turn on the signed access switch.

2.2 Plan for new users

  • To avoid the additional integration cost of authentication, the signed access switch is turned off by default.

  • If you only need the authenticated API operation, you can manually turn on the signed access switch.

2.3 Management of the signed access switch

  • If the switch is turned off, security threats may occur.

  • You can prevent charges resulting from attacks only by turning on the signed access switch.

3. Signature generation and authentication mechanism

Warning

When you use the HTTP API, read the Best practices document to prevent service failures.

3.1 Signature generation algorithm and examples

Authenticated API operations

  • http://47.74.XXX.XXX/{account_id}/sign_d

  • http://47.74.XXX.XXX/{account_id}/sign_resolve

Important
  • Replace {account_id} with your HTTPDNS Account ID. You can obtain this ID in the HTTPDNS console.

  • You can add the IP parameter to the authenticated API operation. However, this parameter and its value are not used to calculate the signature.

  • For more information about how to obtain the list of service IP addresses, see Obtain the endpoints of the resolution service.

Signature algorithm

sign = md5sum( host-secret-timestamp )

Authentication fields

Field

Description

host

The host to resolve. The value is the same as the host parameter in the URL.

secret

Generated by the server. Obtain the secret in the console > Developer Configuration.

image

timestamp

The time when the signature expires. This is the number of seconds since January 1, 1970. It is a positive integer with a fixed-length of 10.

Note

The maximum validity period of a signature is 24 hours.

Signature examples

  • Example 1: Resolve a single domain name

    • Original request: http://47.74.XXX.XXX/{account_id}/d?host=www.aliyun.com

    • Assume that the secret key is IAmASecret and the signature expires at 15:00:00 on August 15, 2018 (UTC+8). The corresponding timestamp for this expiration time is 1534316400.

    • sign = md5sum("www.aliyun.com-IAmASecret-1534316400") = 60c71e98b6d7fcbb366243e224eab457

    • Authenticated request: http://47.74.XXX.XXX/{account_id}/sign_d?host=www.aliyun.com&t=1534316400&s=60c71e98b6d7fcbb366243e224eab457

  • Example 2: Batch resolve domain names

    • Original request:

      http://47.74.XXX.XXX/{account_id}/resolve?host=www.aliyun.com,www.taobao.com

    • Assume that the secret key is IAmASecret and the signature expires at 15:00:00 on August 15, 2018 (UTC+8). The corresponding timestamp for this expiration time is 1534316400.

    • sign = md5sum("www.aliyun.com,www.taobao.com-IAmASecret-1534316400") = 12a3f6b1b14a46ca813ca6439beb59a4

    • Authenticated request: http://47.74.XXX.XXX/{account_id}/sign_resolve?host=www.aliyun.com,www.taobao.com&t=1534316400&s=12a3f6b1b14a46ca813ca6439beb59a4

Pros and cons of this solution

  • Disadvantages

    • The time on the client may differ from the time on the server.

    • Storing the secret key on the client is risky because the key may be compromised.

  • Advantages

    • You do not need to pull data from the server.

3.2 Authentication response

  • If authentication is successful, the HTTP response returns the status code 200. The response format is the same as the one described in the API Response Description section of Resolve a single domain name.

  • If authentication fails, the HTTP response returns the status code 403 or 400 and includes a specific error code. The response is in JSON format.

     { "code": "InvalidSignature" }

3.3 Status code description

HTTP status code

Error code

Description

403

SignatureExpired

The timestamp has expired.

403

InvalidSignature

The signature is incorrect.

400

InvalidDuration

The validity period of the signature is too long. The maximum period is 86,400 seconds.

400

InvalidSignature

The signature format is incorrect.

400

InvalidTimestamp

The timestamp format is incorrect.

400

AccountNotExists

The account does not exist or is disabled.